1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
"""
@package rdigit.dialogs
@brief rdigit dialog for creating new map.
Classes:
- rdigit:NewRasterDialog
(C) 2014 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
@author Anna Petrasova <kratochanna gmail.com>
"""
import wx
from gui_core.gselect import Select
from gui_core.wrap import Button, StaticText
from core.gcmd import GWarning
import grass.script.core as gcore
import grass.script.raster as grast
from grass.exceptions import CalledModuleError
class NewRasterDialog(wx.Dialog):
"""Dialog for new raster map name and type selection
and selection of optional background map."""
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.SetTitle(_("Create new raster map"))
self._name = None
self._type = None
# create widgets
self._mapSelect = Select(parent=self, type="raster")
self._backgroundSelect = Select(parent=self, type="raster")
self._typeChoice = wx.Choice(self, choices=["CELL", "FCELL", "DCELL"])
self._typeChoice.SetSelection(0)
self._mapSelect.SetFocus()
btnCancel = Button(parent=self, id=wx.ID_CANCEL)
btnOK = Button(parent=self, id=wx.ID_OK)
btnOK.SetDefault()
btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
# do layout
mainSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.GridBagSizer(hgap=10, vgap=10)
sizer.Add(
StaticText(self, label=_("Name for new raster map:")),
pos=(0, 0),
span=(1, 2),
flag=wx.ALIGN_CENTER_VERTICAL,
)
sizer.Add(self._mapSelect, pos=(1, 0), span=(1, 2))
sizer.Add(
StaticText(self, label=_("Optionally select background raster map:")),
pos=(2, 0),
span=(1, 2),
flag=wx.ALIGN_CENTER_VERTICAL,
)
sizer.Add(self._backgroundSelect, pos=(3, 0), span=(1, 2))
sizer.Add(
StaticText(self, label=_("New raster map type:")),
pos=(4, 0),
flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL,
)
sizer.Add(self._typeChoice, pos=(4, 1), flag=wx.EXPAND)
mainSizer.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
btnSizer = wx.StdDialogButtonSizer()
btnSizer.AddButton(btnCancel)
btnSizer.AddButton(btnOK)
btnSizer.Realize()
mainSizer.Add(btnSizer, flag=wx.EXPAND | wx.ALL, border=10)
self._backgroundSelect.Bind(wx.EVT_TEXT, self.OnBackgroundMap)
self.SetSizer(mainSizer)
mainSizer.Fit(self)
def OnBackgroundMap(self, event):
value = self._backgroundSelect.GetValue()
try:
ret = grast.raster_info(value)
self._typeChoice.SetStringSelection(ret["datatype"])
except CalledModuleError:
return
def OnOK(self, event):
mapName = self.GetMapName()
if not mapName:
GWarning(
parent=self.GetParent(),
message=_("Please specify name for a new raster map"),
)
else:
found = gcore.find_file(name=mapName, mapset=gcore.gisenv()["MAPSET"])
if found and found["mapset"] == gcore.gisenv()["MAPSET"]:
dlgOverwrite = wx.MessageDialog(
self.GetParent(),
message=_(
"Raster map <%s> already exists "
"in the current mapset. "
"Do you want to overwrite it?"
)
% mapName,
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if not dlgOverwrite.ShowModal() == wx.ID_YES:
dlgOverwrite.Destroy()
return
else:
dlgOverwrite.Destroy()
self.EndModal(wx.ID_OK)
else:
self.EndModal(wx.ID_OK)
def GetMapName(self):
return self._mapSelect.GetValue()
def GetBackgroundMapName(self):
return self._backgroundSelect.GetValue()
def GetMapType(self):
return self._typeChoice.GetStringSelection()
if __name__ == "__main__":
app = wx.App()
dlg = NewRasterDialog(None)
dlg.Show()
app.MainLoop()
|