[GRASS-SVN] r37405 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 23 14:11:00 EDT 2009


Author: martinl
Date: 2009-05-23 14:11:00 -0400 (Sat, 23 May 2009)
New Revision: 37405

Modified:
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI: autocompete prompt stage 2 (complete flags/params)


Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2009-05-23 17:39:11 UTC (rev 37404)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2009-05-23 18:11:00 UTC (rev 37405)
@@ -335,6 +335,22 @@
         if grassModule is not None:
             xml.sax.parseString( getInterfaceDescription( grassModule ) , processTask( self ) )
 
+    def get_list_params(self, element = 'name'):
+        """Get list of parameters"""
+        params = []
+        for p in self.params:
+            params.append(p['name'])
+        
+        return params
+
+    def get_list_flags(self, element = 'name'):
+        """Get list of parameters"""
+        flags = []
+        for p in self.flags:
+            flags.append(p['name'])
+        
+        return flags
+    
     def get_param(self, value, element='name', raiseError=True):
         """Find and return a param by name."""
         for p in self.params:
@@ -353,7 +369,7 @@
         param = self.get_param(aParam)
         param['value'] = aValue
             
-    def get_flag( self, aFlag ):
+    def get_flag(self, aFlag):
         """
         Find and return a flag by name.
         """
@@ -368,8 +384,7 @@
         """
         param = self.get_flag(aFlag)
         param['value'] = aValue
-            
-
+        
     def getCmd(self, ignoreErrors = False):
         """
         Produce an array of command name and arguments for feeding
@@ -1777,6 +1792,23 @@
         self.parent = parent
         self.grass_task = None
 
+    def ParseInterface(self, cmd):
+        """Parse interface
+
+        @param cmd command to be parsed (given as list)
+        """
+        grass_task = grassTask()
+        handler = processTask(grass_task)
+        enc = locale.getdefaultlocale()[1]
+        if enc and enc.lower() not in ("utf8", "utf-8"):
+            xml.sax.parseString(getInterfaceDescription(cmd[0]).decode(enc).encode("utf-8"),
+                                handler)
+        else:
+            xml.sax.parseString(getInterfaceDescription(cmd[0]),
+                                handler)
+        
+        return grass_task
+    
     def ParseCommand(self, cmd, gmpath=None, completed=None, parentframe=None,
                      show=True, modal=False):
         """
@@ -1803,16 +1835,8 @@
         self.parent = parentframe
 
         # parse the interface decription
-        self.grass_task = grassTask()
-        handler = processTask(self.grass_task)
-        enc = locale.getdefaultlocale()[1]
-        if enc and enc.lower() not in ("utf8", "utf-8"):
-            xml.sax.parseString(getInterfaceDescription(cmd[0]).decode(enc).encode("utf-8"),
-                                handler)
-        else:
-            xml.sax.parseString(getInterfaceDescription(cmd[0]),
-                                handler)
-        
+        self.grass_task = self.ParseInterface(cmd)
+
         # if layer parameters previously set, re-insert them into dialog
         if completed is not None:
             if 'params' in dcmd_params:

Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-05-23 17:39:11 UTC (rev 37404)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-05-23 18:11:00 UTC (rev 37405)
@@ -24,6 +24,7 @@
 
 import globalvar
 import utils
+import menuform
 
 class GPrompt:
     """Interactive GRASS prompt"""
@@ -131,6 +132,8 @@
         # some variables
         self._choices = choices
         self._hideOnNoMatch = True
+        self._module = None # currently selected module
+        self._params = None # params or flags ?
         self._screenheight = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)
         
         # sort variable needed by listmix
@@ -148,7 +151,8 @@
         listmix.ColumnSorterMixin.__init__(self, 1)
         
         # set choices (list of GRASS modules)
-        self.SetChoices(globalvar.grassCmd['all'])
+        self._choicesCmd = globalvar.grassCmd['all']
+        self.SetChoices(self._choicesCmd)
 
         # bindings...
         self.Bind(wx.EVT_KILL_FOCUS, self.OnControlChanged, self)
@@ -238,7 +242,21 @@
             ###    values = [dd.GetItem(sel, x).GetText()
             ###        for x in xrange(dd.GetColumnCount())]
             ###    self._selectCallback(values)
-            self.SetValue(itemtext)
+            
+            cmd = shlex.split(str(self.GetValue()))
+            if len(cmd) > 1:
+                # -> append text (skip last item)
+                if self._params is True:
+                    self.SetValue(' '.join(cmd[:-1]) + ' ' + itemtext + '=')
+                else:
+                    if len(itemtext) > 1:
+                        prefix = '--'
+                    else:
+                        prefix = '-'
+                    self.SetValue(' '.join(cmd[:-1]) + ' ' + prefix + itemtext)
+            else:
+                # -> reset text
+                self.SetValue(itemtext)
             self.SetInsertionPointEnd()
             
             self._showDropDown(False)
@@ -312,13 +330,35 @@
             event.Skip()
             return
         
+        cmd = shlex.split(str(text))
+        if len(cmd) > 1:
+            # search for module's options
+            if not self._module:
+                self._module = menuform.GUI().ParseInterface(cmd = cmd)
+            
+            if cmd[-1][0] == '-':
+                # -> flags
+                self.SetChoices(self._module.get_list_flags())
+                self._params = False
+            else:
+                # -> options
+                self.SetChoices(self._module.get_list_params())
+                self._params = True
+        else:
+            # search for GRASS modules
+            if self._module:
+                # -> switch back to GRASS modules list
+                self.SetChoices(self._choicesCmd)
+                self._module = None
+                self._params = None
+        
         found = False
         choices = self._choices
         for numCh, choice in enumerate(choices):
             ### if self._matchFunction and self._matchFunction(text, choice):
             ###    found = True
             ### elif
-            if choice.lower().startswith(text.lower()):
+            if choice.lower().startswith(cmd[-1].lower().lstrip('-')):
                 found = True
             if found:
                 self._showDropDown(True)



More information about the grass-commit mailing list