[GRASS-dev] strange behavior of gselect.Select

Luca Delucchi lucadeluge at gmail.com
Thu Jan 14 00:50:08 PST 2016


On 14 January 2016 at 04:07, Anna Petrášová <kratochanna at gmail.com> wrote:
>
>> ok, in my case I'm speaking about a wx.combo.ComboCtrl but probably is
>> the same. Could I add an option style (set by default to None) in
>> Select class of gselect.py?
>>
> Yes. I have some doubts it will work consistently across all platforms, but
> I can test on Windows if you need.
>

Yes please, could you test the attached diff on Windows?
Is there anyone could test it also on mac?

I tested it on Linux/Debian with wx python version 3.0.1.1 and it
works correctly.


-- 
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org
-------------- next part --------------
Index: gui/wxpython/gui_core/gselect.py
===================================================================
--- gui/wxpython/gui_core/gselect.py	(revision 67560)
+++ gui/wxpython/gui_core/gselect.py	(working copy)
@@ -79,7 +79,7 @@
                  type = None, multiple = False, nmaps = 1,
                  mapsets = None, updateOnPopup = True, onPopup = None,
                  fullyQualified = True, extraItems = {}, layerTree = None,
-                 validator = wx.DefaultValidator):
+                 validator = wx.DefaultValidator, style = 0):
         """Custom control to create a ComboBox with a tree control to
         display and select GIS elements within acessible mapsets.
         Elements can be selected with mouse. Can allow multiple
@@ -97,12 +97,13 @@
         :param layerTree: show only elements from given layer tree if not None
         :param validator: validator for TextCtrl
         """
-        wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size, validator=validator)
+        wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size,
+                                    validator=validator, style=style)
         if globalvar.CheckWxVersion([3]):
             self.SetName("Select")
         else:
             self.GetChildren()[0].SetName("Select")
-            
+
         self.GetChildren()[0].type = type
 
         self.tcp = TreeCtrlComboPopup()
@@ -291,7 +292,7 @@
 
     def OnKeyUp(self, event):
         """Enable to select items using keyboard.
-        
+
         Unused with wxPython 3, can be removed in the future.
         """
         item = self.seltree.GetSelection()
@@ -436,7 +437,7 @@
         """
         # get current mapset
         curr_mapset = grass.gisenv()['MAPSET']
-        
+
         # map element types to g.list types
         elementdict = {'cell': 'raster',
                        'raster': 'raster',
@@ -589,7 +590,7 @@
     def OnKeyUp(self, event):
         """Enables to select items using keyboard
 
-        Unused with wxPython 3, can be removed in the future.        
+        Unused with wxPython 3, can be removed in the future.
         """
 
         item = self.seltree.GetSelection()
@@ -1358,7 +1359,7 @@
         else:
             extList = vectorFormatExtension
             fileMask += '%(name)s (*.%(low)s;*.%(up)s)|*.%(low)s;*.%(up)s|' % {'name': 'ESRI Shapefile', 'low': 'shp', 'up': 'SHP'}
-        
+
         for name, ext in sorted(extList.items()):
             if name in ('ESRI Shapefile', 'GeoTIFF'):
                 continue
@@ -1435,7 +1436,7 @@
                                              startDirectory=os.getcwd(),
                                              changeCallback=self.OnUpdate)
         browse.GetChildren()[1].SetName('GdalSelectDataSource')
-        
+
         self.dbWidgets['browse'] = browse
         self.dbWidgets['choice'] = wx.Choice(parent=self.dbPanel, name='GdalSelectDataSource')
         self.dbWidgets['choice'].Bind(wx.EVT_CHOICE, self.OnUpdate)
@@ -1786,7 +1787,7 @@
             settingsFile = os.path.join(GetSettingsPath(), 'wxOGR')
         else:
             settingsFile = os.path.join(GetSettingsPath(), 'wxGDAL')
-            
+
         self.settsManager = ManageSettingsWidget(parent=self,
                                                  settingsFile=settingsFile)
         self.settsManager.settingsChanged.connect(self.OnSettingsChanged)
@@ -1924,7 +1925,7 @@
 
             # v.external returns info for individual bands, however projection is shared by all bands ->
             # (it is possible to take first line)
-            
+
             lines = ret.splitlines()
             projectionMatch = '0'
             if lines:
@@ -1987,7 +1988,7 @@
                     listData.append((layerId, baseName, projectionMatchCaption, grassName))
                     data.append((layerId, baseName,  int(projectionMatch), grassName))
                     layerId += 1
-        
+
         # emit signal
         self.reloadDataRequired.emit(listData=listData, data=data)
 
@@ -2317,16 +2318,16 @@
         self.task=task
         self.parent = parent
         self.giface = giface
-        
+
         self.selectedFeatures = None
         self.registered = False
         self._vectorSelect = None
 
         self.mapdisp = self.giface.GetMapDisplay()
-        
+
         self.catsField = wx.TextCtrl(parent=self, id=wx.ID_ANY,
                                      size=globalvar.DIALOG_TEXTCTRL_SIZE)
-        
+
         icon = wx.Bitmap(os.path.join(globalvar.ICONDIR, "grass", "select.png"))
         self.buttonVecSelect = buttons.ThemedGenBitmapToggleButton(parent=self, id=wx.ID_ANY,
                                                                    bitmap=icon,
@@ -2333,13 +2334,13 @@
                                                                    size=globalvar.DIALOG_COLOR_SIZE)
         self.buttonVecSelect.Bind(wx.EVT_BUTTON, self._onClick)
 
-        
+
         if self.mapdisp:
             switcher = self.mapdisp.GetToolSwitcher()
             switcher.AddCustomToolToGroup(group='mouseUse',
                                           btnId=self.buttonVecSelect.GetId(),
                                           toggleHandler=self.buttonVecSelect.SetValue)
-        
+
         self._layout()
 
     def _isMapSelected(self):
@@ -2350,7 +2351,7 @@
         if layerSelected is None:
             GWarning(_("No vector map selected in layer manager. Operation canceled."))
             return False
-        
+
         return True
 
     def _chckMap(self):
@@ -2398,7 +2399,7 @@
     def OnClose(self, event=None):
         if not self.mapdisp:
             return
-        
+
         switcher = self.mapdisp.GetToolSwitcher()
         switcher.RemoveCustomToolFromGroup(self.buttonVecSelect.GetId())
         if self._vectorSelect is not None:
Index: gui/wxpython/tplot/frame.py
===================================================================
--- gui/wxpython/tplot/frame.py	(revision 67560)
+++ gui/wxpython/tplot/frame.py	(working copy)
@@ -51,6 +51,7 @@
 from core import globalvar
 from grass.pygrass.vector.geometry import Point
 from grass.pygrass.raster import RasterRow
+from grass.pygrass.gis.region import Region
 from collections import OrderedDict
 from subprocess import PIPE
 try:
@@ -107,6 +108,7 @@
         self.dbif = tgis.SQLDatabaseInterfaceConnection()
         self.dbif.connect()
         self.Bind(wx.EVT_CLOSE, self.onClose)
+        self.region = Region()
 
     def init(self):
         self.timeDataR = OrderedDict()
@@ -214,12 +216,19 @@
         self.datasetSelectLabelV = wx.StaticText(parent=self.controlPanelVector,
                                                  id=wx.ID_ANY,
                                                  label=_('Vector temporal '
-                                                         'dataset (strds)'))
+                                                         'dataset (strds)\n'
+                                                         'Please press enter if'
+                                                         ' you digit the name'
+                                                         ' instead select with'
+                                                         ' combobox'))
         self.datasetSelectV = gselect.Select(parent=self.controlPanelVector,
                                              id=wx.ID_ANY,
                                              size=globalvar.DIALOG_GSELECT_SIZE,
-                                             type='stvds', multiple=True)
-        self.datasetSelectV.Bind(wx.EVT_TEXT, self.OnVectorSelected)
+                                             type='stvds', multiple=True,
+                                             style=wx.TE_PROCESS_ENTER)
+        self.datasetSelectV.Bind(wx.EVT_TEXT_ENTER, self.OnVectorSelected)
+        self.datasetSelectV.Bind(wx.EVT_COMBOBOX_CLOSEUP,
+                                 self.OnVectorSelected)
 
         self.attribute = gselect.ColumnSelect(parent=self.controlPanelVector)
         self.attributeLabel = wx.StaticText(parent=self.controlPanelVector,
@@ -281,6 +290,10 @@
         """Load data and read properties
         :param list timeseries: a list of timeseries
         """
+        if not self.poi:
+            GError(parent=self, message=_("Invalid input coordinates"),
+                   showTraceback=False)
+            return
         mode = None
         unit = None
         columns = ','.join(['name', 'start_time', 'end_time'])
@@ -683,6 +696,12 @@
                     GError(parent=self, message=_("Invalid input coordinates"),
                            showTraceback=False)
                     return
+                bbox = self.region.get_bbox()
+                if not bbox.contains(self.poi):
+                    GError(parent=self, message=_("Seed point outside the "
+                                                  "current region"),
+                           showTraceback=False)
+                    return
         # check raster dataset
         if datasetsR:
             datasetsR = datasetsR.split(',')
@@ -838,11 +857,20 @@
     def OnVectorSelected(self, event):
         """Update the controlbox related to stvds"""
         dataset = self.datasetSelectV.GetValue().strip()
-        vect_list = grass.read_command('t.vect.list', flags='s', input=dataset,
-                                       col='name')
-        vect_list = list(set(sorted(vect_list.split())))
-        for vec in vect_list:
-            self.attribute.InsertColumns(vec, 1)
+        if dataset:
+            try:
+                vect_list = grass.read_command('t.vect.list', flags='s',
+                                               input=dataset, column='name')
+            except Exception:
+                self.attribute.Clear()
+                GError(parent=self, message=_("Invalid input temporal dataset"),
+                       showTraceback=False)
+                return
+            vect_list = list(set(sorted(vect_list.split())))
+            for vec in vect_list:
+                self.attribute.InsertColumns(vec, 1)
+        else:
+            return
 
 
 class LookUp:


More information about the grass-dev mailing list