[GRASS-SVN] r48658 - in grass/trunk/gui/wxpython: . gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Oct 6 06:57:43 EDT 2011
Author: martinl
Date: 2011-10-06 03:57:43 -0700 (Thu, 06 Oct 2011)
New Revision: 48658
Modified:
grass/trunk/gui/wxpython/gui_modules/gdialogs.py
grass/trunk/gui/wxpython/gui_modules/gmodeler.py
grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI/modeler: implement series
Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py 2011-10-06 07:16:37 UTC (rev 48657)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py 2011-10-06 10:57:43 UTC (rev 48658)
@@ -11,7 +11,7 @@
- SavedRegion
- DecorationDialog
- TextLayerDialog
- - AddMapLayersDialog
+ - MapLayersDialog
- ImportDialog
- GdalImportDialog
- GdalOutputDialog
@@ -903,32 +903,28 @@
'coords' : self.currCoords,
'active' : self.chkbox.IsChecked() }
-class AddMapLayersDialog(wx.Dialog):
- """!Add selected map layers (raster, vector) into layer tree"""
- def __init__(self, parent, title, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
- wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title, style = style)
-
- self.parent = parent # GMFrame
+class MapLayersDialog(wx.Dialog):
+ def __init__(self, parent, title,
+ style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
+ """!Dialog for selecting map layers (raster, vector)"""
+ wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
+ style = style, **kwargs)
- #
+ self.parent = parent # GMFrame or ?
+
# dialog body
- #
- self.bodySizer = self.__createDialogBody()
+ self.bodySizer = self._createDialogBody()
# update list of layer to be loaded
self.map_layers = [] # list of map layers (full list type/mapset)
self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
self.mapset.GetStringSelection())
- #
+
# buttons
- #
btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
- btnOk = wx.Button(parent = self, id = wx.ID_OK, label = _("&Add"))
+ btnOk = wx.Button(parent = self, id = wx.ID_OK)
btnOk.SetDefault()
- btnOk.SetToolTipString(_("Add selected map layers to current display"))
-
- #
+
# sizers & do layout
- #
btnSizer = wx.StdDialogButtonSizer()
btnSizer.AddButton(btnCancel)
btnSizer.AddButton(btnOk)
@@ -946,7 +942,7 @@
# set dialog min size
self.SetMinSize(self.GetSize())
- def __createDialogBody(self):
+ def _createDialogBody(self):
bodySizer = wx.GridBagSizer(vgap = 3, hgap = 3)
bodySizer.AddGrowableCol(1)
bodySizer.AddGrowableRow(3)
@@ -955,13 +951,13 @@
bodySizer.Add(item = wx.StaticText(parent = self, label = _("Map layer type:")),
flag = wx.ALIGN_CENTER_VERTICAL,
pos = (0,0))
-
+
self.layerType = wx.Choice(parent = self, id = wx.ID_ANY,
choices = ['raster', 'vector'], size = (100,-1))
self.layerType.SetSelection(0)
bodySizer.Add(item = self.layerType,
pos = (0,1))
-
+
# select toggle
self.toggle = wx.CheckBox(parent = self, id = wx.ID_ANY,
label = _("Select toggle"))
@@ -974,24 +970,24 @@
bodySizer.Add(item = wx.StaticText(parent = self, label = _("Mapset:")),
flag = wx.ALIGN_CENTER_VERTICAL,
pos = (1,0))
-
+
self.mapset = gselect.MapsetSelect(parent = self)
self.mapset.SetStringSelection(grass.gisenv()['MAPSET'])
bodySizer.Add(item = self.mapset,
pos = (1,1), span = (1, 2))
-
+
# map name filter
bodySizer.Add(item = wx.StaticText(parent = self, label = _("Filter:")),
flag = wx.ALIGN_CENTER_VERTICAL,
pos = (2,0))
-
+
self.filter = wx.TextCtrl(parent = self, id = wx.ID_ANY,
value = "",
size = (250,-1))
bodySizer.Add(item = self.filter,
flag = wx.EXPAND,
pos = (2,1), span = (1, 2))
-
+
# layer list
bodySizer.Add(item = wx.StaticText(parent = self, label = _("List of maps:")),
flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
@@ -1002,7 +998,7 @@
bodySizer.Add(item = self.layers,
flag = wx.EXPAND,
pos = (3,1), span = (1, 2))
-
+
# bindings
self.layerType.Bind(wx.EVT_CHOICE, self.OnChangeParams)
self.mapset.Bind(wx.EVT_COMBOBOX, self.OnChangeParams)
@@ -1023,15 +1019,15 @@
# check all items by default
for item in range(self.layers.GetCount()):
self.layers.Check(item)
-
+
def OnChangeParams(self, event):
"""!Filter parameters changed by user"""
# update list of layer to be loaded
self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
self.mapset.GetStringSelection())
-
+
event.Skip()
-
+
def OnMenu(self, event):
"""!Table description area, context menu"""
if not hasattr(self, "popupID1"):
@@ -1042,21 +1038,21 @@
self.Bind(wx.EVT_MENU, self.OnSelectAll, id = self.popupDataID1)
self.Bind(wx.EVT_MENU, self.OnSelectInvert, id = self.popupDataID2)
self.Bind(wx.EVT_MENU, self.OnDeselectAll, id = self.popupDataID3)
-
+
# generate popup-menu
menu = wx.Menu()
menu.Append(self.popupDataID1, _("Select all"))
menu.Append(self.popupDataID2, _("Invert selection"))
menu.Append(self.popupDataID3, _("Deselect all"))
-
+
self.PopupMenu(menu)
menu.Destroy()
-
+
def OnSelectAll(self, event):
"""!Select all map layer from list"""
for item in range(self.layers.GetCount()):
self.layers.Check(item, True)
-
+
def OnSelectInvert(self, event):
"""!Invert current selection"""
for item in range(self.layers.GetCount()):
@@ -1069,13 +1065,13 @@
"""!Select all map layer from list"""
for item in range(self.layers.GetCount()):
self.layers.Check(item, False)
-
+
def OnFilter(self, event):
"""!Apply filter for map names"""
if len(event.GetString()) == 0:
self.layers.Set(self.map_layers)
return
-
+
list = []
for layer in self.map_layers:
try:
@@ -1083,18 +1079,18 @@
list.append(layer)
except:
pass
-
+
self.layers.Set(list)
self.OnSelectAll(None)
event.Skip()
-
+
def OnToggle(self, event):
"""!Select toggle (check or uncheck all layers)"""
check = event.Checked()
for item in range(self.layers.GetCount()):
self.layers.Check(item, check)
-
+
event.Skip()
def GetMapLayers(self):
@@ -1103,14 +1099,14 @@
for indx in self.layers.GetSelections():
# layers.append(self.layers.GetStringSelec(indx))
pass
-
+
# return fully qualified map names
mapset = self.mapset.GetStringSelection()
for item in range(self.layers.GetCount()):
if not self.layers.IsChecked(item):
continue
layerNames.append(self.layers.GetString(item) + '@' + mapset)
-
+
return layerNames
def GetLayerType(self):
Modified: grass/trunk/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gmodeler.py 2011-10-06 07:16:37 UTC (rev 48657)
+++ grass/trunk/gui/wxpython/gui_modules/gmodeler.py 2011-10-06 10:57:43 UTC (rev 48658)
@@ -73,7 +73,7 @@
import gselect
from debug import Debug
from gcmd import GMessage, GException, GWarning, GError, RunCommand
-from gdialogs import ElementDialog, GetImageHandlers
+from gdialogs import ElementDialog, GetImageHandlers, MapLayersDialog
from preferences import PreferencesBaseDialog, globalSettings as UserSettings
from ghelp import SearchModuleWindow
@@ -500,13 +500,36 @@
if vtype == 'string':
value = '"' + value + '"'
cond = pattern.sub(value, cond)
+
# split condition
- condVar, condText = re.split('\s*in\s*', cond)
+ condVar, condText = map(lambda x: x.strip(), re.split('\s*in\s*', cond))
+ pattern = re.compile('%' + condVar)
+ ### for vars()[condVar] in eval(condText): ?
+ if condText[0] == '`' and condText[-1] == '`':
+ # run command
+ cmd, dcmd = utils.CmdToTuple(condText[1:-1].split(' '))
+ ret = RunCommand(cmd,
+ read = True,
+ **dcmd)
+ if ret:
+ vlist = ret.splitlines()
+ else:
+ vlist = eval(condText)
- for action in item.GetItems():
- for vars()[condVar] in eval(condText):
- if isinstance(action, ModelAction):
- self.RunAction(action, params, log, onDone)
+ for var in vlist:
+ for action in item.GetItems():
+ if not isinstance(action, ModelAction):
+ continue
+
+ par = action.GetParams(dcopy = True)['params']
+ for idx in range(len(par)):
+ if not par[idx].get('value', None):
+ continue
+
+ if pattern.search(par[idx]['value']):
+ par[idx]['value'] = pattern.sub(par[idx]['value'], var)
+
+ self.RunAction(action, { action.GetName(): {'params': par } }, log, onDone)
if params:
dlg.Destroy()
@@ -2226,6 +2249,7 @@
alist.append(action)
shape.SetItems(alist)
self.frame.DefineLoop(shape)
+ self.frame.SetStatusText(shape.GetLog(), 0)
self.frame.GetCanvas().Refresh()
dlg.Destroy()
@@ -4124,6 +4148,11 @@
self.listBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
label=" %s " % _("List of items in loop"))
+ self.btnSeries = wx.Button(parent = self.panel, id = wx.ID_ANY,
+ label = _("Series"))
+ self.btnSeries.SetToolTipString(_("Define map series as condition for the loop"))
+ self.btnSeries.Bind(wx.EVT_BUTTON, self.OnSeries)
+
self._layout()
self.SetMinSize(self.GetSize())
self.SetSize((500, 400))
@@ -4132,13 +4161,15 @@
"""!Do layout"""
sizer = wx.BoxSizer(wx.VERTICAL)
- condSizer = wx.StaticBoxSizer(self.condBox, wx.VERTICAL)
+ condSizer = wx.StaticBoxSizer(self.condBox, wx.HORIZONTAL)
condSizer.Add(item = self.condText, proportion = 1,
+ flag = wx.ALL, border = 3)
+ condSizer.Add(item = self.btnSeries, proportion = 0,
flag = wx.EXPAND)
-
+
listSizer = wx.StaticBoxSizer(self.listBox, wx.VERTICAL)
listSizer.Add(item = self.itemList, proportion = 1,
- flag = wx.EXPAND)
+ flag = wx.EXPAND | wx.ALL, border = 3)
btnSizer = wx.StdDialogButtonSizer()
btnSizer.AddButton(self.btnCancel)
@@ -4161,6 +4192,17 @@
"""!Get list of selected actions"""
return self.itemList.GetItems()
+ def OnSeries(self, event):
+ """!Define map series as condition"""
+ dialog = MapLayersDialog(parent = self, title = _("Define series of maps"))
+ if dialog.ShowModal() != wx.ID_OK:
+ dialog.Destroy()
+ return
+
+ self.condText.SetValue('map in %s' % map(lambda x: str(x), dialog.GetMapLayers()))
+
+ dialog.Destroy()
+
class ItemPanel(wx.Panel):
def __init__(self, parent, id = wx.ID_ANY,
**kwargs):
@@ -4227,11 +4269,13 @@
shapeItems = map(lambda x: x.GetId(), self.shape.GetItems())
else:
shapeItems = list()
+
i = 0
if len(self.columns) == 3: # ItemCheckList
checked = list()
for action in data:
- if isinstance(action, ModelData):
+ if isinstance(action, ModelData) or \
+ action == self.shape:
continue
if len(self.columns) == 3:
@@ -4663,7 +4707,15 @@
value = '"' + value + '"'
cond = pattern.sub(value, cond)
if isinstance(item, ModelLoop):
- self.fd.write('%sfor %s:\n' % (' ' * self.indent, cond))
+ condVar, condText = map(lambda x: x.strip(), re.split('\s*in\s*', cond))
+ cond = "%sfor %s in " % (' ' * self.indent, condVar)
+ if condText[0] == '`' and condText[-1] == '`':
+ task = menuform.GUI(show = None).ParseCommand(cmd = utils.split(condText[1:-1]))
+ cond += "grass.read_command("
+ cond += self._getPythonActionCmd(task, len(cond)) + ".splitlines()"
+ else:
+ cond += condText
+ self.fd.write('%s:\n' % cond)
self.indent += 4
for action in item.GetItems():
self._writePythonItem(action, ignoreBlock = False)
@@ -4685,13 +4737,18 @@
def _writePythonAction(self, item):
"""!Write model action to Python file"""
task = menuform.GUI(show = None).ParseCommand(cmd = item.GetLog(string = False))
+ strcmd = "%sgrass.run_command(" % (' ' * self.indent)
+ self.fd.write(strcmd + self._getPythonActionCmd(task, len(strcmd)) + '\n')
+
+ def _getPythonActionCmd(self, task, cmdIndent):
opts = task.get_options()
+
+ ret = ''
flags = ''
params = list()
- strcmd = "%sgrass.run_command(" % (' ' * self.indent)
- cmdIndent = len(strcmd)
+
for f in opts['flags']:
- if f.get('value', False) == True:
+ if f.get('value', False):
name = f.get('name', '')
if len(name) > 1:
params.append('%s = True' % name)
@@ -4703,23 +4760,26 @@
value = p.get('value', None)
if name and value:
ptype = p.get('type', 'string')
- if ptype == 'string':
+ if value[0] == '%':
+ params.append("%s = %s" % (name, value[1:]))
+ elif ptype == 'string':
params.append('%s = "%s"' % (name, value))
else:
params.append("%s = %s" % (name, value))
- self.fd.write(strcmd + '"%s"' % task.get_name())
+ ret += '"%s"' % task.get_name()
if flags:
- self.fd.write(",\n%sflags = '%s'" % (' ' * cmdIndent, flags))
+ ret += ",\n%sflags = '%s'" % (' ' * cmdIndent, flags)
if len(params) > 0:
- self.fd.write(",\n")
+ ret += ",\n"
for opt in params[:-1]:
- self.fd.write("%s%s,\n" % (' ' * cmdIndent, opt))
- self.fd.write("%s%s)\n" % (' ' * cmdIndent, params[-1]))
+ ret += "%s%s,\n" % (' ' * cmdIndent, opt)
+ ret += "%s%s)" % (' ' * cmdIndent, params[-1])
else:
- self.fd.write(")\n")
+ ret += ")"
+
+ return ret
-
def main():
import gettext
gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2011-10-06 07:16:37 UTC (rev 48657)
+++ grass/trunk/gui/wxpython/wxgui.py 2011-10-06 10:57:43 UTC (rev 48658)
@@ -1346,32 +1346,31 @@
def OnAddMaps(self, event = None):
"""!Add selected map layers into layer tree"""
- dialog = gdialogs.AddMapLayersDialog(parent = self, title = _("Add selected map layers into layer tree"))
+ dialog = gdialogs.MapLayersDialog(parent = self, title = _("Add selected map layers into layer tree"))
+
+ if dialog.ShowModal() != wx.ID_OK:
+ dialog.Destroy()
+ return
- if dialog.ShowModal() == wx.ID_OK:
- # start new map display if no display is available
- if not self.curr_page:
- self.NewDisplay()
-
- maptree = self.curr_page.maptree
- busy = wx.BusyInfo(message = _("Please wait, loading workspace..."),
- parent = self)
- wx.Yield()
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay()
- for layerName in dialog.GetMapLayers():
- if dialog.GetLayerType() == 'raster':
- cmd = ['d.rast', 'map=%s' % layerName]
- elif dialog.GetLayerType() == 'vector':
- cmd = ['d.vect', 'map=%s' % layerName]
- newItem = maptree.AddLayer(ltype = dialog.GetLayerType(),
- lname = layerName,
- lchecked = False,
- lopacity = 1.0,
- lcmd = cmd,
- lgroup = None)
-
- busy.Destroy()
-
+ maptree = self.curr_page.maptree
+
+ for layerName in dialog.GetMapLayers():
+ if dialog.GetLayerType() == 'raster':
+ cmd = ['d.rast', 'map=%s' % layerName]
+ elif dialog.GetLayerType() == 'vector':
+ cmd = ['d.vect', 'map=%s' % layerName]
+ newItem = maptree.AddLayer(ltype = dialog.GetLayerType(),
+ lname = layerName,
+ lchecked = False,
+ lopacity = 1.0,
+ lcmd = cmd,
+ lgroup = None)
+ dialog.Destroy()
+
def OnAddRaster(self, event):
"""!Add raster map layer"""
# start new map display if no display is available
More information about the grass-commit
mailing list