[GRASS-SVN] r73154 - in grass/trunk/gui/wxpython: . startup

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 23 20:45:40 PDT 2018


Author: wenzeslaus
Date: 2018-08-23 20:45:40 -0700 (Thu, 23 Aug 2018)
New Revision: 73154

Modified:
   grass/trunk/gui/wxpython/gis_set.py
   grass/trunk/gui/wxpython/startup/guiutils.py
Log:
wxGUI/startup: new mapset dialog as a separate class and reuse create mapset method

Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py	2018-08-24 03:05:13 UTC (rev 73153)
+++ grass/trunk/gui/wxpython/gis_set.py	2018-08-24 03:45:40 UTC (rev 73154)
@@ -39,7 +39,7 @@
 from core.utils import GetListOfLocations, GetListOfMapsets
 from startup.utils import (
     get_lockfile_if_present, get_possible_database_path)
-from startup.guiutils import SetSessionMapset
+from startup.guiutils import SetSessionMapset, NewMapsetDialog
 from location_wizard.dialogs import RegionDef
 from gui_core.dialogs import TextEntryDialog
 from gui_core.widgets import GenericValidator, StaticWrapText
@@ -597,22 +597,7 @@
                 defineRegion.Destroy()
 
             if gWizard.user_mapset:
-                dlg = TextEntryDialog(
-                    parent=self,
-                    message=_("New mapset:"),
-                    caption=_("Create new mapset"),
-                    defaultValue=self._getDefaultMapsetName(),
-                    validator=GenericValidator(
-                        grass.legal_name,
-                        self._nameValidationFailed
-                    ),
-                    style=wx.OK | wx.CANCEL | wx.HELP
-                )
-                help = dlg.FindWindowById(wx.ID_HELP)
-                help.Bind(wx.EVT_BUTTON, self.OnHelp)
-                if dlg.ShowModal() == wx.ID_OK:
-                    mapsetName = dlg.GetValue()
-                    self.CreateNewMapset(mapsetName)
+                self.OnCreateMapset(event)
 
     def ImportFile(self, filePath):
         """Tries to import file as vector or raster.
@@ -991,14 +976,12 @@
 
     def OnCreateMapset(self, event):
         """Create new mapset"""
-        dlg = TextEntryDialog(
+        dlg = NewMapsetDialog(
             parent=self,
-            message=_('Enter name for new mapset:'),
-            caption=_('Create new mapset'),
-            defaultValue=self._getDefaultMapsetName(),
-            validator=GenericValidator(
-                grass.legal_name,
-                self._nameValidationFailed))
+            default=self._getDefaultMapsetName(),
+            validation_failed_handler=self._nameValidationFailed,
+            help_hanlder=self.OnHelp,
+        )
         if dlg.ShowModal() == wx.ID_OK:
             mapset = dlg.GetValue()
             return self.CreateNewMapset(mapset=mapset)

Modified: grass/trunk/gui/wxpython/startup/guiutils.py
===================================================================
--- grass/trunk/gui/wxpython/startup/guiutils.py	2018-08-24 03:05:13 UTC (rev 73153)
+++ grass/trunk/gui/wxpython/startup/guiutils.py	2018-08-24 03:45:40 UTC (rev 73154)
@@ -14,7 +14,13 @@
 """
 
 
+import wx
+
+import grass.script as gs
+
 from core.gcmd import RunCommand
+from gui_core.dialogs import TextEntryDialog
+from gui_core.widgets import GenericValidator
 
 
 def SetSessionMapset(database, location, mapset):
@@ -22,3 +28,29 @@
     RunCommand("g.gisenv", set="GISDBASE=%s" % database)
     RunCommand("g.gisenv", set="LOCATION_NAME=%s" % location)
     RunCommand("g.gisenv", set="MAPSET=%s" % mapset)
+
+
+
+class NewMapsetDialog(TextEntryDialog):
+    def __init__(self, parent=None, default=None,
+                 validation_failed_handler=None, help_hanlder=None):
+        if help_hanlder:
+            style = wx.OK | wx.CANCEL | wx.HELP
+        else:
+            style = wx.OK | wx.CANCEL
+        if validation_failed_handler:
+            validator=GenericValidator(
+                gs.legal_name, validation_failed_handler)
+        else:
+            validator = None
+        TextEntryDialog.__init__(
+            self, parent=parent,
+            message=_("Name for the new mapset:"),
+            caption=_("Create new mapset"),
+            defaultValue=default,
+            validator=validator,
+            style=style
+        )
+        if help_hanlder:
+            help_button = self.FindWindowById(wx.ID_HELP)
+            help_button.Bind(wx.EVT_BUTTON, help_hanlder)



More information about the grass-commit mailing list