[GRASS-SVN] r64876 - in grass/trunk/gui/wxpython: gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 16 11:14:25 PDT 2015


Author: martinl
Date: 2015-03-16 11:14:25 -0700 (Mon, 16 Mar 2015)
New Revision: 64876

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/gui_core/widgets.py
   grass/trunk/gui/wxpython/lmgr/layertree.py
Log:
wxGUI: implement MapValidator
       update NewVectorDialog and OnCopyMap to use this validator


Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2015-03-16 15:30:32 UTC (rev 64875)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2015-03-16 18:14:25 UTC (rev 64876)
@@ -50,7 +50,7 @@
 from gui_core.gselect import LocationSelect, MapsetSelect, Select, \
                              OgrTypeSelect, GdalSelect, MapsetSelect, \
                              SubGroupSelect
-from gui_core.widgets import SingleSymbolPanel, GListCtrl, SimpleValidator
+from gui_core.widgets import SingleSymbolPanel, GListCtrl, SimpleValidator, MapValidator
 from core.utils import GetValidLayerName, _
 from core.settings import UserSettings, GetDisplayVectSettings
 from core.debug import Debug
@@ -199,7 +199,7 @@
         
         self.element = Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
                               type = 'vector', layerTree = layerTree,
-                              validator = SimpleValidator(callback = self.ValidatorCallback))
+                              validator = MapValidator())
         self.element.SetFocus()
         
         self.warning = _("Name of vector map is missing.")

Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py	2015-03-16 15:30:32 UTC (rev 64875)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py	2015-03-16 18:14:25 UTC (rev 64876)
@@ -16,6 +16,10 @@
  - widgets::FloatValidator
  - widgets::EmailValidator
  - widgets::TimeISOValidator
+ - widgets::MapValidator
+ - widgets::NTCValidator
+ - widgets::SimpleValidator
+ - widgets::GenericValidator
  - widgets::GListCtrl
  - widgets::SearchModuleWidget
  - widgets::ManageSettingsWidget
@@ -65,6 +69,8 @@
 except ImportError:
     import wx.lib.customtreectrl as CT
 
+from grass.script import core as grass
+
 from grass.pydispatch.signal import Signal
 
 from core        import globalvar
@@ -657,7 +663,6 @@
         """Clone validator"""
         return TimeISOValidator()
 
-
 class NTCValidator(wx.PyValidator):
     """validates input in textctrls, taken from wxpython demo"""
     def __init__(self, flag=None):
@@ -772,7 +777,22 @@
         """
         return True # Prevent wxDialog from complaining.
 
+class MapValidator(GenericValidator):
+    """Validator for map name input
 
+    See G_legal_filename()
+    """
+    def __init__(self):
+        def _mapNameValidationFailed(ctrl):
+            message = _("Name <%(name)s> is not a valid name for GRASS map. "
+                        "Please use only ASCII characters excluding %(chars)s "
+                        "and space.") % {'name': ctrl.GetValue(), 'chars': '/"\'@,=*~'}
+            GError(message, caption=_("Invalid name"))
+        
+        GenericValidator.__init__(self,
+                                  grass.legal_name,
+                                  _mapNameValidationFailed)
+       
 class SingleSymbolPanel(wx.Panel):
     """Panel for displaying one symbol.
 

Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py	2015-03-16 15:30:32 UTC (rev 64875)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py	2015-03-16 18:14:25 UTC (rev 64876)
@@ -45,7 +45,7 @@
 from core.gcmd            import GWarning, GError, RunCommand
 from icons.icon           import MetaIcon
 from web_services.dialogs import SaveWMSLayerDialog
-from gui_core.widgets import GenericValidator
+from gui_core.widgets import MapValidator
 from lmgr.giface import LayerManagerGrassInterfaceForMapDisplay
 from core.giface import Notification
 
@@ -783,12 +783,6 @@
         GUI(parent = self, centreOnParent = False).ParseCommand(['v.colors',
                                                                  'map=%s' % name])
         
-    def _mapNameValidationFailed(self, ctrl):
-        message = _("Name <%(name)s> is not a valid name for GRASS map. "
-                    "Please use only ASCII characters excluding %(chars)s "
-                    "and space.") % {'name': ctrl.GetValue(), 'chars': '/"\'@,=*~'}
-        GError(parent=self, message=message, caption=_("Invalid name"))
-
     def OnCopyMap(self, event):
         """Copy selected map into current mapset"""
         layer = self.GetSelectedLayer()
@@ -816,7 +810,7 @@
                               message = _('Enter name for the new %s in the current mapset:') % label.lower(),
                               caption = _('Make a copy of %s <%s>') % (label.lower(), lnameSrc),
                               defaultValue = lnameSrc.split('@')[0],
-                              validator = GenericValidator(grass.legal_name, self._mapNameValidationFailed),
+                              validator = MapValidator(),
                               size = (700, -1))
         if dlg.ShowModal() == wx.ID_OK:
             lnameDst = dlg.GetValue()



More information about the grass-commit mailing list