Browse Source

wxGUI/gui_core: lazy import both of the pygrass (ctypes) dependent modules

If one can be lazy imported, the other can be too.
Avoids or postpones a fatal error at startup when uncaught exception happens.
Also translate the error message and avoid 'is False',
use not (style and readability).


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73230 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 years ago
parent
commit
ff36c41cbb
1 changed files with 13 additions and 11 deletions
  1. 13 11
      gui/wxpython/gui_core/gselect.py

+ 13 - 11
gui/wxpython/gui_core/gselect.py

@@ -67,12 +67,6 @@ import wx.lib.filebrowsebutton as filebrowse
 import grass.script as grass
 import grass.script as grass
 from grass.script import task as gtask
 from grass.script import task as gtask
 from grass.exceptions import CalledModuleError
 from grass.exceptions import CalledModuleError
-try:
-    from grass.pygrass import messages
-except ImportError as e:
-    print(_("Unable to import pyGRASS: %s\n"
-            "Some functionality will be not accessible") % e,
-          file=sys.stderr)
 
 
 from gui_core.widgets import ManageSettingsWidget, CoordinatesValidator
 from gui_core.widgets import ManageSettingsWidget, CoordinatesValidator
 
 
@@ -516,7 +510,7 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
                 renamed_elements.append(elementdict[elem])
                 renamed_elements.append(elementdict[elem])
 
 
         if element in ('stds', 'strds', 'str3ds', 'stvds'):
         if element in ('stds', 'strds', 'str3ds', 'stvds'):
-            if self.tgis_error is False:
+            if not self.tgis_error:
                 import grass.temporal as tgis
                 import grass.temporal as tgis
                 filesdict = tgis.tlist_grouped(
                 filesdict = tgis.tlist_grouped(
                     elementdict[element], element == 'stds')
                     elementdict[element], element == 'stds')
@@ -763,11 +757,19 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
             if self.type in ('stds', 'strds', 'str3ds', 'stvds'):
             if self.type in ('stds', 'strds', 'str3ds', 'stvds'):
                 # Initiate the temporal framework. Catch database error
                 # Initiate the temporal framework. Catch database error
                 # and set the error flag for the stds listing.
                 # and set the error flag for the stds listing.
-                import grass.temporal as tgis
                 try:
                 try:
-                    tgis.init(True)
-                except messages.FatalError as e:
-                    sys.stderr.write("Temporal GIS error:\n%s" % e)
+                    import grass.temporal as tgis
+                    from grass.pygrass import messages
+                    try:
+                        tgis.init(True)
+                    except messages.FatalError as e:
+                        sys.stderr.write(_("Temporal GIS error:\n%s") % e)
+                        self.tgis_error = True
+                except ImportError as e:
+                    # PyGRASS (ctypes) is the likely cause
+                    sys.stderr.write(_(
+                        "Unable to import pyGRASS: %s\n"
+                        "Some functionality will be not accessible") % e)
                     self.tgis_error = True
                     self.tgis_error = True
         if 'mapsets' in kargs:
         if 'mapsets' in kargs:
             self.mapsets = kargs['mapsets']
             self.mapsets = kargs['mapsets']