Browse Source

wxGUI: always switch when creating new location/mapset, show dialog upon switching only after creating new location/mapset (#1229)

Anna Petrasova 4 years ago
parent
commit
9768113262
3 changed files with 45 additions and 19 deletions
  1. 11 5
      gui/wxpython/datacatalog/tree.py
  2. 17 1
      gui/wxpython/lmgr/frame.py
  3. 17 13
      gui/wxpython/startup/guiutils.py

+ 11 - 5
gui/wxpython/datacatalog/tree.py

@@ -979,6 +979,8 @@ class DataCatalogTree(TreeView):
                                              mapset=mapset,
                                              element='mapset',
                                              action='new')
+            self.SwitchMapset(grassdb_node.data['name'], location_node.data['name'], mapset,
+                              show_confirmation=True)
 
     def OnCreateMapset(self, event):
         """Create new mapset"""
@@ -1004,7 +1006,8 @@ class DataCatalogTree(TreeView):
                 self.showImportDataInfo.emit()
 
             # switch to PERMANENT mapset in newly created location
-            self.SwitchMapset(grassdatabase, location, mapset)
+            self.SwitchMapset(grassdatabase, location, mapset,
+                              show_confirmation=True)
 
     def OnCreateLocation(self, event):
         """Create new location"""
@@ -1536,7 +1539,7 @@ class DataCatalogTree(TreeView):
                 event.Veto()
                 return
 
-    def SwitchMapset(self, grassdb, location, mapset):
+    def SwitchMapset(self, grassdb, location, mapset, show_confirmation=False):
         """
         Switch to location and mapset interactively.
         """
@@ -1544,13 +1547,16 @@ class DataCatalogTree(TreeView):
             genv = gisenv()
             # Switch to mapset in the same location
             if (grassdb == genv['GISDBASE'] and location == genv['LOCATION_NAME']):
-                switch_mapset_interactively(self, self._giface, None, None, mapset)
+                switch_mapset_interactively(self, self._giface, None, None, mapset,
+                                            show_confirmation)
             # Switch to mapset in the same grassdb
             elif grassdb == genv['GISDBASE']:
-                switch_mapset_interactively(self, self._giface, None, location, mapset)
+                switch_mapset_interactively(self, self._giface, None, location, mapset,
+                                            show_confirmation)
             # Switch to mapset in a different grassdb
             else:
-                switch_mapset_interactively(self, self._giface, grassdb, location, mapset)
+                switch_mapset_interactively(self, self._giface, grassdb, location, mapset,
+                                            show_confirmation)
 
     def OnSwitchMapset(self, event):
         """Switch to location and mapset"""

+ 17 - 1
gui/wxpython/lmgr/frame.py

@@ -517,10 +517,20 @@ class GMFrame(wx.Frame):
             create_location_interactively(self, gisenv['GISDBASE'])
         )
         if location:
-            self._giface.grassdbChanged.emit(grassdb=gisenv['GISDBASE'],
+            self._giface.grassdbChanged.emit(grassdb=grassdb,
                                              location=location,
                                              action='new',
                                              element='location')
+            if grassdb == gisenv['GISDBASE']:
+                switch_grassdb = None
+            else:
+                switch_grassdb = grassdb
+            if can_switch_mapset_interactive(self, grassdb, location, mapset):
+                switch_mapset_interactively(self, self._giface,
+                                            switch_grassdb,
+                                            location,
+                                            mapset,
+                                            show_confirmation=True)
 
     def OnSettingsChanged(self):
         """Here can be functions which have to be called
@@ -1081,6 +1091,12 @@ class GMFrame(wx.Frame):
                                              mapset=mapset,
                                              action='new',
                                              element='mapset')
+            if can_switch_mapset_interactive(self,
+                                             gisenv['GISDBASE'],
+                                             gisenv['LOCATION_NAME'],
+                                             mapset):
+                switch_mapset_interactively(self, self._giface, None, None,
+                                            mapset, show_confirmation=True)
 
     def OnChangeMapset(self, event):
         """Change current mapset"""

+ 17 - 13
gui/wxpython/startup/guiutils.py

@@ -704,19 +704,21 @@ def import_file(guiparent, filePath):
             parent=guiparent)
 
 
-def switch_mapset_interactively(guiparent, giface, dbase, location, mapset):
+def switch_mapset_interactively(guiparent, giface, dbase, location, mapset,
+                                show_confirmation=False):
     """Switch current mapset. Emits giface.currentMapsetChanged signal."""
     if dbase:
         if RunCommand('g.mapset', parent=guiparent,
                       location=location,
                       mapset=mapset,
                       dbase=dbase) == 0:
-            GMessage(parent=guiparent,
-                     message=_("Current GRASS database is <%(dbase)s>.\n"
-                               "Current location is <%(loc)s>.\n"
-                               "Current mapset is <%(mapset)s>."
-                               ) %
-                     {'dbase': dbase, 'loc': location, 'mapset': mapset})
+            if show_confirmation:
+                GMessage(parent=guiparent,
+                         message=_("Current GRASS database is <%(dbase)s>.\n"
+                                   "Current location is <%(loc)s>.\n"
+                                   "Current mapset is <%(mapset)s>."
+                                   ) %
+                        {'dbase': dbase, 'loc': location, 'mapset': mapset})
             giface.currentMapsetChanged.emit(dbase=dbase,
                                              location=location,
                                              mapset=mapset)
@@ -724,10 +726,11 @@ def switch_mapset_interactively(guiparent, giface, dbase, location, mapset):
         if RunCommand('g.mapset', parent=guiparent,
                       location=location,
                       mapset=mapset) == 0:
-            GMessage(parent=guiparent,
-                     message=_("Current location is <%(loc)s>.\n"
-                               "Current mapset is <%(mapset)s>.") %
-                     {'loc': location, 'mapset': mapset})
+            if show_confirmation:
+                GMessage(parent=guiparent,
+                         message=_("Current location is <%(loc)s>.\n"
+                                   "Current mapset is <%(mapset)s>.") %
+                        {'loc': location, 'mapset': mapset})
             giface.currentMapsetChanged.emit(dbase=None,
                                              location=location,
                                              mapset=mapset)
@@ -735,6 +738,7 @@ def switch_mapset_interactively(guiparent, giface, dbase, location, mapset):
         if RunCommand('g.mapset',
                       parent=guiparent,
                       mapset=mapset) == 0:
-            GMessage(parent=guiparent,
-                     message=_("Current mapset is <%s>.") % mapset)
+            if show_confirmation:
+                GMessage(parent=guiparent,
+                         message=_("Current mapset is <%s>.") % mapset)
             giface.currentMapsetChanged.emit(dbase=None, location=None, mapset=mapset)