[GRASS-SVN] r48387 - in
grass/branches/releasebranch_6_4/gui/wxpython: . gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 20 10:53:52 EDT 2011
Author: martinl
Date: 2011-09-20 07:53:52 -0700 (Tue, 20 Sep 2011)
New Revision: 48387
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gmodeler.py
grass/branches/releasebranch_6_4/gui/wxpython/wxgui.py
Log:
wxGUI: attempt to fix #1448 (run model menu item does not seem to work)
(merge r48308 & r48343 from devbr6)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gmodeler.py 2011-09-20 14:31:13 UTC (rev 48386)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gmodeler.py 2011-09-20 14:53:52 UTC (rev 48387)
@@ -317,15 +317,18 @@
for rel in data['rels']:
actionItem = self.FindAction(rel['id'])
if rel['dir'] == 'from':
- relation = ModelRelation(dataItem, actionItem, rel['name'])
+ relation = ModelRelation(parent = self, fromShape = dataItem,
+ toShape = actionItem, param = rel['name'])
else:
- relation = ModelRelation(actionItem, dataItem, rel['name'])
+ relation = ModelRelation(parent = self, fromShape = actionItem,
+ toShape = dataItem, param = rel['name'])
relation.SetControlPoints(rel['points'])
actionItem.AddRelation(relation)
dataItem.AddRelation(relation)
-
- dataItem.Update()
-
+
+ if self.canvas:
+ dataItem.Update()
+
# load loops
for loop in gxmXml.loops:
loopItem = ModelLoop(parent = self,
@@ -405,14 +408,109 @@
return errList
- def Run(self, log, onDone):
- """!Run model"""
- for action in self.actions:
- if not action.IsEnabled():
+ def RunAction(self, item, params, log, onDone, statusbar = None):
+ """!Run given action
+
+ @param item action item
+ @param params parameters dict
+ @param log logging window
+ @param onDone on-done method
+ @param statusbar wx.StatusBar instance or None
+ """
+ name = item.GetName()
+ if name in params:
+ paramsOrig = item.GetParams(dcopy = True)
+ item.MergeParams(params[name])
+
+ if statusbar:
+ statusbar.SetStatusText(_('Running model...'), 0)
+ log.RunCmd(command = item.GetLog(string = False),
+ onDone = onDone)
+
+ if name in params:
+ item.SetParams(paramsOrig)
+
+ def Run(self, log, onDone, parent = None):
+ """!Run model
+
+ @param log logging window (see goutput.GMConsole)
+ @param onDone on-done method
+ @param parent window for messages or None
+ """
+ if self.GetNumItems() < 1:
+ GMessage(parent = parent,
+ message = _('Model is empty. Nothing to run.'))
+ return
+
+ statusbar = None
+ if isinstance(parent, wx.Frame):
+ statusbar = parent.GetStatusBar()
+
+ # validation
+ if statusbar:
+ statusbar.SetStatusText(_('Validating model...'), 0)
+ errList = self.Validate()
+ if statusbar:
+ statusbar.SetStatusText('', 0)
+ if errList:
+ dlg = wx.MessageDialog(parent = parent,
+ message = _('Model is not valid. Do you want to '
+ 'run the model anyway?\n\n%s') % '\n'.join(errList),
+ caption = _("Run model?"),
+ style = wx.YES_NO | wx.NO_DEFAULT |
+ wx.ICON_QUESTION | wx.CENTRE)
+ ret = dlg.ShowModal()
+ if ret != wx.ID_YES:
+ return
+
+ # parametrization
+ params = self.Parameterize()
+ if params:
+ dlg = ModelParamDialog(parent = parent,
+ params = params)
+ dlg.CenterOnParent()
+
+ ret = dlg.ShowModal()
+ if ret != wx.ID_OK:
+ dlg.Destroy()
+ return
+
+ err = dlg.GetErrors()
+ if err:
+ GError(parent = self, message = unicode('\n'.join(err)))
+ return
+
+ log.cmdThread.SetId(-1)
+ for item in self.GetItems():
+ if not item.IsEnabled():
continue
- log.RunCmd(command = action.GetLog(string = False),
- onDone = onDone)
+ if isinstance(item, ModelAction):
+ if item.GetBlockId():
+ continue
+ self.RunAction(item, params, log, onDone)
+ elif isinstance(item, ModelLoop):
+ cond = item.GetText()
+ # substitute variables in condition
+ variables = self.GetVariables()
+ for variable in variables:
+ pattern = re.compile('%' + variable)
+ if pattern.search(cond):
+ value = variables[variable].get('value', '')
+ vtype = variables[variable].get('type', 'string')
+ if vtype == 'string':
+ value = '"' + value + '"'
+ cond = pattern.sub(value, cond)
+ # split condition
+ condVar, condText = re.split('\s*in\s*', cond)
+
+ for action in item.GetItems():
+ for vars()[condVar] in eval(condText):
+ if isinstance(action, ModelAction):
+ self.RunAction(action, params, log, onDone)
+ if params:
+ dlg.Destroy()
+
def DeleteIntermediateData(self, log):
"""!Detele intermediate data"""
rast, vect, rast3d, msg = self.GetIntermediateData()
@@ -925,87 +1023,8 @@
def OnRunModel(self, event):
"""!Run entire model"""
- if self.model.GetNumItems() < 1:
- GMessage(parent = self,
- message = _('Model is empty. Nothing to run.'))
- return
+ self.model.Run(self.goutput, self.OnDone, parent = self)
- # validation
- errList = self._validateModel()
- if errList:
- dlg = wx.MessageDialog(parent = self,
- message = _('Model is not valid. Do you want to '
- 'run the model anyway?\n\n%s') % '\n'.join(errList),
- caption=_("Run model?"),
- style = wx.YES_NO | wx.NO_DEFAULT |
- wx.ICON_QUESTION | wx.CENTRE)
- ret = dlg.ShowModal()
- if ret != wx.ID_YES:
- return
-
- # parametrization
- params = self.model.Parameterize()
- if params:
- dlg = ModelParamDialog(parent = self,
- params = params)
- dlg.CenterOnParent()
-
- ret = dlg.ShowModal()
- if ret != wx.ID_OK:
- dlg.Destroy()
- return
-
- err = dlg.GetErrors()
- if err:
- GError(parent = self,
- message = unicode('\n'.join(err)))
- return
-
- self.goutput.cmdThread.SetId(-1)
- for item in self.model.GetItems():
- if not item.IsEnabled():
- continue
- if isinstance(item, ModelAction):
- if item.GetBlockId():
- continue
- self._runAction(item, params)
- elif isinstance(item, ModelLoop):
- cond = item.GetText()
- # substitute variables in condition
- variables = self.model.GetVariables()
- for variable in variables:
- pattern = re.compile('%' + variable)
- if pattern.search(cond):
- value = variables[variable].get('value', '')
- vtype = variables[variable].get('type', 'string')
- if vtype == 'string':
- value = '"' + value + '"'
- cond = pattern.sub(value, cond)
- # split condition
- condVar, condText = re.split('\s*in\s*', cond)
-
- for action in item.GetItems():
- for vars()[condVar] in eval(condText):
- if isinstance(action, ModelAction):
- self._runAction(action, params)
-
- if params:
- dlg.Destroy()
-
- def _runAction(self, item, params):
- """!Run given action"""
- name = item.GetName()
- if name in params:
- paramsOrig = item.GetParams(dcopy = True)
- item.MergeParams(params[name])
-
- self.SetStatusText(_('Running model...'), 0)
- self.goutput.RunCmd(command = item.GetLog(string = False),
- onDone = self.OnDone)
-
- if name in params:
- item.SetParams(paramsOrig)
-
def OnDone(self, cmd, returncode):
"""!Computation finished"""
self.SetStatusText('', 0)
@@ -1017,8 +1036,11 @@
message = _('Model is empty. Nothing to validate.'))
return
- errList = self._validateModel()
+ self.SetStatusText(_('Validating model...'), 0)
+ errList = self.model.Validate()
+ self.SetStatusText('', 0)
+
if errList:
GWarning(parent = self,
message = _('Model is not valid.\n\n%s') % '\n'.join(errList))
@@ -1130,16 +1152,6 @@
self.SetStatusText(_("Model exported to <%s>") % filename)
- def _validateModel(self):
- """!Validate model"""
- self.SetStatusText(_('Validating model...'), 0)
-
- errList = self.model.Validate()
-
- self.SetStatusText('', 0)
-
- return errList
-
def OnDefineRelation(self, event):
"""!Define relation between data and action items"""
self.canvas.SetCursor(self.cursors["cross"])
@@ -1310,9 +1322,11 @@
p.get('prompt', ''))
if data:
if p.get('age', 'old') == 'old':
- rel = ModelRelation(data, layer, p.get('name', ''))
+ rel = ModelRelation(parent = self, fromShape = data,
+ toShape = layer, param = p.get('name', ''))
else:
- rel = ModelRelation(layer, data, p.get('name', ''))
+ rel = ModelRelation(parent = self, fromShape = layer,
+ toShape = data, param = p.get('name', ''))
layer.AddRelation(rel)
data.AddRelation(rel)
self.AddLine(rel)
@@ -1327,9 +1341,11 @@
data.Show(True)
if p.get('age', 'old') == 'old':
- rel = ModelRelation(data, layer, p.get('name', ''))
+ rel = ModelRelation(parent = self, fromShape = data,
+ toShape = layer, param = p.get('name', ''))
else:
- rel = ModelRelation(layer, data, p.get('name', ''))
+ rel = ModelRelation(parent = self, fromShape = layer,
+ toShape = data, param = p.get('name', ''))
layer.AddRelation(rel)
data.AddRelation(rel)
self.AddLine(rel)
@@ -1492,7 +1508,7 @@
loop.Clear()
for item in items:
- rel = ModelRelation(parent, item)
+ rel = ModelRelation(parent = self, fromShape = parent, toShape = item)
dx = item.GetX() - parent.GetX()
dy = item.GetY() - parent.GetY()
loop.AddRelation(rel)
@@ -1504,7 +1520,7 @@
# close loop
item = loop.GetItems()[-1]
- rel = ModelRelation(item, loop)
+ rel = ModelRelation(parent = self, fromShape = item, toShape = loop)
loop.AddRelation(rel)
self.AddLine(rel)
dx = (item.GetX() - loop.GetX()) + loop.GetWidth() / 2 + 50
@@ -1539,7 +1555,8 @@
dy = condition.GetY()
for branch in items.keys():
for item in items[branch]:
- rel = ModelRelation(parent, item)
+ rel = ModelRelation(parent = self, fromShape = parent,
+ toShape = item)
condition.AddRelation(rel)
self.AddLine(rel)
rel.MakeLineControlPoints(0)
@@ -1856,8 +1873,9 @@
def SetParameterized(self, isparameterized):
"""!Set action parameterized"""
self.isParameterized = isparameterized
- self._setPen()
-
+ if self.parent.GetCanvas():
+ self._setPen()
+
def IsParameterized(self):
"""!Check if action is parameterized"""
return self.isParameterized
@@ -2149,7 +2167,8 @@
drel['from'] = shape
elif drel['to'] is None:
drel['to'] = shape
- rel = ModelRelation(drel['from'], drel['to'])
+ rel = ModelRelation(parent = self.frame, fromShape = drel['from'],
+ toShape = drel['to'])
dlg = ModelRelationDialog(parent = self.frame,
shape = rel)
if dlg.IsValid():
@@ -2515,14 +2534,16 @@
class ModelRelation(ogl.LineShape):
"""!Data - action relation"""
- def __init__(self, fromShape, toShape, param = ''):
+ def __init__(self, parent, fromShape, toShape, param = ''):
self.fromShape = fromShape
self.toShape = toShape
self.param = param
+ self.parent = parent
self._points = None
- ogl.LineShape.__init__(self)
+ if self.parent.GetCanvas():
+ ogl.LineShape.__init__(self)
def __del__(self):
self.fromShape.rels.remove(self)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/wxgui.py 2011-09-20 14:31:13 UTC (rev 48386)
+++ grass/branches/releasebranch_6_4/gui/wxpython/wxgui.py 2011-09-20 14:53:52 UTC (rev 48387)
@@ -333,7 +333,7 @@
win.Show()
- def OnDone(self, returncode):
+ def OnDone(self, cmd, returncode):
"""Command execution finised"""
if hasattr(self, "model"):
self.model.DeleteIntermediateData(log = self.goutput)
@@ -343,33 +343,21 @@
def OnRunModel(self, event):
"""!Run model"""
filename = ''
- dlg = wx.FileDialog(parent = self, message=_("Choose model to run"),
+ dlg = wx.FileDialog(parent = self, message =_("Choose model to run"),
defaultDir = os.getcwd(),
- wildcard=_("GRASS Model File (*.gxm)|*.gxm"))
+ wildcard = _("GRASS Model File (*.gxm)|*.gxm"))
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
if not filename:
+ dlg.Destroy()
return
self.model = gmodeler.Model()
self.model.LoadModel(filename)
- self.SetStatusText(_('Validating model...'), 0)
- result = self.model.Validate()
- if result:
- dlg = wx.MessageDialog(parent = self,
- message = _('Model is not valid. Do you want to '
- 'run the model anyway?\n\n%s') % '\n'.join(errList),
- caption=_("Run model?"),
- style = wx.YES_NO | wx.NO_DEFAULT |
- wx.ICON_QUESTION | wx.CENTRE)
- ret = dlg.ShowModal()
- if ret != wx.ID_YES:
- return
+ self.model.Run(log = self.goutput, onDone = self.OnDone, parent = self)
- self.SetStatusText(_('Running model...'), 0)
- self.model.Run(log = self.goutput,
- onDone = self.OnDone)
+ dlg.Destroy()
def OnMapsets(self, event):
"""!Launch mapset access dialog
More information about the grass-commit
mailing list