[GRASS-SVN] r70450 - in grass/trunk/gui/wxpython: lmgr mapdisp

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 28 20:47:03 PST 2017


Author: wenzeslaus
Date: 2017-01-28 20:47:03 -0800 (Sat, 28 Jan 2017)
New Revision: 70450

Modified:
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
Log:
wxGUI: lazy imports for lmgr and  mapdisp

Avoids potential startup failures when dependencies are not met.
Insignificantly or potentially improves startup time.

Also removes unused imports (e.g. pylint -E --enable=unused-import).

Imports from core, gui_core etc. not reviewed (needs to be imported anyway).


Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2017-01-29 02:57:21 UTC (rev 70449)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2017-01-29 04:47:03 UTC (rev 70450)
@@ -50,23 +50,14 @@
 from lmgr.layertree import LayerTree, LMIcons
 from lmgr.menudata import LayerManagerMenuData, LayerManagerModuleTree
 from gui_core.widgets import GNotebook, FormNotebook
-from modules.mcalc_builder import MapCalcFrame
-from dbmgr.manager import AttributeManager
 from core.workspace import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
 from core.gconsole import GConsole, EVT_IGNORED_CMD_RUN
 from core.giface import Notification
-from gui_core.goutput import GConsoleWindow, GC_SEARCH, GC_PROMPT
-from modules.import_export import GdalOutputDialog, DxfImportDialog, GdalImportDialog, OgrImportDialog
+from gui_core.goutput import GConsoleWindow, GC_PROMPT
 from gui_core.dialogs import LocationDialog, MapsetDialog, CreateNewVector, GroupDialog, MapLayersDialog, QuitDialog
-from modules.colorrules import RasterColorTable, VectorColorTable
 from gui_core.menu import SearchModuleWindow
 from gui_core.menu import Menu as GMenu
-from gmodeler.model import Model
-from gmodeler.frame import ModelFrame
-from psmap.frame import PsMapFrame
 from core.debug import Debug
-from gui_core.ghelp import AboutWindow
-from modules.extensions import InstallExtensionWindow, ManageExtensionWindow
 from lmgr.toolbars import LMWorkspaceToolbar, LMDataToolbar, LMToolsToolbar
 from lmgr.toolbars import LMMiscToolbar, LMVectorToolbar, LMNvizToolbar
 from lmgr.pyshell import PyShellWindow
@@ -74,11 +65,6 @@
 from datacatalog.catalog import DataCatalog
 from gui_core.forms import GUI
 from gui_core.wrap import Menu
-from gcp.manager import GCPWizard
-from nviz.main import haveNviz
-from nviz.preferences import NvizPreferencesDialog
-from mapswipe.frame import SwipeMapFrame
-from rlisetup.frame import RLiSetupFrame
 
 
 class GMFrame(wx.Frame):
@@ -418,6 +404,7 @@
                           first time
         """
         Debug.msg(5, "GMFrame.AddNvizTools()")
+        from nviz.main import haveNviz
         if not haveNviz:
             return
 
@@ -534,27 +521,28 @@
         self._setCopyingOfSelectedText()
 
     def OnGCPManager(self, event=None, cmd=None):
-        """Launch georectifier module. See OnIClass documentation.
-        """
+        """Launch georectifier module. See OnIClass documentation"""
+        from gcp.manager import GCPWizard
         GCPWizard(self, self._giface)
 
     def OnGModeler(self, event=None, cmd=None):
-        """Launch Graphical Modeler. See OnIClass documentation."""
+        """Launch Graphical Modeler. See OnIClass documentation"""
+        from gmodeler.frame import ModelFrame
         win = ModelFrame(parent=self, giface=self._giface)
         win.CentreOnScreen()
-
         win.Show()
 
     def OnPsMap(self, event=None, cmd=None):
-        """Launch Cartographic Composer. See OnIClass documentation.
-        """
+        """Launch Cartographic Composer. See OnIClass documentation"""
+        from psmap.frame import PsMapFrame
         win = PsMapFrame(parent=self)
         win.CentreOnScreen()
-
         win.Show()
 
     def OnMapSwipe(self, event=None, cmd=None):
-        """Launch Map Swipe. See OnIClass documentation."""
+        """Launch Map Swipe. See OnIClass documentation"""
+        from mapswipe.frame import SwipeMapFrame
+
         win = SwipeMapFrame(parent=self, giface=self._giface)
 
         rasters = []
@@ -578,10 +566,10 @@
         win.Show()
 
     def OnRLiSetup(self, event=None, cmd=None):
-        """Launch r.li Setup. See OnIClass documentation."""
+        """Launch r.li setup. See OnIClass documentation"""
+        from rlisetup.frame import RLiSetupFrame
         win = RLiSetupFrame(parent=self)
         win.CentreOnScreen()
-
         win.Show()
 
     def OnDone(self, event):
@@ -604,13 +592,13 @@
             dlg.Destroy()
             return
 
+        from gmodeler.model import Model
         self.model = Model()
         self.model.LoadModel(filename)
         self.model.Run(
             log=self.GetLogWindow(),
             onDone=self.OnDone,
             parent=self)
-
         dlg.Destroy()
 
     def OnMapsets(self, event):
@@ -1259,6 +1247,7 @@
 
     def OnAboutGRASS(self, event):
         """Display 'About GRASS' dialog"""
+        from gui_core.ghelp import AboutWindow
         win = AboutWindow(self)
         win.CentreOnScreen()
         win.Show(True)
@@ -1714,15 +1703,15 @@
         dlg.Destroy()
 
     def OnRasterRules(self, event):
-        """Launches dialog for raster color rules
-        """
+        """Launches dialog for raster color rules"""
+        from modules.colorrules import RasterColorTable
         ctable = RasterColorTable(self, layerTree=self.GetLayerTree())
         ctable.Show()
         ctable.CentreOnScreen()
 
     def OnVectorRules(self, event):
-        """Launches dialog for vector color rules
-        """
+        """Launches dialog for vector color rules"""
+        from modules.colorrules import VectorColorTable
         ctable = VectorColorTable(self, layerTree=self.GetLayerTree(),
                                   attributeType='color')
         ctable.Show()
@@ -1737,13 +1726,15 @@
 
     def OnInstallExtension(self, event):
         """Install extension from GRASS Addons SVN repository"""
+        from modules.extensions import InstallExtensionWindow
         win = InstallExtensionWindow(
             self, giface=self._giface, size=(650, 550))
         win.CentreOnScreen()
         win.Show()
 
     def OnManageExtension(self, event):
-        """Uninstall extension"""
+        """Manage or uninstall extensions"""
+        from modules.extensions import ManageExtensionWindow
         win = ManageExtensionWindow(self, size=(650, 300))
         win.CentreOnScreen()
         win.Show()
@@ -1768,10 +1759,10 @@
     def OnNvizPreferences(self, event):
         """Show nviz preferences"""
         if not self.dialogs['nvizPreferences']:
+            from nviz.preferences import NvizPreferencesDialog
             dlg = NvizPreferencesDialog(parent=self, giface=self._giface)
             self.dialogs['nvizPreferences'] = dlg
             self.dialogs['nvizPreferences'].CenterOnScreen()
-
         self.dialogs['nvizPreferences'].Show()
 
     def OnHelp(self, event):
@@ -1865,12 +1856,12 @@
     def OnMapCalculator(self, event, cmd=''):
         """Init map calculator for interactive creation of mapcalc statements
         """
+        from modules.mcalc_builder import MapCalcFrame
         if event:
             try:
                 cmd = self.GetMenuCmd(event)
             except KeyError:
                 cmd = ['r.mapcalc']
-
         win = MapCalcFrame(parent=self,
                            giface=self._giface,
                            cmd=cmd[0])
@@ -1891,6 +1882,7 @@
 
     def OnVectorOutputFormat(self, event):
         """Set vector output format handler"""
+        from modules.import_export import GdalOutputDialog
         dlg = GdalOutputDialog(parent=self, ogr=True)
         dlg.CentreOnScreen()
         dlg.Show()
@@ -1905,30 +1897,35 @@
 
     def OnImportDxfFile(self, event, cmd=None):
         """Convert multiple DXF layers to GRASS vector map layers"""
+        from modules.import_export import DxfImportDialog
         dlg = DxfImportDialog(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 OnLinkGdalLayers(self, event, cmd=None):
         """Link multiple GDAL layers to GRASS raster map layers"""
+        from modules.import_export import GdalImportDialog
         dlg = GdalImportDialog(parent=self, giface=self._giface, link=True)
         dlg.CentreOnScreen()
         dlg.Show()
 
     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 OnLinkOgrLayers(self, event, cmd=None):
         """Links multiple OGR layers to GRASS vector map layers"""
+        from modules.import_export import OgrImportDialog
         dlg = OgrImportDialog(parent=self, giface=self._giface, link=True)
         dlg.CentreOnScreen()
         dlg.Show()
@@ -1984,14 +1981,13 @@
         if not dcmd:
             return
 
+        from dbmgr.manager import AttributeManager
         dbmanager = AttributeManager(parent=self, id=wx.ID_ANY,
                                      size=wx.Size(500, 300),
                                      item=layer, log=self._gconsole,
                                      selection=selection)
-
         # register ATM dialog
         self.dialogs['atm'].append(dbmanager)
-
         # show ATM window
         dbmanager.Show()
 

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2017-01-29 02:57:21 UTC (rev 70449)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2017-01-29 04:47:03 UTC (rev 70450)
@@ -30,11 +30,9 @@
 import wx
 import wx.aui
 
-from core.render import Map
 from mapdisp.toolbars import MapToolbar, NvizIcons
 from mapdisp.gprint import PrintOptions
 from core.gcmd import GError, GMessage, RunCommand
-from dbmgr.dialogs import DisplayAttributesDialog
 from core.utils import ListOfCatsToRange, GetLayerNameFromCmd, _
 from gui_core.dialogs import GetImageHandlers, ImageSizeDialog
 from core.debug import Debug
@@ -45,16 +43,11 @@
 from mapwin.buffered import BufferedMapWindow
 from mapwin.decorations import LegendController, BarscaleController, \
     ArrowController, DtextController, LegendVectController
-from modules.histogram import HistogramFrame
-from wxplot.histogram import HistogramPlotFrame
-from wxplot.profile import ProfileFrame
-from wxplot.scatter import ScatterFrame
 from mapwin.analysis import ProfileController, MeasureDistanceController, \
     MeasureAreaController
 from gui_core.forms import GUI
 from core.giface import Notification
 from gui_core.vselect import VectorSelectBase, VectorSelectHighlighter
-
 from mapdisp import statusbar as sb
 
 import grass.script as grass
@@ -1138,6 +1131,8 @@
 
     def Profile(self, rasters=None):
         """Launch profile tool"""
+        from wxplot.profile import ProfileFrame
+
         self.profileController = ProfileController(
             self._giface, mapWindow=self.GetMapWindow())
         win = ProfileFrame(parent=self, rasterList=rasters,
@@ -1157,6 +1152,7 @@
             if layer.maplayer.GetType() == 'raster':
                 raster.append(layer.maplayer.GetName())
 
+        from wxplot.histogram import HistogramPlotFrame
         win = HistogramPlotFrame(parent=self, rasterList=raster)
         win.CentreOnParent()
         win.Show()
@@ -1170,6 +1166,7 @@
             if layer.maplayer.GetType() == 'raster':
                 raster.append(layer.maplayer.GetName())
 
+        from wxplot.scatter import ScatterFrame
         win = ScatterFrame(parent=self, rasterList=raster)
 
         win.CentreOnParent()
@@ -1181,6 +1178,7 @@
     def OnHistogram(self, event):
         """Init histogram display canvas and tools
         """
+        from modules.histogram import HistogramFrame
         win = HistogramFrame(self, giface=self._giface)
 
         win.CentreOnParent()



More information about the grass-commit mailing list