瀏覽代碼

wxGUI/mapcalc: fix https://trac.osgeo.org/grass/ticket/1305, improving focus problem when adding map

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52807 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 年之前
父節點
當前提交
8ec906b625
共有 1 個文件被更改,包括 23 次插入3 次删除
  1. 23 3
      gui/wxpython/modules/mcalc_builder.py

+ 23 - 3
gui/wxpython/modules/mcalc_builder.py

@@ -111,6 +111,11 @@ class MapCalcFrame(wx.Frame):
             element = 'rast3d'
         else:
             element = 'cell'
+
+        # characters which can be in raster map name but the map name must be then quoted
+        self.charactersToQuote = '+-&!<>%~?^|'
+        # stores last typed map name in Select widget to distinguish typing from selection
+        self.lastMapName = ''
         
         self.operatorBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                         label=" %s " % _('Operators'))
@@ -244,7 +249,7 @@ class MapCalcFrame(wx.Frame):
         self.btn_save.Bind(wx.EVT_BUTTON, self.OnSaveExpression)
         self.btn_load.Bind(wx.EVT_BUTTON, self.OnLoadExpression)
         
-        self.mapselect.Bind(wx.EVT_TEXT, self.OnSelect)
+        self.mapselect.Bind(wx.EVT_TEXT, self.OnSelectTextEvt)
         self.function.Bind(wx.EVT_COMBOBOX, self._return_funct)
         self.function.Bind(wx.EVT_TEXT_ENTER, self.OnSelect)
         self.newmaptxt.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
@@ -404,11 +409,26 @@ class MapCalcFrame(wx.Frame):
         elif event.GetId() == self.btn['parenr'].GetId(): mark = ")"
         self._addSomething(mark)
         
+    def OnSelectTextEvt(self, event):
+        """!Checks if user is typing or the event was emited by map selection.
+        Prevents from changing focus.
+        """
+        item = event.GetString()
+        if not (abs(len(item) - len(self.lastMapName)) == 1  and \
+            self.lastMapName in item or item in self.lastMapName):
+            self.OnSelect(event)
+        self.lastMapName = item
+
     def OnSelect(self, event):
         """!Gets raster map or function selection and send it to
-        insertion method
+        insertion method. 
+
+        Checks for characters which can be in raster map name but 
+        the raster map name must be then quoted.
         """
-        item = event.GetString()
+        item = event.GetString().strip()
+        if any((char in item) for char in self.charactersToQuote):
+            item = '"' + item + '"'
         self._addSomething(item)
 
     def OnUpdateStatusBar(self, event):