[GRASS-SVN] r73230 - grass/trunk/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 2 19:31:55 PDT 2018


Author: wenzeslaus
Date: 2018-09-02 19:31:55 -0700 (Sun, 02 Sep 2018)
New Revision: 73230

Modified:
   grass/trunk/gui/wxpython/gui_core/gselect.py
Log:
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).


Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2018-09-03 02:04:19 UTC (rev 73229)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2018-09-03 02:31:55 UTC (rev 73230)
@@ -67,12 +67,6 @@
 import grass.script as grass
 from grass.script import task as gtask
 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
 
@@ -516,7 +510,7 @@
                 renamed_elements.append(elementdict[elem])
 
         if element in ('stds', 'strds', 'str3ds', 'stvds'):
-            if self.tgis_error is False:
+            if not self.tgis_error:
                 import grass.temporal as tgis
                 filesdict = tgis.tlist_grouped(
                     elementdict[element], element == 'stds')
@@ -763,11 +757,19 @@
             if self.type in ('stds', 'strds', 'str3ds', 'stvds'):
                 # Initiate the temporal framework. Catch database error
                 # and set the error flag for the stds listing.
-                import grass.temporal as tgis
                 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
         if 'mapsets' in kargs:
             self.mapsets = kargs['mapsets']



More information about the grass-commit mailing list