[GRASS-SVN] r53942 - in grass/trunk/gui/wxpython: gmodeler gui_core lmgr scripts

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 20 13:10:39 PST 2012


Author: annakrat
Date: 2012-11-20 13:10:38 -0800 (Tue, 20 Nov 2012)
New Revision: 53942

Modified:
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/gui/wxpython/gui_core/goutput.py
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/scripts/vkrige.py
Log:
wxGUI/GConsole: decoupling layer manager, moving display commands to layer manager (co-author: wenzeslaus)

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2012-11-20 18:40:59 UTC (rev 53941)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2012-11-20 21:10:38 UTC (rev 53942)
@@ -106,7 +106,7 @@
         
         self.pythonPanel = PythonPanel(parent = self)
         
-        self.goutput = GConsole(parent = self, frame = self)
+        self.goutput = GConsole(parent = self)
         self.goutput.Bind(EVT_OUTPUT_TEXT, self.OnOutputText)
         self.Bind(EVT_CMD_RUN, self.OnCmdRun)
         self.Bind(EVT_CMD_DONE, self.OnCmdDone)

Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2012-11-20 18:40:59 UTC (rev 53941)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2012-11-20 21:10:38 UTC (rev 53942)
@@ -1620,7 +1620,7 @@
         ### add 'command output' tab regardless standalone dialog
         if self.parent.GetName() == "MainFrame" and self.parent.get_dcmd is None:
             from gui_core.goutput import GConsole, EVT_OUTPUT_TEXT
-            self.goutput = GConsole(parent = self.notebook, frame = self.parent, margin = False)
+            self.goutput = GConsole(parent = self.notebook, margin = False)
             self.goutput.Bind(EVT_OUTPUT_TEXT, self.OnOutputText)
             self.outpage = self.notebook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
             index = self.AddBitmapToImageList(section = 'output', imageList = imageList)

Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py	2012-11-20 18:40:59 UTC (rev 53941)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py	2012-11-20 21:10:38 UTC (rev 53942)
@@ -22,6 +22,7 @@
 
 import os
 import sys
+import re
 import textwrap
 import time
 import threading
@@ -205,7 +206,7 @@
             self._want_abort_all = False
 
 
-# Occurs event when some new text appears.
+# Occurs when some new text appears.
 # Text priority is specified by priority attribute.
 # Priority is 1 (lowest), 2, 3 (highest);
 # value 0 is currently not used and probably will not be used.
@@ -214,16 +215,30 @@
 # However, the new text or the whole text are not event attributes.
 gOutputText, EVT_OUTPUT_TEXT = NewEvent()
 
+# Occurs when ignored command is called.
+# Attribute cmd contains command (as a list).
+gIgnoredCmdRun, EVT_IGNORED_CMD_RUN = NewEvent()
 
+
 class GConsole(wx.SplitterWindow):
     """!Create and manage output console for commands run by GUI.
     """
-    def __init__(self, parent, id = wx.ID_ANY, margin = False,
-                 frame = None,
+    def __init__(self, parent, margin = False,
                  style = wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE,
                  gcstyle = GC_EMPTY,
+                 ignoredCmdPattern = None,
                  **kwargs):
-        wx.SplitterWindow.__init__(self, parent, id, style = style, *kwargs)
+        """!
+        @param parent gui parent
+        @param margin use margin in output pane (GStc)
+        @param style wx.SplitterWindow style
+        @param gcstyle GConsole style
+        (GC_EMPTY, GC_PROMPT to show command prompt,
+        GC_SEARCH to show search widget)
+        @param ignoredCmdPattern regular expression specifying commads
+        to be ignored (e.g. @c '^d\..*' for display commands)
+        """
+        wx.SplitterWindow.__init__(self, parent, id = wx.ID_ANY, style = style, **kwargs)
         self.SetName("GConsole")
         
         self.panelOutput = wx.Panel(parent = self, id = wx.ID_ANY)
@@ -231,14 +246,10 @@
 
         # initialize variables
         self.parent = parent # GMFrame | CmdPanel | ?
-        if frame:
-            self.frame = frame
-        else:
-            self.frame = parent
 
         self._gcstyle = gcstyle
         self.lineWidth       = 80
-        
+        self._ignoredCmdPattern = ignoredCmdPattern
         # create queues
         self.requestQ = Queue.Queue()
         self.resultQ = Queue.Queue()
@@ -519,12 +530,16 @@
     def RunCmd(self, command, compReg = True, switchPage = False, skipInterface = False,
                onDone = None, onPrepare = None, userData = None):
         """!Run command typed into console command prompt (GPrompt).
-        
-        @todo Display commands (*.d) are captured and processed
-        separately by mapdisp.py. Display commands are rendered in map
-        display widget that currently has the focus (as indicted by
-        mdidx).
-        
+
+        @todo Document the other event.
+        @todo Solve problem with the other event
+        (now uses gOutputText event but there is no text,
+        use onPrepare handler instead?)
+
+        Posts event EVT_IGNORED_CMD_RUN when command which should be ignored
+        (according to ignoredCmdPattern) is run.
+        For example, see layer manager which handles d.* on its own.
+
         @param command command given as a list (produced e.g. by utils.split())
         @param compReg True use computation region
         @param switchPage switch to output page
@@ -549,7 +564,7 @@
         except IOError, e:
             GError(_("Unable to write file '%(filePath)s'.\n\nDetails: %(error)s") % 
                     {'filePath': filePath, 'error' : e },
-                   parent = self.frame)
+                   parent = self)
             fileHistory = None
         
         if fileHistory:
@@ -560,51 +575,15 @@
         
         if command[0] in globalvar.grassCmd:
             # send GRASS command without arguments to GUI command interface
-            # except display commands (they are handled differently)
-            if self.frame.GetName() == "LayerManager" and \
-                    command[0][0:2] == "d." and \
-                    'help' not in ' '.join(command[1:]):
-                # display GRASS commands
-                try:
-                    layertype = {'d.rast'         : 'raster',
-                                 'd.rast3d'       : '3d-raster',
-                                 'd.rgb'          : 'rgb',
-                                 'd.his'          : 'his',
-                                 'd.shaded'       : 'shaded',
-                                 'd.legend'       : 'rastleg',
-                                 'd.rast.arrow'   : 'rastarrow',
-                                 'd.rast.num'     : 'rastnum',
-                                 'd.rast.leg'     : 'maplegend',
-                                 'd.vect'         : 'vector',
-                                 'd.thematic.area': 'thememap',
-                                 'd.vect.chart'   : 'themechart',
-                                 'd.grid'         : 'grid',
-                                 'd.geodesic'     : 'geodesic',
-                                 'd.rhumbline'    : 'rhumb',
-                                 'd.labels'       : 'labels',
-                                 'd.barscale'     : 'barscale',
-                                 'd.redraw'       : 'redraw'}[command[0]]
-                except KeyError:
-                    GMessage(parent = self.frame,
-                             message = _("Command '%s' not yet implemented in the WxGUI. "
-                                         "Try adding it as a command layer instead.") % command[0])
-                    return
-                
-                if layertype == 'barscale':
-                    self.frame.GetLayerTree().GetMapDisplay().OnAddBarscale(None)
-                elif layertype == 'rastleg':
-                    self.frame.GetLayerTree().GetMapDisplay().OnAddLegend(None)
-                elif layertype == 'redraw':
-                    self.frame.GetLayerTree().GetMapDisplay().OnRender(None)
-                else:
-                    # add layer into layer tree
-                    lname, found = utils.GetLayerNameFromCmd(command, fullyQualified = True,
-                                                             layerType = layertype)
-                    if self.frame.GetName() == "LayerManager":
-                        self.frame.GetLayerTree().AddLayer(ltype = layertype,
-                                                               lname = lname,
-                                                               lcmd = command)
-            
+            # except ignored commands (event is emitted)
+
+            if self._ignoredCmdPattern and \
+              re.compile(self._ignoredCmdPattern).search(command[0]) and \
+              '--help' not in command:
+                event = gIgnoredCmdRun(cmd = command)
+                wx.PostEvent(self, event)
+                return
+
             else:
                 # other GRASS commands (r|v|g|...)
                 try:
@@ -756,7 +735,10 @@
             self.cmdOutput.Unbind(stc.EVT_STC_PAINTED)
 
     def OnCmdOutput(self, event):
-        """!Print command output"""
+        """!Print command output
+
+        Posts event EVT_OUTPUT_TEXT with priority attribute set to 1.
+        """
         message = event.text
         type  = event.type
 
@@ -830,8 +812,11 @@
         event.Skip()
 
     def OnCmdDone(self, event):
-        """!Command done (or aborted)"""
+        """!Command done (or aborted)
 
+        Posts event EVT_MAP_CREATED.
+        """
+
         # Process results here
         try:
             ctime = time.time() - event.time

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2012-11-20 18:40:59 UTC (rev 53941)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2012-11-20 21:10:38 UTC (rev 53942)
@@ -41,7 +41,7 @@
 
 from core.gcmd             import RunCommand, GError, GMessage
 from core.settings         import UserSettings, GetDisplayVectSettings
-from core.utils            import SetAddOnPath
+from core.utils            import SetAddOnPath, GetLayerNameFromCmd
 from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from lmgr.layertree        import LayerTree, LMIcons
@@ -50,7 +50,7 @@
 from modules.mcalc_builder import MapCalcFrame
 from dbmgr.manager         import AttributeManager
 from core.workspace        import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
-from gui_core.goutput      import GConsole, GC_SEARCH, GC_PROMPT, EVT_OUTPUT_TEXT
+from gui_core.goutput      import GConsole, GC_SEARCH, GC_PROMPT, EVT_OUTPUT_TEXT, EVT_IGNORED_CMD_RUN
 from gui_core.dialogs      import GdalOutputDialog, DxfImportDialog, GdalImportDialog, MapLayersDialog
 from gui_core.dialogs      import EVT_APPLY_MAP_LAYERS
 from gui_core.dialogs      import LocationDialog, MapsetDialog, CreateNewVector, GroupDialog
@@ -259,10 +259,13 @@
         self.notebook.AddPage(page = self.notebookLayers, text = _("Map layers"), name = 'layers')
         
         # create 'command output' text area
-        self.goutput = GConsole(self, frame = self,
-                                gcstyle = GC_SEARCH | GC_PROMPT)
+        self.goutput = GConsole(self,
+                                gcstyle = GC_SEARCH | GC_PROMPT,
+                                ignoredCmdPattern = '^d\..*')
         self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
         self.goutput.Bind(EVT_OUTPUT_TEXT, self.OnOutputText)
+        self.goutput.Bind(EVT_IGNORED_CMD_RUN,
+                          lambda event: self.DisplayCmdRun(event.cmd))
         self._setCopyingOfSelectedText()
         
         # create 'search module' notebook page
@@ -533,6 +536,52 @@
             self.SetFocus()
             self.Raise()
 
+    def DisplayCmdRun(self, command):
+        """!Handles display commands.
+
+        @param command command in a list
+        """
+        try:
+            # display GRASS commands
+            layertype = {'d.rast'         : 'raster',
+                         'd.rast3d'       : '3d-raster',
+                         'd.rgb'          : 'rgb',
+                         'd.his'          : 'his',
+                         'd.shaded'       : 'shaded',
+                         'd.legend'       : 'rastleg',
+                         'd.rast.arrow'   : 'rastarrow',
+                         'd.rast.num'     : 'rastnum',
+                         'd.rast.leg'     : 'maplegend',
+                         'd.vect'         : 'vector',
+                         'd.thematic.area': 'thememap',
+                         'd.vect.chart'   : 'themechart',
+                         'd.grid'         : 'grid',
+                         'd.geodesic'     : 'geodesic',
+                         'd.rhumbline'    : 'rhumb',
+                         'd.labels'       : 'labels',
+                         'd.barscale'     : 'barscale',
+                         'd.redraw'       : 'redraw'}[command[0]]
+        except KeyError:
+            GMessage(parent = self,
+                     message = _("Command '%s' not yet implemented in the WxGUI. "
+                                 "Try adding it as a command layer instead.") % command[0])
+            return
+        
+        if layertype == 'barscale':
+            self.GetLayerTree().GetMapDisplay().OnAddBarscale(None)
+        elif layertype == 'rastleg':
+            self.GetLayerTree().GetMapDisplay().OnAddLegend(None)
+        elif layertype == 'redraw':
+            self.GetLayerTree().GetMapDisplay().OnRender(None)
+        else:
+            # add layer into layer tree
+            lname, found = GetLayerNameFromCmd(command, fullyQualified = True,
+                                               layerType = layertype)
+            if found:
+                self.GetLayerTree().AddLayer(ltype = layertype,
+                                             lname = lname,
+                                             lcmd = command)
+
     def GetLayerNotebook(self):
         """!Get Layers Notebook"""
         return self.notebookLayers

Modified: grass/trunk/gui/wxpython/scripts/vkrige.py
===================================================================
--- grass/trunk/gui/wxpython/scripts/vkrige.py	2012-11-20 18:40:59 UTC (rev 53941)
+++ grass/trunk/gui/wxpython/scripts/vkrige.py	2012-11-20 21:10:38 UTC (rev 53942)
@@ -98,7 +98,7 @@
             self.CreatePage(package = Rpackage, Rinstance = Rinstance, controller = controller)
         
         ## Command output. From menuform module, cmdPanel class
-        self.goutput = goutput.GConsole(parent = self, frame = self.parent, margin = False)
+        self.goutput = goutput.GConsole(parent = self, margin = False)
         self.goutputId = self.RPackagesBook.GetPageCount()
         self.outpage = self.RPackagesBook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
         self.goutput.Bind(goutput.EVT_OUTPUT_TEXT, self.OnOutputText)



More information about the grass-commit mailing list