Browse Source

wxGUI/modeler: implement GrassInterface class (just few issues related to forms.py)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58518 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 years ago
parent
commit
c47fb86ed9

+ 0 - 1
gui/wxpython/gmodeler/dialogs.py

@@ -36,7 +36,6 @@ from gui_core.widgets     import SearchModuleWidget, SimpleValidator
 from core.gcmd            import GError, EncodeString
 from gui_core.dialogs     import SimpleDialog, MapLayersDialogForModeler
 from gui_core.prompt      import GPromptSTC
-from gui_core.forms       import CmdPanel
 from gui_core.gselect     import Select, ElementSelect
 from gmodeler.model       import *
 from lmgr.menudata        import LayerManagerMenuData

+ 5 - 3
gui/wxpython/gmodeler/frame.py

@@ -51,7 +51,7 @@ from gmodeler.preferences import PreferencesDialog, PropertiesDialog
 from gmodeler.toolbars    import ModelerToolbar
 from core.giface import Notification
 from gui_core.pystc       import PyStc
-
+from gmodeler.giface import GraphicalModelerGrassInterface
 from gmodeler.model       import *
 from gmodeler.dialogs     import *
 
@@ -1108,8 +1108,10 @@ class ModelEvtHandler(ogl.ShapeEvtHandler):
         self.frame.ModelChanged()
         shape = self.GetShape()
         if isinstance(shape, ModelAction):
-            module = GUI(parent = self.frame, show = True).ParseCommand(shape.GetLog(string = False),
-                                                                        completed = (self.frame.GetOptData, shape, shape.GetParams()))
+            gmodule = GUI(parent = self.frame, show = True,
+                          giface = GraphicalModelerGrassInterface(self.frame.GetModel()))
+            module = gmodule.ParseCommand(shape.GetLog(string = False),
+                                          completed = (self.frame.GetOptData, shape, shape.GetParams()))
         
         elif isinstance(shape, ModelData):
             dlg = ModelDataDialog(parent = self.frame, shape = shape)

+ 29 - 0
gui/wxpython/gmodeler/giface.py

@@ -0,0 +1,29 @@
+"""!
+@package gmodeler.giface
+
+@brief wxGUI Graphical Modeler GRASS interface
+
+Classes:
+ - giface::GraphicalModelerGrassInterface
+
+(C) 2013 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 Martin Landa <landa.martin gmail.com>
+"""
+
+class GraphicalModelerGrassInterface(object):
+    """!@implements core::giface::GrassInterface"""
+    def __init__(self, model):
+        self._model = model
+        
+    def __getattr__(self, name):
+        return getattr(self._giface, name)
+    
+    def GetLayerTree(self):
+        return None
+    
+    def GetLayerList(self, prompt):
+        return self._model.GetMaps(prompt)

+ 3 - 1
gui/wxpython/gmodeler/model.py

@@ -48,6 +48,7 @@ from core.gcmd           import GMessage, GException, GError, RunCommand, Encode
 from core.settings       import UserSettings
 from gui_core.forms      import GUI, CmdPanel
 from gui_core.widgets    import GNotebook
+from gmodeler.giface import GraphicalModelerGrassInterface
 
 from grass.script import core as grass
 from grass.script import task as gtask
@@ -2285,7 +2286,8 @@ class ModelParamDialog(wx.Dialog):
         task.flags  = params['flags']
         task.params = params['params']
         
-        panel = CmdPanel(parent = self, id = wx.ID_ANY, task = task)
+        panel = CmdPanel(parent = self, id = wx.ID_ANY, task = task,
+                         giface = GraphicalModelerGrassInterface(self.parent.GetModel()))
         self.tasks.append(task)
         
         return panel

+ 6 - 10
gui/wxpython/gui_core/forms.py

@@ -392,10 +392,6 @@ class TaskFrame(wx.Frame):
         self.task     = task_description
         self.parent   = parent             # LayerTree | Modeler | None | ...
         self._giface  = giface
-        if parent and parent.GetName() == 'Modeler':
-            self.modeler = self.parent
-        else:
-            self.modeler = None
 
         self.dialogClosing = Signal('TaskFrame.dialogClosing')
         
@@ -549,7 +545,7 @@ class TaskFrame(wx.Frame):
         accelTable = wx.AcceleratorTable(accelTableList)
         self.SetAcceleratorTable(accelTable)
         
-        if self.parent and not self.modeler:
+        if self._giface and self._giface.GetLayerTree():
             addLayer = False
             for p in self.task.params:
                 if p.get('age', 'old') == 'new' and \
@@ -671,7 +667,7 @@ class TaskFrame(wx.Frame):
 
     def OnApply(self, event):
         """!Apply the command"""
-        if self.modeler:
+        if self._giface and hasattr(self._giface, "_model"):
             cmd = self.createCmd(ignoreErrors = True, ignoreRequired = True)
         else:
             cmd = self.createCmd()
@@ -887,7 +883,7 @@ class CmdPanel(wx.Panel):
             f['wxId'] = [ chk.GetId(), ]
             chk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
             
-            if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
+            if self.parent.GetName() == 'MainFrame' and (self._giface and hasattr(self._giface, "_model")):
                 parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
                                      label = _("Parameterized in model"))
                 parChk.SetName('ModelParam')
@@ -1182,8 +1178,8 @@ class CmdPanel(wx.Panel):
                                     element_dict = {'rast': 'strds', 'vect': 'stvds', 'rast3d': 'str3ds'}
                                     elem = element_dict[type_param.get('default')]
                         
-                        if self.parent.modeler:
-                            extraItems = {_('Graphical Modeler') : self.parent.modeler.GetModel().GetMaps(p.get('prompt'))}
+                        if self._giface and hasattr(self._giface, "_model"):
+                            extraItems = {_('Graphical Modeler') : self._giface.GetLayerList(p.get('prompt'))}
                         else:
                             extraItems = None
                         selection = gselect.Select(parent = which_panel, id = wx.ID_ANY,
@@ -1594,7 +1590,7 @@ class CmdPanel(wx.Panel):
                     if p.get('guidependency', ''):
                         cb.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
                 
-            if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
+            if self.parent.GetName() == 'MainFrame' and (self._giface and hasattr(self._giface, "_model")):
                 parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
                                      label = _("Parameterized in model"))
                 parChk.SetName('ModelParam')