Browse Source

wxGUI: Show the world map in demolocation immediately after startup (#1070)

* Shows world countries map which is in the demolocation when in demolocation.
* Needs at least CallAfter to report errors correctly if needed.
* However, CallLater 1000 is needed for proper alignment of the map in the window
  (and with the red computational region extent).
* Tests if vector map exists.

Possible future improvements: Different colors than defaults. OnIdle instead of CallLater.

Co-authored-by: Vaclav Petras <wenzeslaus@gmail.com>
Linda Kladivova 4 years ago
parent
commit
22cdf1f8ac
2 changed files with 32 additions and 0 deletions
  1. 28 0
      gui/wxpython/lmgr/frame.py
  2. 4 0
      lib/python/grassdb/checks.py

+ 28 - 0
gui/wxpython/lmgr/frame.py

@@ -69,6 +69,7 @@ from lmgr.giface import LayerManagerGrassInterface
 from datacatalog.catalog import DataCatalog
 from datacatalog.catalog import DataCatalog
 from gui_core.forms import GUI
 from gui_core.forms import GUI
 from gui_core.wrap import Menu, TextEntryDialog
 from gui_core.wrap import Menu, TextEntryDialog
+from grass.grassdb.checks import is_current_mapset_in_demolocation
 from startup.guiutils import (
 from startup.guiutils import (
     switch_mapset_interactively,
     switch_mapset_interactively,
     create_mapset_interactively,
     create_mapset_interactively,
@@ -260,6 +261,8 @@ class GMFrame(wx.Frame):
             self.GetMapDisplay().Raise()
             self.GetMapDisplay().Raise()
         wx.CallAfter(self.Raise)
         wx.CallAfter(self.Raise)
 
 
+        self._show_demo_map()
+
     def _setTitle(self):
     def _setTitle(self):
         """Set frame title"""
         """Set frame title"""
         if self.workspaceFile:
         if self.workspaceFile:
@@ -413,6 +416,31 @@ class GMFrame(wx.Frame):
         wx.CallAfter(self.datacatalog.LoadItems)
         wx.CallAfter(self.datacatalog.LoadItems)
         return self.notebook
         return self.notebook
 
 
+    def _show_demo_map(self):
+        """If in demolocation, add demo map to map display
+
+        This provides content for first-time user experience.
+        """
+        def show_demo():
+            layer_name = "country_boundaries@PERMANENT"
+            exists = grass.find_file(name=layer_name, element="vector")["name"]
+            if not exists:
+                # Do not fail nor report errors to the first-time user when not found.
+                Debug.msg(
+                    5,
+                    "GMFrame._show_demo_map(): {} does not exist".format(layer_name)
+                )
+                return
+            self.GetLayerTree().AddLayer(
+                ltype="vector",
+                lname=layer_name,
+                lchecked=True,
+                lcmd=["d.vect", "map={}".format(layer_name)],
+            )
+        if is_current_mapset_in_demolocation():
+            # Show only after everything is initialized for proper map alignment.
+            wx.CallLater(1000, show_demo)
+
     def AddNvizTools(self, firstTime):
     def AddNvizTools(self, firstTime):
         """Add nviz notebook page
         """Add nviz notebook page
 
 

+ 4 - 0
lib/python/grassdb/checks.py

@@ -114,6 +114,10 @@ def get_mapset_owner(mapset_path):
         return None
         return None
 
 
 
 
+def is_current_mapset_in_demolocation():
+    return gisenv()['LOCATION_NAME'] == "world_latlong_wgs84"
+
+
 def is_mapset_locked(mapset_path):
 def is_mapset_locked(mapset_path):
     """Check if the mapset is locked"""
     """Check if the mapset is locked"""
     lock_name = ".gislock"
     lock_name = ".gislock"