ソースを参照

wxGUI/startup: file to separate GUI-dependent utils (now only db/loc/mapset setting)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73153 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 年 前
コミット
bdbba2ae71
3 ファイル変更32 行追加13 行削除
  1. 3 12
      gui/wxpython/gis_set.py
  2. 24 0
      gui/wxpython/startup/guiutils.py
  3. 5 1
      gui/wxpython/startup/utils.py

+ 3 - 12
gui/wxpython/gis_set.py

@@ -39,6 +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 location_wizard.dialogs import RegionDef
 from gui_core.dialogs import TextEntryDialog
 from gui_core.widgets import GenericValidator, StaticWrapText
@@ -877,12 +878,7 @@ class GRASSStartup(wx.Frame):
             for line in ret.splitlines():
                 self.listOfMapsetsSelectable += line.split(' ')
         else:
-            RunCommand("g.gisenv",
-                       set="GISDBASE=%s" % self.gisdbase)
-            RunCommand("g.gisenv",
-                       set="LOCATION_NAME=%s" % locationName)
-            RunCommand("g.gisenv",
-                       set="MAPSET=PERMANENT")
+            self.SetLocation(self.gisdbase, locationName, "PERMANENT")
             # first run only
             self.listOfMapsetsSelectable = copy.copy(self.listOfMapsets)
 
@@ -1110,12 +1106,7 @@ class GRASSStartup(wx.Frame):
         self.ExitSuccessfully()
 
     def SetLocation(self, dbase, location, mapset):
-        RunCommand("g.gisenv",
-                   set="GISDBASE=%s" % dbase)
-        RunCommand("g.gisenv",
-                   set="LOCATION_NAME=%s" % location)
-        RunCommand("g.gisenv",
-                   set="MAPSET=%s" % mapset)
+        SetSessionMapset(dbase, location, mapset)
 
     def _getDefaultMapsetName(self):
         """Returns default name for mapset."""

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

@@ -0,0 +1,24 @@
+"""
+@package startup.guiutils
+
+@brief General GUI-dependent utilities for GUI startup of GRASS GIS
+
+(C) 2018 by Vaclav Petras the GRASS Development Team
+
+This program is free software under the GNU General Public License
+(>=v2). Read the file COPYING that comes with GRASS for details.
+
+@author Vaclav Petras <wenzeslaus gmail com>
+
+This is for code which depend on something from GUI (wx or wxGUI). 
+"""
+
+
+from core.gcmd import RunCommand
+
+
+def SetSessionMapset(database, location, mapset):
+    """Sets database, location and mapset for the current session"""
+    RunCommand("g.gisenv", set="GISDBASE=%s" % database)
+    RunCommand("g.gisenv", set="LOCATION_NAME=%s" % location)
+    RunCommand("g.gisenv", set="MAPSET=%s" % mapset)

+ 5 - 1
gui/wxpython/startup/utils.py

@@ -1,7 +1,7 @@
 """
 @package startup.utils
 
-@brief General utilities for GUI startup of GRASS GIS
+@brief General GUI-independent utilities for GUI startup of GRASS GIS
 
 (C) 2017-2018 by Vaclav Petras the GRASS Development Team
 
@@ -9,6 +9,10 @@ This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 
 @author Vaclav Petras <wenzeslaus gmail com>
+
+This file should not use (import) anything from GUI code (wx or wxGUI).
+This can potentially be part of the Python library (i.e. it needs to
+solve the errors etc. in a general manner).
 """