Browse Source

wxGUI/startup: new mapset dialog as a separate class and reuse create mapset method

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73154 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 năm trước cách đây
mục cha
commit
3bc6888076
2 tập tin đã thay đổi với 39 bổ sung24 xóa
  1. 7 24
      gui/wxpython/gis_set.py
  2. 32 0
      gui/wxpython/startup/guiutils.py

+ 7 - 24
gui/wxpython/gis_set.py

@@ -39,7 +39,7 @@ from core.gcmd import GMessage, GError, DecodeString, RunCommand
 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 @@ class GRASSStartup(wx.Frame):
                 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 @@ class GRASSStartup(wx.Frame):
 
     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)

+ 32 - 0
gui/wxpython/startup/guiutils.py

@@ -14,7 +14,13 @@ This is for code which depend on something from GUI (wx or wxGUI).
 """
 
 
+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 @@ def SetSessionMapset(database, location, mapset):
     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)