[GRASS-SVN] r58691 - grass/branches/develbranch_6/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 12 15:04:43 PST 2014


Author: annakrat
Date: 2014-01-12 15:04:43 -0800 (Sun, 12 Jan 2014)
New Revision: 58691

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py
Log:
wxGUI/prompt: fix #1963 ('ls -' error); improve autocompletion just after command (merge from trunk, r58689)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py	2014-01-12 23:04:03 UTC (rev 58690)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py	2014-01-12 23:04:43 UTC (rev 58691)
@@ -857,54 +857,51 @@
         """!Determines which part of command (flags, parameters) should
         be completed at current cursor position"""
         entry = self.GetTextLeft()
-        toComplete = dict()
+        toComplete = dict(cmd=None, entity=None)
         try:
             cmd = entry.split()[0].strip()
         except IndexError:
-            return None
+            return toComplete
         
         try:
             splitted = utils.split(str(entry))
         except ValueError: # No closing quotation error
-            return None
-        if len(splitted) > 1:
-            if cmd in globalvar.grassCmd:
-                toComplete['cmd'] = cmd
-                if entry[-1] == ' ':
-                    words = entry.split(' ')
-                    if any(word.startswith('-') for word in words):
-                        toComplete['entity'] = 'params'
+            return toComplete
+        if len(splitted) > 0 and cmd in globalvar.grassCmd:
+            toComplete['cmd'] = cmd
+            if entry[-1] == ' ':
+                words = entry.split(' ')
+                if any(word.startswith('-') for word in words):
+                    toComplete['entity'] = 'params'
+                else:
+                    toComplete['entity'] = 'params+flags'
+            else:
+                # get word left from current position
+                word = self.GetWordLeft(withDelimiter = True)
+                
+                if word[0] == '=' and word[-1] == '@':
+                    toComplete['entity'] = 'mapsets'
+                elif word[0] == '=':
+                    # get name of parameter
+                    paramName = self.GetWordLeft(withDelimiter = False, ignoredDelimiter = '=').strip('=')
+                    if paramName:
+                        try:
+                            param = self.cmdDesc.get_param(paramName)
+                        except (ValueError, AttributeError):
+                            return toComplete
                     else:
-                        toComplete['entity'] = 'params+flags'
-                else:
-                    # get word left from current position
-                    word = self.GetWordLeft(withDelimiter = True)
+                        return toComplete
                     
-                    if word[0] == '=' and word[-1] == '@':
-                        toComplete['entity'] = 'mapsets'
-                    elif word[0] == '=':
-                        # get name of parameter
-                        paramName = self.GetWordLeft(withDelimiter = False, ignoredDelimiter = '=').strip('=')
-                        if paramName:
-                            try:
-                                param = self.cmdDesc.get_param(paramName)
-                            except (ValueError, AttributeError):
-                                return None
-                        else:
-                            return None
-                        
-                        if param['values']:
-                            toComplete['entity'] = 'param values'
-                        elif param['prompt'] == 'raster' and param['element'] == 'cell':
-                            toComplete['entity'] = 'raster map'
-                        elif param['prompt'] == 'vector' and param['element'] == 'vector':
-                            toComplete['entity'] = 'vector map'
-                    elif word[0] == '-':
-                        toComplete['entity'] = 'flags'
-                    elif word[0] == ' ':
-                        toComplete['entity'] = 'params'
-            else:
-                return None
+                    if param['values']:
+                        toComplete['entity'] = 'param values'
+                    elif param['prompt'] == 'raster' and param['element'] == 'cell':
+                        toComplete['entity'] = 'raster map'
+                    elif param['prompt'] == 'vector' and param['element'] == 'vector':
+                        toComplete['entity'] = 'vector map'
+                elif word[0] == '-':
+                    toComplete['entity'] = 'flags'
+                elif word[0] == ' ':
+                    toComplete['entity'] = 'params'
         else:
             toComplete['entity'] = 'command'
             toComplete['cmd'] = cmd
@@ -954,7 +951,14 @@
             self.toComplete = self.EntityToComplete()
             try:
                 if self.toComplete['entity'] == 'command': 
-                    self.autoCompList = self.moduleList[entry.strip()]
+                    for command in globalvar.grassCmd:
+                        try:
+                            if command.find(self.toComplete['cmd']) == 0:
+                                dotNumber = list(self.toComplete['cmd']).count('.') 
+                                self.autoCompList.append(command.split('.',dotNumber)[-1])
+                        except UnicodeDecodeError, e: # TODO: fix it
+                            sys.stderr.write(DecodeString(command) + ": " + unicode(e))
+                            
             except (KeyError, TypeError):
                 return
             self.ShowList()
@@ -983,14 +987,13 @@
             self.InsertText(pos, '=')
             self.CharRight()
             self.toComplete = self.EntityToComplete()
-            if self.toComplete and 'entity' in self.toComplete:
-                if self.toComplete['entity'] == 'raster map':
-                    self.autoCompList = self.mapList['raster']
-                elif self.toComplete['entity'] == 'vector map':
-                    self.autoCompList = self.mapList['vector']
-                elif self.toComplete['entity'] == 'param values':
-                    param = self.GetWordLeft(withDelimiter = False, ignoredDelimiter='=').strip(' =')
-                    self.autoCompList = self.cmdDesc.get_param(param)['values']
+            if self.toComplete['entity'] == 'raster map':
+                self.autoCompList = self.mapList['raster']
+            elif self.toComplete['entity'] == 'vector map':
+                self.autoCompList = self.mapList['vector']
+            elif self.toComplete['entity'] == 'param values':
+                param = self.GetWordLeft(withDelimiter = False, ignoredDelimiter='=').strip(' =')
+                self.autoCompList = self.cmdDesc.get_param(param)['values']
             self.ShowList()
         
         # complete mapset ('@')
@@ -1000,7 +1003,7 @@
             self.CharRight()
             self.toComplete = self.EntityToComplete()
             
-            if self.toComplete and self.toComplete['entity'] == 'mapsets':
+            if self.toComplete['entity'] == 'mapsets':
                 self.autoCompList = self.mapsetList
             self.ShowList()
             



More information about the grass-commit mailing list