[GRASS-SVN] r57431 - in grass/trunk/gui/wxpython: gui_core lmgr mapdisp modules nviz vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 7 14:08:10 PDT 2013


Author: wenzeslaus
Date: 2013-08-07 14:08:10 -0700 (Wed, 07 Aug 2013)
New Revision: 57431

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/modules/histogram.py
   grass/trunk/gui/wxpython/nviz/mapwindow.py
   grass/trunk/gui/wxpython/vdigit/preferences.py
   grass/trunk/gui/wxpython/vdigit/toolbars.py
Log:
wxGUI/mapdisp: avoiding usage of lmgr and related objects in mapdisplay (some still remains, some are in used classes; note that this is not an attempt to fix nviz start and end procedures)

Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -320,7 +320,7 @@
         return None
 
 def CreateNewVector(parent, cmd, title = _('Create new vector map'),
-                    exceptMap = None, log = None,
+                    exceptMap=None, giface=None,
                     disableAdd = False, disableTable = False):
     """!Create new vector map layer
     
@@ -443,8 +443,8 @@
     if '@' not in outmap:
         outmap += '@' + grass.gisenv()['MAPSET']
         
-    if log:
-        log.WriteLog(_("New vector map <%s> created") % outmap)
+    if giface:
+        giface.WriteLog(_("New vector map <%s> created") % outmap)
         
     return dlg
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -340,8 +340,11 @@
         
         return self.notebook
             
-    def AddNvizTools(self):
-        """!Add nviz notebook page"""
+    def AddNvizTools(self, firstTime):
+        """!Add nviz notebook page
+
+        @param firstTime if a mapdisplay is starting 3D mode for the first time
+        """
         Debug.msg(5, "GMFrame.AddNvizTools()")
         if not haveNviz:
             return
@@ -361,8 +364,12 @@
         idx = self.notebook.GetPageIndexByName('layers')
         self.notebook.InsertPage(indx = idx + 1, page = self.nviz, text = _("3D view"), name = 'nviz')
         self.notebook.SetSelectionByName('nviz')
-        
-        
+
+        # this is a bit strange here since a new window is created everytime
+        if not firstTime:
+            for page in ('view', 'light', 'fringe', 'constant', 'cplane', 'animation'):
+                self.nviz.UpdatePage(page)
+
     def RemoveNvizTools(self):
         """!Remove nviz notebook page"""
         # if more mapwindow3D were possible, check here if nb page should be removed
@@ -1465,7 +1472,7 @@
         """!Init histogram display canvas and tools
         """
         from modules.histogram import HistogramFrame
-        win = HistogramFrame(self)
+        win = HistogramFrame(self, giface=self._giface)
         
         win.CentreOnScreen()
         win.Show()
@@ -1632,7 +1639,17 @@
         cb_boxsizer.Fit(self.GetLayerTree())
         self.currentPage.Layout()
         self.GetLayerTree().Layout()
-        
+
+        mapdisplay = self.currentPage.maptree.mapdisplay
+        mapdisplay.Bind(wx.EVT_ACTIVATE,
+                        lambda event, page=self.currentPage:
+                        self._onMapDisplayFocus(page))
+        mapdisplay.starting3dMode.connect(
+            lambda firstTime, mapDisplayPage=self.currentPage:
+            self._onMapDisplayStarting3dMode(mapDisplayPage))
+        mapdisplay.starting3dMode.connect(self.AddNvizTools)
+        mapdisplay.ending3dMode.connect(self.RemoveNvizTools)
+
         # use default window layout
         if UserSettings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled'):
             dim = UserSettings.Get(group = 'general', key = 'defWindowPos', subkey = 'dim')
@@ -1648,7 +1665,26 @@
         self.displayIndex += 1
         
         return self.GetMapDisplay()
-    
+
+    def _onMapDisplayFocus(self, notebookLayerPage):
+        """Changes bookcontrol page to page associated with display."""
+        # moved from mapdisp/frame.py
+        # TODO: why it is called 3 times when getting focus?
+        # and one times when loosing focus?
+        pgnum = self.notebookLayers.GetPageIndex(notebookLayerPage)
+        if pgnum > -1:
+            self.notebookLayers.SetSelection(pgnum)
+            self.currentPage = self.notebookLayers.GetCurrentPage()
+
+    def _onMapDisplayStarting3dMode(self, mapDisplayPage):
+        """!Disables 3D mode for all map displays except for @p mapDisplay"""
+        # TODO: it should be disabled also for newly created map windows
+        # moreover mapdisp.Disable3dMode() does not work properly
+        for page in range(0, self.GetLayerNotebook().GetPageCount()):
+            mapdisp = self.GetLayerNotebook().GetPage(page).maptree.GetMapDisplay()
+            if self.GetLayerNotebook().GetPage(page) != mapDisplayPage:
+                mapdisp.Disable3dMode()
+
     def OnAddMaps(self, event = None):
         """!Add selected map layers into layer tree"""
         dialog = MapLayersDialog(parent = self, title = _("Add selected map layers into layer tree"))

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -63,7 +63,9 @@
 
 import grass.script as grass
 
+from grass.pydispatch.signal import Signal
 
+
 class MapFrame(SingleMapFrame):
     """!Main frame for map display window. Drawing takes place in
     child double buffered drawing window.
@@ -88,11 +90,26 @@
                               Map = Map, auimgr = auimgr, name = name, **kwargs)
         
         self._giface = giface
-        self._layerManager = lmgr   # Layer Manager object
-        self.tree       = tree      # Layer Manager layer tree object
-        self.page       = page      # Notebook page holding the layer tree
-        self.layerbook  = notebook  # Layer Manager layer tree notebook
+        # Layer Manager object
+        # need by GLWindow (a lot), VDigitWindow (a little bit)
+        self._layerManager = lmgr
+        # Layer Manager layer tree object
+        # used for VDigit toolbar and window and GLWindow
+        self.tree = tree
+        # Notebook page holding the layer tree
+        # used only in OnCloseWindow
+        self.page = page
+        # Layer Manager layer tree notebook
+        # used only in OnCloseWindow
+        self.layerbook = notebook
 
+        # Emitted when starting (switching to) 3D mode.
+        # Parameter firstTime specifies if 3D was already actived.
+        self.starting3dMode = Signal("MapFrame.starting3dMode")
+
+        # Emitted when ending (switching from) 3D mode.
+        self.ending3dMode = Signal("MapFrame.ending3dMode")
+
         # properties are shared in other objects, so defining here
         self.mapWindowProperties = MapWindowProperties()
         self.mapWindowProperties.setValuesFromUserSettings()
@@ -188,7 +205,6 @@
         #
         # Bind various events
         #
-        self.Bind(wx.EVT_ACTIVATE, self.OnFocus)
         self.Bind(wx.EVT_CLOSE,    self.OnCloseWindow)
         self.Bind(wx.EVT_SIZE,     self.OnSize)
         
@@ -237,12 +253,7 @@
             GError(_("Unable to start wxGUI vector digitizer.\n"
                      "Details: %s") % errorMsg, parent = self)
             return
-        
-        if self._layerManager:
-            log = self._layerManager.GetLogWindow()
-        else:
-            log = None
-        
+
         if not self.MapWindowVDigit:
             from vdigit.mapwindow import VDigitWindow
             self.MapWindowVDigit = VDigitWindow(parent=self, giface=self._giface,
@@ -271,8 +282,8 @@
             self._mgr.GetPane('3d').Hide()
         self._mgr.GetPane('vdigit').Show()
         self.toolbars['vdigit'] = VDigitToolbar(parent = self, MapWindow = self.MapWindow,
-                                                digitClass = VDigit, giface =  self._giface,
-                                                layerTree = self.tree, log = log)
+                                                digitClass=VDigit, giface=self._giface,
+                                                layerTree=self.tree)
         self.MapWindowVDigit.SetToolbar(self.toolbars['vdigit'])
         
         self._mgr.AddPane(self.toolbars['vdigit'],
@@ -302,13 +313,9 @@
                                "was not found or loaded properly.\n"
                                "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg))
             return
-        
-        # disable 3D mode for other displays
-        for page in range(0, self._layerManager.GetLayerNotebook().GetPageCount()):
-            mapdisp = self._layerManager.GetLayerNotebook().GetPage(page).maptree.GetMapDisplay()
-            if self._layerManager.GetLayerNotebook().GetPage(page) != self._layerManager.currentPage:
-                if '3D' in mapdisp.toolbars['map'].combo.GetString(1):
-                    mapdisp.toolbars['map'].combo.Delete(1)
+
+        # here was disabling 3D for other displays, now done on starting3dMode
+
         self.toolbars['map'].Enable2D(False)
         # add rotate tool to map toolbar
         self.toolbars['map'].InsertTool((('rotate', NvizIcons['rotate'],
@@ -332,12 +339,13 @@
             self.MapWindow3D = GLWindow(self, giface = self._giface, id = wx.ID_ANY, frame = self,
                                         Map = self.Map, tree = self.tree, lmgr = self._layerManager)
             self._setUpMapWindow(self.MapWindow3D)
+            self.MapWindow3D.mapQueried.connect(self.Query)
             self.MapWindow = self.MapWindow3D
             self.MapWindow.SetNamedCursor('default')
-            
-            # add Nviz notebookpage
-            self._layerManager.AddNvizTools()
-            
+
+            # here was AddNvizTools in lmgr
+            self.starting3dMode.emit(firstTime=True)
+
             # switch from MapWindow to MapWindowGL
             self._mgr.GetPane('2d').Hide()
             self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
@@ -358,13 +366,12 @@
             # switch from MapWindow to MapWindowGL
             self._mgr.GetPane('2d').Hide()
             self._mgr.GetPane('3d').Show()
-            
-            # add Nviz notebookpage
-            self._layerManager.AddNvizTools()
+
+            # here was AddNvizTools in lmgr and updating of pages
+            self.starting3dMode.emit(firstTime=False)
+
             self.MapWindow3D.ResetViewHistory()
-            for page in ('view', 'light', 'fringe', 'constant', 'cplane', 'animation'):
-                self._layerManager.nviz.UpdatePage(page)
-                
+
         self._giface.updateMap.disconnect(self.MapWindow2D.UpdateMap)
         self._giface.updateMap.connect(self.MapWindow3D.UpdateMap)
         self.MapWindow3D.overlays = self.MapWindow2D.overlays
@@ -375,7 +382,13 @@
         
         self.SetStatusText("", 0)
         self._mgr.Update()
-    
+
+    def Disable3dMode(self):
+        """Disables 3D mode (NVIZ) in user interface."""
+        # TODO: this is broken since item is removed but switch is drived by index
+        if '3D' in self.toolbars['map'].combo.GetString(1):
+            self.toolbars['map'].combo.Delete(1)
+
     def RemoveNviz(self):
         """!Restore 2D view"""
         try:
@@ -398,13 +411,14 @@
         self._mgr.GetPane('3d').Hide()
 
         self.MapWindow = self.MapWindow2D
-        # remove nviz notebook page
-        self._layerManager.RemoveNvizTools()
+        # here was RemoveNvizTools form lmgr
+        self.ending3dMode.emit()
         try:
             self.MapWindow2D.overlays = self.MapWindow3D.overlays
             self.MapWindow2D.textdict = self.MapWindow3D.textdict
         except AttributeError:
             pass
+        # TODO: here we end because self.MapWindow3D is None for a while
         self._giface.updateMap.disconnect(self.MapWindow3D.UpdateMap)
         self._giface.updateMap.connect(self.MapWindow2D.UpdateMap)
 
@@ -472,19 +486,7 @@
         if self._mgr.GetPane(name).IsOk():
             return self._mgr.GetPane(name).IsShown()
         return False
-        
-    def OnFocus(self, event):
-        """!Change choicebook page to match display.
-        """
-        # change bookcontrol page to page associated with display
-        if self.page:
-            pgnum = self.layerbook.GetPageIndex(self.page)
-            if pgnum > -1:
-                self.layerbook.SetSelection(pgnum)
-                self._layerManager.currentPage = self.layerbook.GetCurrentPage()
-        
-        event.Skip()
-        
+
     def RemoveQueryLayer(self):
         """!Removes temporary map layers (queries)"""
         qlayer = self.GetMap().GetListOfLayers(name = globalvar.QUERYLAYER)
@@ -639,6 +641,7 @@
         """!Window closed.
         Also close associated layer tree page
         """
+        Debug.msg(2, "MapFrame.OnCloseWindow(): function starts")
         pgnum = None
         self.Map.Clean()
         
@@ -656,6 +659,7 @@
             pgnum = self.layerbook.GetPageIndex(self.page)
             if pgnum > -1:
                 self.layerbook.DeletePage(pgnum)
+        Debug.msg(2, "MapFrame.OnCloseWindow(): function ends")
 
     def Query(self, x, y):
         """!Query selected layers. 
@@ -926,7 +930,7 @@
     def OnHistogram(self, event):
         """!Init histogram display canvas and tools
         """
-        win = HistogramFrame(self)
+        win = HistogramFrame(self, giface=self._giface)
         
         win.CentreOnParent()
         win.Show()
@@ -1077,10 +1081,9 @@
     
     def OnAddArrow(self, event):
         """!Handler for north arrow menu selection.
-            Opens Appearance page of nviz notebook.
         """
-        
-        self._layerManager.nviz.SetPage('decoration')
+        # here was opening of appearance page of nviz notebook
+        # but now moved to MapWindow3D where are other problematic nviz calls
         self.MapWindow3D.SetDrawArrow((70, 70))
         
     def GetOptData(self, dcmd, type, params, propwin):
@@ -1098,6 +1101,7 @@
         """!Set display extents to match selected raster (including
         NULLs) or vector map.
         """
+        Debug.msg(3, "MapFrame.OnZoomToMap()")
         layers = None
         if self.IsStandalone():
             layers = self.MapWindow.GetMap().GetListOfLayers(active = False)
@@ -1163,7 +1167,16 @@
         self.SetProperty('projection', projection)
         
     def IsStandalone(self):
-        """!Check if Map display is standalone"""
+        """!Check if Map display is standalone
+
+        @depreciated
+        """
+        # TODO: once it is removed from 2 places in vdigit it can be deleted
+        # here and also in base class and other classes in the tree (hopefully)
+        # and one place here still uses IsStandalone
+        Debug.msg(1, "MapFrame.IsStandalone(): Method IsStandalone is"
+                  "depreciated, use some general approach instead such as"
+                  " Signals or giface")
         if self._layerManager:
             return False
         
@@ -1174,7 +1187,12 @@
 
         @return window reference
         @return None (if standalone)
+
+        @depreciated
         """
+        Debug.msg(1, "MapFrame.GetLayerManager(): Method GetLayerManager is"
+                  "depreciated, use some general approach instead such as"
+                  " Signals or giface")
         return self._layerManager
     
     def GetMapToolbar(self):

Modified: grass/trunk/gui/wxpython/modules/histogram.py
===================================================================
--- grass/trunk/gui/wxpython/modules/histogram.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/modules/histogram.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -265,13 +265,14 @@
     """!Main frame for hisgram display window. Uses d.histogram
     rendered onto canvas
     """
-    def __init__(self, parent = None, id = wx.ID_ANY,
+    def __init__(self, parent, giface, id=wx.ID_ANY,
                  title = _("GRASS GIS Histogramming Tool (d.histogram)"),
                  size = wx.Size(500, 350),
                  style = wx.DEFAULT_FRAME_STYLE, **kwargs):
         wx.Frame.__init__(self, parent, id, title, size = size, style = style, **kwargs)
         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
-        
+
+        self._giface = giface
         self.Map   = Map()         # instance of render.Map to be associated with display
         self.layer = None          # reference to layer with histogram
         
@@ -286,13 +287,14 @@
         self.SetToolBar(self.toolbar)
 
         # find selected map
+        # might by moved outside this class
+        # setting to None but honestly we do not handle no map case
+        # TODO: when self.mapname is None content of map window is showed
         self.mapname = None
-        if parent.GetName() == "MapWindow" and not parent.IsStandalone():
-            tree = parent.GetLayerManager().GetLayerTree()
+        layers = self._giface.GetLayerList().GetSelectedLayers()
+        if len(layers) > 0:
+            self.mapname = layers[0].maplayer.name
 
-            if tree.layer_selected and tree.GetLayerInfo(tree.layer_selected, key = 'type') == 'raster':
-                self.mapname = tree.GetLayerInfo(tree.layer_selected, key = 'maplayer').name
-
         # Add statusbar
         self.statusbar = self.CreateStatusBar(number = 1, style = 0)
         # self.statusbar.SetStatusWidths([-2, -1])

Modified: grass/trunk/gui/wxpython/nviz/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/mapwindow.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/nviz/mapwindow.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -106,6 +106,10 @@
         # Emitted when the zoom history stack is not empty
         self.zoomHistoryAvailable = Signal('GLWindow.zoomHistoryAvailable')
 
+        # Emitted when map was queried, parameters x, y are mouse coordinates
+        # TODO: change pixel coordinates to map coordinates (using Pixel2Cell)
+        self.mapQueried = Signal('GLWindow.mapQueried')
+
         self.init = False
         self.initView = False
         self.context = None
@@ -821,14 +825,12 @@
     def OnLeftUp(self, event):
         self.mouse['end'] = event.GetPositionTuple()
         if self.mouse["use"] == "query":
-            # querying
-            if self.frame.IsStandalone():
-                GMessage(parent = self.frame,
-                         message = _("Querying is not implemented in standalone mode of Map Display"))
-                return
+            # here changed from 'begin' to 'end' because it is more common
+            # behavior used also in 2d map window
+            # and moreover we are in left up
+            self.mapQueried.emit(x=self.mouse['end'][0],
+                                 y=self.mouse['end'][1])
 
-            self.frame.Query(self.mouse['begin'][0],self.mouse['begin'][1])
-
         elif self.mouse["use"] in ('arrow', 'scalebar'):
             self.lmgr.nviz.FindWindowById(
                     self.lmgr.nviz.win['decoration'][self.mouse["use"]]['place']).SetValue(False)
@@ -1229,7 +1231,10 @@
         return int(size * coef)/coef
     
     def SetDrawArrow(self, pos):
-        
+        """North arrow drawing.
+
+        Also, opens Appearance page of nviz notebook (needs refactoring).
+        """
         if self._display.SetArrow(pos[0], pos[1], 
                                  self.decoration['arrow']['size'],
                                  self.decoration['arrow']['color']):
@@ -1239,7 +1244,11 @@
             self.decoration['arrow']['position']['x'] = pos[0]
             self.decoration['arrow']['position']['y'] = pos[1]
             self.Refresh(False)
-    
+        # this was in mapdisp/frame.py but moved here to be with similar calls
+        # such as self.lmgr.nviz.UpdatePage
+        # anyway, it need to be handled in some another way
+        self.lmgr.nviz.SetPage('decoration')
+
     def SetDrawScalebar(self, pos):
         """!Add scale bar, sets properties and draw"""
         if len(self.decoration['scalebar']) == 0:

Modified: grass/trunk/gui/wxpython/vdigit/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/preferences.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/vdigit/preferences.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -696,6 +696,8 @@
 
         @todo Needs refactoring 
         """
+        # TODO: it seems that it needs to be replaced by signal
+        # but if it makes sense generally for wxGUI it can be added to giface 
         if self.parent.GetLayerManager():
             self.parent.GetLayerManager().WorkspaceChanged() # geometry attributes
         # symbology

Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-07 09:51:37 UTC (rev 57430)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-07 21:08:10 UTC (rev 57431)
@@ -31,11 +31,11 @@
 class VDigitToolbar(BaseToolbar):
     """!Toolbar for digitization
     """
-    def __init__(self, parent, MapWindow, digitClass, giface, tools = [], layerTree = None, log = None):
+    def __init__(self, parent, MapWindow, digitClass, giface,
+                 tools=[], layerTree=None):
         self.MapWindow     = MapWindow
         self.Map           = MapWindow.GetMap() # Map class instance
         self.layerTree     = layerTree  # reference to layer tree associated to map display
-        self.log           = log        # log area
         self.tools         = tools
         self.digitClass    = digitClass
         BaseToolbar.__init__(self, parent)
@@ -336,7 +336,8 @@
         self.MapWindow.mouse['use'] = "pointer"
         self.MapWindow.mouse['box'] = "point"
         self.MapWindow.polycoords = []
-        
+
+        # TODO: replace this by binding wx event in parent (or use signals...)
         if not self.parent.IsStandalone():
             # disable the toolbar
             self.parent.RemoveToolbar("vdigit")
@@ -688,7 +689,7 @@
             else:
                 openVectorMap = None
             dlg = CreateNewVector(self.parent,
-                                  exceptMap = openVectorMap, log = self.log,
+                                  exceptMap=openVectorMap, giface=self._giface,
                                   cmd = (('v.edit',
                                           { 'tool' : 'create' },
                                           'map')),
@@ -707,6 +708,10 @@
                 
                 # create table ?
                 if dlg.IsChecked('table'):
+                    # TODO: replace this by signal
+                    # also note that starting of tools such as atm, iclass,
+                    # plots etc. should be handled in some better way
+                    # than starting randomly from mapdisp and lmgr
                     lmgr = self.parent.GetLayerManager()
                     if lmgr:
                         lmgr.OnShowAttributeTable(None, selection = 'table')



More information about the grass-commit mailing list