[GRASS-SVN] r35725 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 1 16:58:39 EST 2009


Author: martinl
Date: 2009-02-01 16:58:39 -0500 (Sun, 01 Feb 2009)
New Revision: 35725

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/render.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/workspace.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py
Log:
wxGUI: multiple layer selection fixes


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py	2009-02-01 21:52:09 UTC (rev 35724)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py	2009-02-01 21:58:39 UTC (rev 35725)
@@ -182,35 +182,52 @@
     def OnZoomToRaster(self, event):
         pass
 
-    def GetSelectedLayer(self, type='layer'):
+    def GetSelectedLayer(self, type = 'layer', multi = False):
         """
         Get selected layer from layer tree
 
         @param type 'item' / 'layer' / 'nviz'
-
+        @param multi return first selected layer or all
+        
         @return layer / map layer properties / nviz properties
-        @return None on failure
+        @return None / [] on failure
         """
-        # get currently selected map layer
-        if not self.tree or not self.tree.GetSelection():
-            return None
+        ret = []
+        if not self.tree or \
+                not self.tree.GetSelection():
+            if multi:
+                return []
+            else:
+                return None
         
-        item = self.tree.GetSelection()
-        if not item.IsChecked():
-            return None
+        if multi and \
+                type == 'item':
+            return self.tree.GetSelections()
+        
+        for item in self.tree.GetSelections():
+            if not item.IsChecked():
+                if multi:
+                    continue
+                else:
+                    return None
 
-        if type == 'item':
-            return item
+            if type == 'item': # -> multi = False
+                return item
         
-        try:
-            if type == 'nviz':
-                layer = self.tree.GetPyData(item)[0]['nviz']
+            try:
+                if type == 'nviz':
+                    layer = self.tree.GetPyData(item)[0]['nviz']
+                else:
+                    layer = self.tree.GetPyData(item)[0]['maplayer']
+            except:
+                layer = None
+
+            if multi:
+                ret.append(layer)
             else:
-                layer = self.tree.GetPyData(item)[0]['maplayer']
-        except:
-            layer = None
+                return layer
             
-        return layer
+        return ret
 
 class BufferedWindow(MapWindow, wx.Window):
     """
@@ -2317,7 +2334,7 @@
         """
         self.ZoomToMap(zoom=True)
         
-    def ZoomToMap(self, layer=None, zoom=False):
+    def ZoomToMap(self, layer = None, zoom = False):
         """
         Set display extents to match selected raster
         or vector map.
@@ -2325,33 +2342,33 @@
         zoomreg = {}
 
         if not layer:
-            layer = self.GetSelectedLayer()
+            layer = self.GetSelectedLayer(multi = True)
         
-        if layer is None:
+        if not layer:
             return
 
-        Debug.msg (3, "BufferedWindow.ZoomToMap(): layer=%s, type=%s" % \
-                   (layer.name, layer.type))
+        rast = []
+        vect = []
+        updated = False
+        for l in layer:
+            # only raster/vector layers are currently supported
+            if l.type == 'raster':
+                rast.append(l.name)
+            elif l.type == 'vector':
+                if self.parent.digit and l.name == self.parent.digit.map and \
+                        self.parent.digit.type == 'vdigit':
+                    w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
+                    self.Map.GetRegion(n=n, s=s, w=w, e=e,
+                                       update=True)
+                    updated = True
+                else:
+                    vect.append(l.name)
 
-        # selected layer must be a valid map
-        if layer.type in ('raster', 'rgb', 'his', 'shaded', 'arrow'):
-            if layer.type == 'raster':
-                self.Map.region = self.Map.GetRegion(rast="%s" % layer.name)
-            else:
-                self.Map.region = self.Map.GetRegion(rast="%s" % layer.name)
-        elif layer.type in ('vector', 'thememap', 'themechart'):
-            if self.parent.digit and layer.name == self.parent.digit.map and \
-               self.parent.digit.type == 'vdigit':
-                w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
-                self.Map.region = self.Map.GetRegion(n=n, s=s, w=w, e=e)
-            else:
-                self.Map.region = self.Map.GetRegion(vect="%s" % layer.name)
-        else:
-            return
-
-        ### self.Map.SetRegion()
-        ### self.Map.AlignExtentFromDisplay()
-
+        if not updated:
+            self.Map.GetRegion(rast = rast,
+                               vect = vect,
+                               update = True)
+        
         self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
                          self.Map.region['e'], self.Map.region['w'])
 
@@ -4011,7 +4028,7 @@
         point = wx.GetMousePosition()
         zoommenu = wx.Menu()
         # Add items to the menu
-        zoommap = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to selected map'))
+        zoommap = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to selected map(s)'))
         zoommenu.AppendItem(zoommap)
         self.Bind(wx.EVT_MENU, self.MapWindow.OnZoomToMap, zoommap)
 

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/render.py	2009-02-01 21:52:09 UTC (rev 35724)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/render.py	2009-02-01 21:58:39 UTC (rev 35725)
@@ -583,9 +583,9 @@
             self.height = 480
             return False
 
-    def GetRegion(self, rast=None, zoom=False, vect=None,
-                  n=None, s=None, e=None, w=None, default=False,
-                  update=False):
+    def GetRegion(self, rast = [], zoom = False, vect = [],
+                  n = None, s = None, e = None, w = None, default = False,
+                  update = False):
         """
         Get region settings (g.region -upgc)
 
@@ -630,21 +630,21 @@
 
         if rast:
             if zoom:
-                cmdList.append('zoom=%s' % rast)
+                cmdList.append('zoom=%s' % ','.join(rast))
             else:
-                cmdList.append('rast=%s' % rast)
+                cmdList.append('rast=%s' % ','.join(rast))
 
         if vect:
-            cmdList.append('vect=%s' % vect)
+            cmdList.append('vect=%s' % ','.join(vect))
         
         try:
             cmdRegion = gcmd.Command(cmdList)
         except gcmd.CmdError, e:
             if rast:
-                e.message = _("Unable to zoom to raster map <%s>.") % rast + \
+                e.message = _("Unable to zoom to raster map <%s>.") % rast[0] + \
                 '%s%s' % (os.linesep, os.linesep) + e.message
             elif vect:
-                e.message = _("Unable to zoom to vector map <%s>.") % vect + \
+                e.message = _("Unable to zoom to vector map <%s>.") % vect[0] + \
                 '%s%s' % (os.linesep, os.linesep) + e.message
 
             print >> sys.stderr, e

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/workspace.py	2009-02-01 21:52:09 UTC (rev 35724)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/workspace.py	2009-02-01 21:58:39 UTC (rev 35725)
@@ -399,6 +399,7 @@
     def __writeLayer(self, mapTree, item):
         """Write bunch of layers to GRASS Workspace XML file"""
         self.indent += 4
+        itemSelected = mapTree.GetSelections()
         while item and item.IsOk():
             type = mapTree.GetPyData(item)[0]['type']
             if type != 'group':
@@ -433,7 +434,7 @@
 
                 self.indent += 4
                 # selected ?
-                if item == mapTree.layer_selected:
+                if item in itemSelected:
                     self.file.write('%s<selected />\n' % (' ' * self.indent))
                 # layer properties
                 self.file.write('%s<task name="%s">\n' % (' ' * self.indent, cmd[0]))

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py	2009-02-01 21:52:09 UTC (rev 35724)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py	2009-02-01 21:58:39 UTC (rev 35725)
@@ -228,9 +228,6 @@
         Debug.msg (4, "LayerTree.OnContextMenu: layertype=%s" % \
                        ltype)
 
-        ## pos = event.GetPosition()
-        ## pos = self.ScreenToClient(pos)
-
         if not hasattr (self, "popupID1"):
             self.popupID1 = wx.NewId()
             self.popupID2 = wx.NewId()
@@ -249,6 +246,9 @@
             self.popupID15 = wx.NewId()
 
         self.popupMenu = wx.Menu()
+
+        numSelected = len(self.GetSelections())
+        
         # general item
         self.popupMenu.Append(self.popupID1, text=_("Remove"))
         self.Bind(wx.EVT_MENU, self.gismgr.OnDeleteLayer, id=self.popupID1)
@@ -256,7 +256,9 @@
         if ltype != "command": # rename
             self.popupMenu.Append(self.popupID2, text=_("Rename"))
             self.Bind(wx.EVT_MENU, self.RenameLayer, id=self.popupID2)
-
+            if numSelected > 1:
+                self.popupMenu.Enable(self.popupID2, False)
+            
         # map layer items
         if ltype != "group" and \
                 ltype != "command": # properties
@@ -265,11 +267,14 @@
             self.Bind(wx.EVT_MENU, self.OnPopupOpacityLevel, id=self.popupID8)
             self.popupMenu.Append(self.popupID3, text=_("Properties"))
             self.Bind(wx.EVT_MENU, self.OnPopupProperties, id=self.popupID3)
-            self.popupMenu.Append(self.popupID9, text=_("Zoom to selected map"))
+            self.popupMenu.Append(self.popupID9, text=_("Zoom to selected map(s)"))
             self.Bind(wx.EVT_MENU, self.mapdisplay.MapWindow.OnZoomToMap, id=self.popupID9)
-            self.popupMenu.Append(self.popupID10, text=_("Set computational region from selected map"))
+            self.popupMenu.Append(self.popupID10, text=_("Set computational region from selected map(s)"))
             self.Bind(wx.EVT_MENU, self.OnSetCompRegFromMap, id=self.popupID10)
-
+            if numSelected > 1:
+                self.popupMenu.Enable(self.popupID8, False)
+                self.popupMenu.Enable(self.popupID3, False)
+            
         # specific items
         try:
             mltype = self.GetPyData(self.layer_selected)[0]['type']
@@ -328,14 +333,20 @@
             
             self.popupMenu.Append(self.popupID7, _("Metadata"))
             self.Bind (wx.EVT_MENU, self.OnMetadata, id=self.popupID7)
-
+            if numSelected > 1:
+                self.popupMenu.Enable(self.popupID4, False)
+                self.popupMenu.Enable(self.popupID5, False)
+                self.popupMenu.Enable(self.popupID6, False)
+                self.popupMenu.Enable(self.popupID7, False)
+                self.popupMenu.Enable(self.popupID14, False)
+        
         #
         # raster layers (specific items)
         #
         elif mltype and mltype == "raster":
-            self.popupMenu.Append(self.popupID12, text=_("Zoom to selected map (ignore NULLs)"))
+            self.popupMenu.Append(self.popupID12, text=_("Zoom to selected map(s) (ignore NULLs)"))
             self.Bind(wx.EVT_MENU, self.mapdisplay.MapWindow.OnZoomToRaster, id=self.popupID12)
-            self.popupMenu.Append(self.popupID13, text=_("Set computational region from selected map (ignore NULLs)"))
+            self.popupMenu.Append(self.popupID13, text=_("Set computational region from selected map(s) (ignore NULLs)"))
             self.Bind(wx.EVT_MENU, self.OnSetCompRegFromRaster, id=self.popupID13)
             self.popupMenu.AppendSeparator()
             self.popupMenu.Append(self.popupID15, _("Set color table"))
@@ -350,6 +361,13 @@
                 self.popupMenu.Append(self.popupID11, _("Nviz properties"))
                 self.Bind (wx.EVT_MENU, self.OnNvizProperties, id=self.popupID11)
 
+            if numSelected > 1:
+                self.popupMenu.Enable(self.popupID15, False)
+                self.popupMenu.Enable(self.popupID4, False)
+                self.popupMenu.Enable(self.popupID5, False)
+                self.popupMenu.Enable(self.popupID6, False)
+                self.popupMenu.Enable(self.popupID11, False)
+        
         ## self.PopupMenu(self.popupMenu, pos)
         self.PopupMenu(self.popupMenu)
         self.popupMenu.Destroy()



More information about the grass-commit mailing list