[GRASS-SVN] r48828 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 16 06:28:06 EDT 2011


Author: martinl
Date: 2011-10-16 03:28:06 -0700 (Sun, 16 Oct 2011)
New Revision: 48828

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI: attempt to fix #1463 (part 1 & 2)


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -540,22 +540,22 @@
         self.wind = event.GetString()
     
 class DecorationDialog(wx.Dialog):
+    """!Controls setting options and displaying/hiding map overlay
+    decorations
     """
-    Controls setting options and displaying/hiding map overlay decorations
-    """
     def __init__(self, parent, ovlId, title, cmd, name = None,
                  pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE,
                  checktxt = '', ctrltxt = ''):
-
+        
         wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
-
+        
         self.ovlId   = ovlId   # PseudoDC id
         self.cmd     = cmd
         self.name    = name    # overlay name
         self.parent  = parent  # MapFrame
-
+        
         sizer = wx.BoxSizer(wx.VERTICAL)
-
+        
         box = wx.BoxSizer(wx.HORIZONTAL)
         self.chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY, label = checktxt)
         if self.parent.Map.GetOverlay(self.ovlId) is None:
@@ -629,7 +629,7 @@
         sizer.Fit(self)
 
         # create overlay if doesn't exist
-        self._CreateOverlay()
+        self._createOverlay()
         
         if len(self.parent.MapWindow.overlays[self.ovlId]['cmd']) > 1:
             if name == 'legend':
@@ -642,8 +642,9 @@
                                       mapName)
             
         
-    def _CreateOverlay(self):
-        if not self.parent.Map.GetOverlay(self.ovlId):
+    def _createOverlay(self):
+        """!Creates overlay"""
+        if not self.parent.GetMap().GetOverlay(self.ovlId):
             self.newOverlay = self.parent.Map.AddOverlay(id = self.ovlId, type = self.name,
                                                          command = self.cmd,
                                                          l_active = False, l_render = False, l_hidden = True)
@@ -660,15 +661,11 @@
         else:
             if self.parent.MapWindow.overlays[self.ovlId]['propwin'] == None:
                 return
-
+            
             self.parent.MapWindow.overlays[self.ovlId]['propwin'].get_dcmd = self.GetOptData
-
-
+        
     def OnOptions(self, event):
-        """        self.SetSizer(sizer)
-        sizer.Fit(self)
-
-        Sets option for decoration map overlays
+        """!Sets option for decoration map overlays
         """
         if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None:
             # build properties dialog
@@ -680,7 +677,7 @@
                 self.parent.MapWindow.overlays[self.ovlId]['propwin'].SetFocus()
             else:
                 self.parent.MapWindow.overlays[self.ovlId]['propwin'].Show()
-    
+        
     def OnResize(self, event):
         if self.FindWindowByName('resize').GetValue():
             self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
@@ -706,16 +703,16 @@
         """!Button 'OK' pressed"""
         # enable or disable overlay
         self.parent.Map.GetOverlay(self.ovlId).SetActive(self.chkbox.IsChecked())
-
+        
         # update map
         if self.parent.IsPaneShown('3d'):
             self.parent.MapWindow.UpdateOverlays()
         
         self.parent.MapWindow.UpdateMap()
-
+        
         # close dialog
         self.OnCancel(None)
-
+        
     def GetOptData(self, dcmd, layer, params, propwin):
         """!Process decoration layer data"""
         # update layer data

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -788,8 +788,8 @@
             if not display or not display.IsAutoRendered():
                 return
             mapLayers = map(lambda x: x.GetName(),
-                            display.GetRender().GetListOfLayers(l_type = 'raster') +
-                            display.GetRender().GetListOfLayers(l_type = 'vector'))
+                            display.GetMap().GetListOfLayers(l_type = 'raster') +
+                            display.GetMap().GetListOfLayers(l_type = 'vector'))
             
             try:
                 task = menuform.GUI(show = None).ParseCommand(event.cmd)

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -234,13 +234,6 @@
         """
         return self.statusbarManager.GetProgressBar()
         
-    def GetRender(self):
-        """!Returns current instance of render.Map()
-        
-        @todo make this method obsolate (name GetMap is better)
-        """
-        return self.Map
-
     def GetMap(self):
         """!Returns current Map instance
         """
@@ -1523,12 +1516,13 @@
             return
         
         id = 1 # index for overlay layer in render
-
+        
         cmd = ['d.legend', 'at=5,50,2,5']
-        if self.tree.layer_selected and \
+        
+        if self.tree and self.tree.layer_selected and \
                 self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
             cmd.append('map=%s' % self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
-
+        
         # Decoration overlay control dialog
         self.dialogs['legend'] = \
             gdialogs.DecorationDialog(parent = self, title = ('Legend'),
@@ -1539,13 +1533,13 @@
                                       name = 'legend',
                                       checktxt = _("Show/hide legend"),
                                       ctrltxt = _("legend object")) 
-
+    
         self.dialogs['legend'].CentreOnParent() 
         ### dialog cannot be show as modal - in the result d.legend is not selectable
         ### self.dialogs['legend'].ShowModal()
         self.dialogs['legend'].Show()
         self.MapWindow.mouse['use'] = 'pointer'
-
+        
     def OnAddText(self, event):
         """!Handler for text decoration menu selection.
         """
@@ -1620,7 +1614,11 @@
         """!Set display extents to match selected raster (including
         NULLs) or vector map.
         """
-        self.MapWindow.ZoomToMap()
+        layers = None
+        if self.IsStandalone():
+            layers = self.MapWindow.GetMap().GetListOfLayers(l_active = False)
+        
+        self.MapWindow.ZoomToMap(layers = layers)
 
     def OnZoomToRaster(self, event):
         """!Set display extents to match selected raster map (ignore NULLs)
@@ -1747,6 +1745,7 @@
             self.timer.Stop()
             self.cmdTimeStamp = os.path.getmtime(monFile['cmd'])
             self.mapFrm.OnDraw(None)
+            self.mapFrm.GetMap().GetLayersFromCmdFile()
             self.timer.Start(mtime)
         
 if __name__ == "__main__":

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -1912,3 +1912,7 @@
             dist = math.sqrt(math.pow((dEast), 2) + math.pow((dNorth), 2))
         
         return (dist, (dEast, dNorth))
+
+    def GetMap(self):
+        """!Get render.Map() instance"""
+        return self.Map

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -648,8 +648,8 @@
             return
         
         mapLayers = map(lambda x: x.GetName(),
-                        display.GetRender().GetListOfLayers(l_type = 'raster') +
-                        display.GetRender().GetListOfLayers(l_type = 'vector'))
+                        display.GetMap().GetListOfLayers(l_type = 'raster') +
+                        display.GetMap().GetListOfLayers(l_type = 'vector'))
         
         task = GUI(show = None).ParseCommand(cmd)
         for p in task.get_options()['params']:

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2011-10-16 09:53:20 UTC (rev 48827)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2011-10-16 10:28:06 UTC (rev 48828)
@@ -833,13 +833,17 @@
         
         return selected
 
-    def _renderLayers(self, force, mapWindow):
+    def _renderLayers(self, force = False, mapWindow = None, overlaysOnly = False):
         maps = list()
         masks = list()
         opacities = list()
         # render map layers
         ilayer = 1
-        for layer in self.layers + self.overlays:
+        if overlaysOnly:
+            layers = self.overlays
+        else:
+            self. self.layers + self.overlays
+        for layer in layers:
             # skip non-active map layers
             if not layer or not layer.active:
                 continue
@@ -866,6 +870,36 @@
         
         return maps, masks, opacities
     
+    def GetLayersFromCmdFile(self):
+        """!Get list of map layers from cmdfile
+        """
+        if not self.cmdfile:
+            return
+        
+        nlayers = 0
+        try:
+            fd = open(self.cmdfile, 'r')
+            for line in fd.readlines():
+                cmd = utils.split(line.strip())
+                ltype = None
+                if cmd[0] == 'd.rast':
+                    ltype = 'raster'
+                
+                name = utils.GetLayerNameFromCmd(cmd, fullyQualified = True,
+                                                 layerType = ltype)[0]
+                
+                self.AddLayer(type = ltype, command = cmd, l_active = False, name = name)
+                nlayers += 1
+        except IOError, e:
+            grass.warning(_("Unable to read cmdfile '%(cmd)s'. Details: %(det)s") % \
+                              { 'cmd' : self.cmdfile, 'det' : e })
+            return
+        
+        fd.close()
+
+        Debug.msg(1, "Map.GetLayersFromCmdFile(): cmdfile=%s" % self.cmdfile)
+        Debug.msg(1, "                            nlayers=%d" % nlayers)
+                
     def _parseCmdFile(self):
         """!Parse cmd file for standalone application
         """
@@ -876,14 +910,13 @@
             cmdLines = fd.readlines()
             gcmd.RunCommand('g.gisenv',
                             set = 'MONITOR_%s_CMDFILE=' % self.monitor)
-            
+
             for cmd in cmdLines:
-                cmdStr = cmd.strip().split(' ')
+                cmdStr = utils.split(cmd.strip())
                 cmd = utils.CmdToTuple(cmdStr)
-
                 gcmd.RunCommand(cmd[0], **cmd[1])
                 nlayers += 1
-
+            
             gcmd.RunCommand('g.gisenv',
                             set = 'MONITOR_%s_CMDFILE=%s' % (self.monitor, self.cmdfile))
         except IOError, e:
@@ -895,7 +928,7 @@
 
         Debug.msg(1, "Map.__parseCmdFile(): cmdfile=%s" % self.cmdfile)
         Debug.msg(1, "                      nlayers=%d" % nlayers)
-
+        
         return nlayers
 
     def _renderCmdFile(self, force, windres):
@@ -914,6 +947,18 @@
         grass.try_remove(self.mapfileCmd) # GRASS_PNG_READ is TRUE
         
         nlayers = self._parseCmdFile()
+        if self.overlays:
+            gcmd.RunCommand('g.gisenv',
+                            unset = 'MONITOR') # GRASS_RENDER_IMMEDIATE doesn't like monitors
+            driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
+            if driver == 'png':
+                os.environ["GRASS_RENDER_IMMEDIATE"] = "png"
+            else:
+                os.environ["GRASS_RENDER_IMMEDIATE"] = "cairo"
+            self._renderLayers(overlaysOnly = True)
+            del os.environ["GRASS_RENDER_IMMEDIATE"]
+            gcmd.RunCommand('g.gisenv',
+                            set = 'MONITOR=%s' % currMon)
         
         if currMon != self.monitor:
             gcmd.RunCommand('g.gisenv',
@@ -1053,6 +1098,15 @@
 
         return layer
 
+    def DeleteAllLayers(self, overlay = False):
+        """!Delete all layers 
+
+        @param overlay True to delete also overlayes
+        """
+        self.layers = []
+        if overlay:
+            self.overlays = []
+        
     def DeleteLayer(self, layer, overlay = False):
         """!Removes layer from list of layers
         



More information about the grass-commit mailing list