Browse Source

wxGUI: After creating new location, switch to PERMANENT and display infobar for first-time user (#1183)

After creating a new Location from Data tab, GUI switches to its PERMANENT mapset.

If the previous location was the demolocation (i.e., it was the active location when user created the new location), an info bar appears offering to import data using Import vector data or Import raster data buttons. This is assumed to be a second info bar which appears to the user navigating through the GUI from the the demolocation (world location).

This follows 37b39db0b967f513b8f636f1efb134655fe1aa19 (#1078).

The demolocation detection is based on the location name.

A signal is used in order to trigger the info bar for any location creation done in the Data tab (button, first-time user intro info bar, context menu).
Linda Kladivova 4 years ago
parent
commit
790d70fee4

+ 19 - 0
gui/wxpython/datacatalog/catalog.py

@@ -57,6 +57,8 @@ class DataCatalog(wx.Panel):
         # infobar manager for data catalog
         # infobar manager for data catalog
         self.infoManager = DataCatalogInfoManager(infobar=self.infoBar,
         self.infoManager = DataCatalogInfoManager(infobar=self.infoBar,
                                                   giface=self.giface)
                                                   giface=self.giface)
+        self.tree.showImportDataInfo.connect(self.showImportDataInfo)
+
         # some layout
         # some layout
         self._layout()
         self._layout()
 
 
@@ -80,6 +82,9 @@ class DataCatalog(wx.Panel):
     def showDataStructureInfo(self):
     def showDataStructureInfo(self):
         self.infoManager.ShowDataStructureInfo(self.OnCreateLocation)
         self.infoManager.ShowDataStructureInfo(self.OnCreateLocation)
 
 
+    def showImportDataInfo(self):
+        self.infoManager.ShowImportDataInfo(self.OnImportOgrLayers, self.OnImportGdalLayers)
+
     def LoadItems(self):
     def LoadItems(self):
         self.tree.ReloadTreeItems()
         self.tree.ReloadTreeItems()
 
 
@@ -105,6 +110,20 @@ class DataCatalog(wx.Panel):
         db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
         db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
         self.tree.CreateMapset(db_node, loc_node)
         self.tree.CreateMapset(db_node, loc_node)
 
 
+    def OnImportOgrLayers(self, event, cmd=None):
+        """Convert multiple OGR layers to GRASS vector map layers"""
+        from modules.import_export import OgrImportDialog
+        dlg = OgrImportDialog(parent=self, giface=self.giface)
+        dlg.CentreOnScreen()
+        dlg.Show()
+
+    def OnImportGdalLayers(self, event, cmd=None):
+        """Convert multiple GDAL layers to GRASS raster map layers"""
+        from modules.import_export import GdalImportDialog
+        dlg = GdalImportDialog(parent=self, giface=self.giface)
+        dlg.CentreOnScreen()
+        dlg.Show()
+
     def OnCreateLocation(self, event):
     def OnCreateLocation(self, event):
         """Create new location"""
         """Create new location"""
         db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()
         db_node, loc_node, mapset_node = self.tree.GetCurrentDbLocationMapsetNode()

+ 14 - 0
gui/wxpython/datacatalog/infomanager.py

@@ -43,5 +43,19 @@ class DataCatalogInfoManager:
         ).format(loc=gisenv()['LOCATION_NAME'])
         ).format(loc=gisenv()['LOCATION_NAME'])
         self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
         self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
 
 
+    def ShowImportDataInfo(self, OnImportOgrLayersHandler, OnImportGdalLayersHandler):
+        """Show info about the data import focused on the first-time user"""
+        buttons = [("Import vector data", OnImportOgrLayersHandler),
+                   ("Import raster data", OnImportGdalLayersHandler)]
+        message = _(
+            "You have successfully created a new Location {loc}. "
+            "Currently you are in its PERMANENT Mapset which is used for "
+            "storing your base maps to make them readily available in other "
+            "Mapsets. You can create new Mapsets for different tasks by right "
+            "clicking on the Location name.\n\n"
+            "To import data, go to the File menu or use the buttons below."
+        ).format(loc=gisenv()['LOCATION_NAME'])
+        self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
+
     def _onLearnMore(self, event):
     def _onLearnMore(self, event):
         self._giface.Help(entry="grass_database")
         self._giface.Help(entry="grass_database")

+ 25 - 9
gui/wxpython/datacatalog/tree.py

@@ -74,7 +74,8 @@ import grass.script as gscript
 from grass.script import gisenv
 from grass.script import gisenv
 from grass.grassdb.data import map_exists
 from grass.grassdb.data import map_exists
 from grass.grassdb.checks import (get_mapset_owner, is_mapset_locked,
 from grass.grassdb.checks import (get_mapset_owner, is_mapset_locked,
-                                  is_different_mapset_owner)
+                                  is_different_mapset_owner,
+                                  is_current_mapset_in_demolocation)
 from grass.exceptions import CalledModuleError
 from grass.exceptions import CalledModuleError
 
 
 
 
@@ -328,6 +329,7 @@ class DataCatalogTree(TreeView):
         self._restricted = True
         self._restricted = True
 
 
         self.showNotification = Signal('Tree.showNotification')
         self.showNotification = Signal('Tree.showNotification')
+        self.showImportDataInfo = Signal('Tree.showImportDataInfo')
         self.parent = parent
         self.parent = parent
         self.contextMenu.connect(self.OnRightClick)
         self.contextMenu.connect(self.OnRightClick)
         self.itemActivated.connect(self.OnDoubleClick)
         self.itemActivated.connect(self.OnDoubleClick)
@@ -984,7 +986,9 @@ class DataCatalogTree(TreeView):
 
 
     def CreateLocation(self, grassdb_node):
     def CreateLocation(self, grassdb_node):
         """
         """
-        Creates new location interactively and adds it to the tree.
+        Creates new location interactively and adds it to the tree and switch
+        to its new PERMANENT mapset.
+        If a user was in Demolocation, it shows data import infobar.
         """
         """
         grassdatabase, location, mapset = (
         grassdatabase, location, mapset = (
             create_location_interactively(self, grassdb_node.data['name'])
             create_location_interactively(self, grassdb_node.data['name'])
@@ -995,6 +999,13 @@ class DataCatalogTree(TreeView):
                                              element='location',
                                              element='location',
                                              action='new')
                                              action='new')
 
 
+            # show data import infobar for first-time user with proper layout
+            if is_current_mapset_in_demolocation():
+                self.showImportDataInfo.emit()
+
+            # switch to PERMANENT mapset in newly created location
+            self.SwitchMapset(grassdatabase, location, mapset)
+
     def OnCreateLocation(self, event):
     def OnCreateLocation(self, event):
         """Create new location"""
         """Create new location"""
         self.CreateLocation(self.selected_grassdb[0])
         self.CreateLocation(self.selected_grassdb[0])
@@ -1525,14 +1536,12 @@ class DataCatalogTree(TreeView):
                 event.Veto()
                 event.Veto()
                 return
                 return
 
 
-    def OnSwitchMapset(self, event):
-        """Switch to location and mapset"""
-        genv = gisenv()
-        grassdb = self.selected_grassdb[0].data['name']
-        location = self.selected_location[0].data['name']
-        mapset = self.selected_mapset[0].data['name']
-
+    def SwitchMapset(self, grassdb, location, mapset):
+        """
+        Switch to location and mapset interactively.
+        """
         if can_switch_mapset_interactive(self, grassdb, location, mapset):
         if can_switch_mapset_interactive(self, grassdb, location, mapset):
+            genv = gisenv()
             # Switch to mapset in the same location
             # Switch to mapset in the same location
             if (grassdb == genv['GISDBASE'] and location == genv['LOCATION_NAME']):
             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)
@@ -1543,6 +1552,13 @@ class DataCatalogTree(TreeView):
             else:
             else:
                 switch_mapset_interactively(self, self._giface, grassdb, location, mapset)
                 switch_mapset_interactively(self, self._giface, grassdb, location, mapset)
 
 
+    def OnSwitchMapset(self, event):
+        """Switch to location and mapset"""
+        grassdb = self.selected_grassdb[0].data['name']
+        location = self.selected_location[0].data['name']
+        mapset = self.selected_mapset[0].data['name']
+        self.SwitchMapset(grassdb, location, mapset)
+
     def _updateAfterGrassdbChanged(self, action, element, grassdb, location, mapset=None,
     def _updateAfterGrassdbChanged(self, action, element, grassdb, location, mapset=None,
                                    map=None, newname=None):
                                    map=None, newname=None):
         """Update tree after grassdata changed"""
         """Update tree after grassdata changed"""