[GRASS-SVN] r58689 - grass/trunk/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 12 15:03:05 PST 2014


Author: annakrat
Date: 2014-01-12 15:03:05 -0800 (Sun, 12 Jan 2014)
New Revision: 58689

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

Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py	2014-01-12 23:02:41 UTC (rev 58688)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py	2014-01-12 23:03:05 UTC (rev 58689)
@@ -298,54 +298,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'
-                    else:
-                        toComplete['entity'] = 'params+flags'
+            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:
-                    # 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 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'
+                    toComplete['entity'] = 'params+flags'
             else:
-                return None
+                # 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:
+                        return toComplete
+                    
+                    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
@@ -393,8 +390,6 @@
             self.InsertText(pos, '.')
             self.CharRight()
             self.toComplete = self.EntityToComplete()
-            if self.toComplete is None:
-                return
             try:
                 if self.toComplete['entity'] == 'command': 
                     for command in globalvar.grassCmd:
@@ -433,14 +428,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 ('@')
@@ -450,7 +444,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()
             
@@ -458,8 +452,6 @@
         elif event.GetKeyCode() == wx.WXK_SPACE and event.ControlDown():
             self.autoCompList = list()
             self.toComplete = self.EntityToComplete()
-            if self.toComplete is None:
-                return 
 
             #complete command
             if self.toComplete['entity'] == 'command':



More information about the grass-commit mailing list