[GRASS-SVN] r43831 - in grass/branches/develbranch_6/gui/wxpython: gui_modules xml

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 9 14:29:57 EDT 2010


Author: martinl
Date: 2010-10-09 18:29:56 +0000 (Sat, 09 Oct 2010)
New Revision: 43831

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
   grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
Log:
wxGUI: v.build.all added to the menu
      fix running commands when module has no required parameter
(merge r43830 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2010-10-09 18:24:44 UTC (rev 43830)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2010-10-09 18:29:56 UTC (rev 43831)
@@ -160,9 +160,9 @@
                  location = None, id =  wx.ID_ANY):
         ElementDialog.__init__(self, parent, title, label = _("Name of mapset:"))
         if location:
-            self.SetTitle(self.GetTitle() + '<%s>' % location)
+            self.SetTitle(self.GetTitle() + ' <%s>' % location)
         else:
-            self.SetTitle(self.GetTitle() + '<%s>' % grass.gisenv()['LOCATION_NAME'])
+            self.SetTitle(self.GetTitle() + ' <%s>' % grass.gisenv()['LOCATION_NAME'])
         
         self.element = gselect.MapsetSelect(parent = self.panel, id = wx.ID_ANY,
                                             size = globalvar.DIALOG_GSELECT_SIZE)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2010-10-09 18:24:44 UTC (rev 43830)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2010-10-09 18:29:56 UTC (rev 43831)
@@ -442,7 +442,7 @@
         except IOError, e:
             self.WriteError(str(e))
             fileHistory = None
-
+        
         cmdString = ' '.join(cmdlist)
         if fileHistory:
             try:
@@ -500,7 +500,6 @@
                     self.parent.curr_page.maptree.AddLayer(ltype=layertype,
                                                            lname=lname,
                                                            lcmd=cmdlist)
-            
             else:
                 #
                 # other GRASS commands (r|v|g|...)
@@ -520,11 +519,18 @@
                     tmpreg = os.getenv("GRASS_REGION")
                     if os.environ.has_key("GRASS_REGION"):
                         del os.environ["GRASS_REGION"]
+
+                if len(cmdlist) == 1:
+                    import menuform
+                    task = menuform.GUI().ParseInterface(cmdlist)
+                    if not task.has_required():
+                        task = None # run command
+                else:
+                    task = None
                 
-                if len(cmdlist) == 1 and cmdlist[0] not in ('v.krige.py'):
-                    import menuform
+                if task and cmdlist[0] not in ('v.krige.py'):
                     # process GRASS command without argument
-                    menuform.GUI().ParseCommand(cmdlist, parentframe=self)
+                    menuform.GUI().ParseCommand(cmdlist, parentframe = self)
                 else:
                     # process GRASS command with argument
                     self.cmdThread.RunCmd(GrassCmd,

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py	2010-10-09 18:24:44 UTC (rev 43830)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py	2010-10-09 18:29:56 UTC (rev 43831)
@@ -255,6 +255,7 @@
             self.popupID13 = wx.NewId()
             self.popupID14 = wx.NewId()
             self.popupID15 = wx.NewId()
+            self.popupID16 = wx.NewId()
 
         self.popupMenu = wx.Menu()
 
@@ -324,10 +325,14 @@
                                     internal=True) == layer.GetName():
                     self.popupMenu.Check(self.popupID14, True)
             
+            self.popupMenu.Append(self.popupID16, text=_("Rebuild topology"))
+            self.Bind(wx.EVT_MENU, self.OnTopology, id=self.popupID16)
+
             if layer.GetMapset() != grass.gisenv()['MAPSET']:
                 # only vector map in current mapset can be edited
                 self.popupMenu.Enable (self.popupID5, False)
                 self.popupMenu.Enable (self.popupID6, False)
+                self.popupMenu.Enable (self.popupID16, False)
             elif digitToolbar and digitToolbar.GetLayer():
                 # vector map already edited
                 vdigitLayer = digitToolbar.GetLayer()
@@ -340,6 +345,8 @@
                     self.popupMenu.Enable(self.popupID1, False)
                     # disable 'bgmap'
                     self.popupMenu.Enable(self.popupID14, False)
+                    # disable 'topology'
+                    self.popupMenu.Enable (self.popupID16, False)
                 else:
                     # disable 'start editing'
                     self.popupMenu.Enable(self.popupID5, False)
@@ -388,6 +395,13 @@
         self.PopupMenu(self.popupMenu)
         self.popupMenu.Destroy()
 
+    def OnTopology(self, event):
+        """!Rebuild topology of selected vector map"""
+        mapLayer = self.GetPyData(self.layer_selected)[0]['maplayer']
+        cmd = ['v.build',
+               'map=%s' % mapLayer.GetName()]
+        self.lmgr.goutput.RunCmd(cmd, switchPage = True)
+        
     def OnMetadata(self, event):
         """!Print metadata of raster/vector map layer
         TODO: Dialog to modify metadata

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-10-09 18:24:44 UTC (rev 43830)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-10-09 18:29:56 UTC (rev 43831)
@@ -319,9 +319,9 @@
 class grassTask:
     """!This class holds the structures needed for both filling by the
     parser and use by the interface constructor.
-
+    
     Use as either grassTask() for empty definition or
-    grassTask('grass.command' ) for parsed filling.
+    grassTask('grass.command') for parsed filling.
     """
     def __init__(self, grassModule = None):
         self.name = _('unknown')
@@ -381,9 +381,8 @@
             return None
         
     def set_param(self, aParam, aValue, element = 'value'):
+        """!Set param value/values.
         """
-        Set param value/values.
-        """
         try:
             param = self.get_param(aParam)
         except ValueError:
@@ -392,18 +391,16 @@
         param[element] = aValue
             
     def get_flag(self, aFlag):
+        """!Find and return a flag by name.
         """
-        Find and return a flag by name.
-        """
         for f in self.flags:
             if f['name'] == aFlag:
                 return f
         raise ValueError, _("Flag not found: %s") % aFlag
 
     def set_flag(self, aFlag, aValue, element = 'value'):
+        """!Enable / disable flag.
         """
-        Enable / disable flag.
-        """
         try:
             param = self.get_flag(aFlag)
         except ValueError:
@@ -432,7 +429,7 @@
     def getCmd(self, ignoreErrors = False):
         """!Produce an array of command name and arguments for feeding
         into some execve-like command processor.
-
+        
         If ignoreErrors==True then it will return whatever has been
         built so far, even though it would not be a correct command
         for GRASS.
@@ -460,7 +457,7 @@
             raise ValueError, '\n'.join(errList)
         
         return cmd
-
+    
     def set_options(self, opts):
         """!Set flags and parameters
 
@@ -477,6 +474,14 @@
         return { 'flags'  : self.flags,
                  'params' : self.params }
     
+    def has_required(self):
+        """!Check if command has at least one required paramater"""
+        for p in self.params:
+            if p.get('required', False) == True:
+                return True
+        
+        return False
+
 class processTask:
     """!A ElementTree handler for the --interface-description output,
     as defined in grass-interface.dtd. Extend or modify this and the
@@ -845,7 +850,7 @@
 
         @param returncode command's return code (0 for success)
         """
-        if self.parent.GetName() != 'LayerTree' or \
+        if self.parent and self.parent.GetName() != 'LayerTree' or \
                 returncode != 0:
             return
         
@@ -881,22 +886,21 @@
         """!Run the command"""
         cmd = self.createCmd()
         
-        if cmd == None or len(cmd) < 2:
+        if not cmd or len(cmd) < 1:
             return
-
+        
         if self.standalone or cmd[0][0:2] != "d.":
             # Send any non-display command to parent window (probably wxgui.py)
-            # put to parents
-            # switch to 'Command output'
+            # put to parents switch to 'Command output'
             if self.notebookpanel.notebook.GetSelection() != self.notebookpanel.goutputId:
                 self.notebookpanel.notebook.SetSelection(self.notebookpanel.goutputId)
             
             try:
+                
                 self.goutput.RunCmd(cmd, onDone = self.OnDone)
             except AttributeError, e:
                 print >> sys.stderr, "%s: Propably not running in wxgui.py session?" % (e)
                 print >> sys.stderr, "parent window is: %s" % (str(self.parent))
-            # Send any other command to the shell.
         else:
             gcmd.Command(cmd)
         
@@ -906,8 +910,7 @@
                     self.btn_clipboard,
                     self.btn_help):
             btn.Enable(False)
-        ### self.btn_abort.Enable(True)
-
+        
     def OnAbort(self, event):
         """!Abort running command"""
         event = goutput.wxCmdAbort(aborted=True)
@@ -1940,7 +1943,7 @@
                         key, value = option.split('=', 1)
                     except:
                         if i == 0: # add key name of first parameter if not given
-                            key = self.grass_task.firstParam
+                            key = self.grass_task.get_options()['params'][0]['name']
                             value = option
                         else:
                             raise ValueError, _("Unable to parse command %s") % ' '.join(cmd)

Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml	2010-10-09 18:24:44 UTC (rev 43830)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml	2010-10-09 18:29:56 UTC (rev 43831)
@@ -1853,6 +1853,13 @@
 	      <command>v.build</command>
 	    </menuitem>
 	    <menuitem>
+	      <label>Rebuild topology on all vector maps</label>
+	      <help>Rebuilds topology on all vector maps in the current mapset..</help>
+	      <keywords>vector,topology</keywords>
+	      <handler>OnMenuCmd</handler>
+	      <command>v.build.all</command>
+	    </menuitem>
+	    <menuitem>
 	      <label>Clean vector map</label>
 	      <help>Toolset for cleaning topology of vector map.</help>
 	      <keywords>vector,topology</keywords>



More information about the grass-commit mailing list