浏览代码

wxGUI: implement MapValidator
update NewVectorDialog and OnCopyMap to use this validator
(merge https://trac.osgeo.org/grass/changeset/64876 from trunk)


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@64922 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 年之前
父节点
当前提交
3ad810e2c2
共有 3 个文件被更改,包括 25 次插入10 次删除
  1. 2 2
      gui/wxpython/gui_core/dialogs.py
  2. 21 0
      gui/wxpython/gui_core/widgets.py
  3. 2 8
      gui/wxpython/lmgr/layertree.py

+ 2 - 2
gui/wxpython/gui_core/dialogs.py

@@ -50,7 +50,7 @@ from core.gcmd import GError, RunCommand, GMessage
 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 @@ class VectorDialog(SimpleDialog):
         
         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.")

+ 21 - 0
gui/wxpython/gui_core/widgets.py

@@ -14,6 +14,10 @@ Classes:
  - widgets::CoordinatesValidator
  - widgets::IntegerValidator
  - widgets::FloatValidator
+ - widgets::MapValidator
+ - widgets::NTCValidator
+ - widgets::SimpleValidator
+ - widgets::GenericValidator
  - widgets::GListCtrl
  - widgets::SearchModuleWidget
  - widgets::ManageSettingsWidget
@@ -56,6 +60,8 @@ try:
 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
@@ -716,7 +722,22 @@ class GenericValidator(wx.PyValidator):
         """
         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.
 

+ 2 - 8
gui/wxpython/lmgr/layertree.py

@@ -45,7 +45,7 @@ from vdigit.main          import haveVDigit
 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 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
         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 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
                               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()