瀏覽代碼

wxGUI/GConsole: fixing usage of command event and fixing d commands without parameters (in Layer Manager)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54024 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 12 年之前
父節點
當前提交
c9471be413
共有 3 個文件被更改,包括 21 次插入10 次删除
  1. 11 3
      gui/wxpython/core/events.py
  2. 2 2
      gui/wxpython/core/gconsole.py
  3. 8 5
      gui/wxpython/lmgr/frame.py

+ 11 - 3
gui/wxpython/core/events.py

@@ -5,12 +5,20 @@
 
 
 Put here only truly general events. Once you find that your event can be
 Put here only truly general events. Once you find that your event can be
 generated in more than one class, put your event here. Otherwise,
 generated in more than one class, put your event here. Otherwise,
-leave it in your class file.
+leave it in your class file. Events are expected to be grass/gis related.
 
 
 General notice:
 General notice:
-Command events are propagated to parent windows. However they do not propagate 
+Command events are propagated to parent windows. However, they do not propagate 
 beyond dialogs. Events do not propagate at all.
 beyond dialogs. Events do not propagate at all.
-
+Command events works only with windows, not EvtHandlers, so for other objects
+than windows you need to have extra parameter - guiparent - which can be used
+for creating command events.
+\code
+mapEvent = gMapCreated(self._guiparent.GetId(), ...)
+wx.PostEvent(self._guiparent, mapEvent)
+\endcode
+
+@todo naming conventions for events
 
 
 (C) 2012 by the GRASS Development Team
 (C) 2012 by the GRASS Development Team
 
 

+ 2 - 2
gui/wxpython/core/gconsole.py

@@ -641,9 +641,9 @@ class GConsole(wx.EvtHandler):
                 name = p.get('value')
                 name = p.get('value')
                 if '@' not in name:
                 if '@' not in name:
                     name = name + '@' + grass.gisenv()['MAPSET']
                     name = name + '@' + grass.gisenv()['MAPSET']
-                mapEvent = gMapCreated(wx.ID_ANY,
+                mapEvent = gMapCreated(self._guiparent.GetId(),
                                        name=name, ltype=prompt, add=None)
                                        name=name, ltype=prompt, add=None)
-                wx.PostEvent(self, mapEvent)
+                wx.PostEvent(self._guiparent, mapEvent)
 
 
         event.Skip()
         event.Skip()
 
 

+ 8 - 5
gui/wxpython/lmgr/frame.py

@@ -40,7 +40,7 @@ except ImportError:
 sys.path.append(os.path.join(globalvar.ETCDIR, "python"))
 sys.path.append(os.path.join(globalvar.ETCDIR, "python"))
 from grass.script          import core as grass
 from grass.script          import core as grass
 
 
-from core.gcmd             import RunCommand, GError, GMessage
+from core.gcmd             import RunCommand, GError, GMessage, GException
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.utils            import SetAddOnPath, GetLayerNameFromCmd
 from core.utils            import SetAddOnPath, GetLayerNameFromCmd
 from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
 from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
@@ -566,6 +566,9 @@ class GMFrame(wx.Frame):
             self.RunDisplayCmd(command)
             self.RunDisplayCmd(command)
         elif re.compile('r[3]?\.mapcalc').search(command[0]):
         elif re.compile('r[3]?\.mapcalc').search(command[0]):
             self.OnMapCalculator(event = None, cmd = command)
             self.OnMapCalculator(event = None, cmd = command)
+        else:
+            raise ValueError('Layer Manger special command (%s)'
+                             ' not supported.' % ' '.join(command))
 
 
     def RunDisplayCmd(self, command):
     def RunDisplayCmd(self, command):
         """!Handles display commands.
         """!Handles display commands.
@@ -610,10 +613,9 @@ class GMFrame(wx.Frame):
             # add layer into layer tree
             # add layer into layer tree
             lname, found = GetLayerNameFromCmd(command, fullyQualified = True,
             lname, found = GetLayerNameFromCmd(command, fullyQualified = True,
                                                layerType = layertype)
                                                layerType = layertype)
-            if found:
-                self.GetLayerTree().AddLayer(ltype = layertype,
-                                             lname = lname,
-                                             lcmd = command)
+            self.GetLayerTree().AddLayer(ltype = layertype,
+                                         lname = lname,
+                                         lcmd = command)
 
 
     def GetLayerNotebook(self):
     def GetLayerNotebook(self):
         """!Get Layers Notebook"""
         """!Get Layers Notebook"""
@@ -1667,6 +1669,7 @@ class GMFrame(wx.Frame):
                                        lgroup = None)
                                        lgroup = None)
 
 
     def OnMapCreated(self, event):
     def OnMapCreated(self, event):
+        """!Decides wheter the map should be added to layer tree."""
         if event.add is None:
         if event.add is None:
             if UserSettings.Get(group = 'cmd',
             if UserSettings.Get(group = 'cmd',
                                 key = 'addNewLayer', subkey = 'enabled'):
                                 key = 'addNewLayer', subkey = 'enabled'):