[GRASS-SVN] r52808 - grass/branches/develbranch_6/gui/wxpython/modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 21 03:50:28 PDT 2012


Author: annakrat
Date: 2012-08-21 03:50:27 -0700 (Tue, 21 Aug 2012)
New Revision: 52808

Modified:
   grass/branches/develbranch_6/gui/wxpython/modules/mcalc_builder.py
Log:
wxGUI/mapcalc: fix #1305, improving focus problem when adding map (merge from trunk, r52807)

Modified: grass/branches/develbranch_6/gui/wxpython/modules/mcalc_builder.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/modules/mcalc_builder.py	2012-08-21 10:43:43 UTC (rev 52807)
+++ grass/branches/develbranch_6/gui/wxpython/modules/mcalc_builder.py	2012-08-21 10:50:27 UTC (rev 52808)
@@ -111,6 +111,11 @@
             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'))
@@ -236,7 +241,7 @@
         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)
@@ -389,11 +394,26 @@
         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):



More information about the grass-commit mailing list