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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 1 17:45:37 EDT 2010


Author: martinl
Date: 2010-06-01 17:45:37 -0400 (Tue, 01 Jun 2010)
New Revision: 42429

Modified:
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
Log:
wxGUI/nviz: cosmetics in vector layer properties tab
siplified gselect.Select()


Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-06-01 20:34:56 UTC (rev 42428)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-06-01 21:45:37 UTC (rev 42429)
@@ -49,13 +49,20 @@
 wxGdalSelect, EVT_GDALSELECT = NewEvent()
 
 class Select(wx.combo.ComboCtrl):
-    def __init__(self, parent, id, size = globalvar.DIALOG_GSELECT_SIZE,
-                 type = None, multiple = False, mapsets = None, exclude = [],
-                 updateOnPopup = True):
-        """!Custom control to create a ComboBox with a tree control
-        to display and select GIS elements within acessible mapsets.
-        Elements can be selected with mouse. Can allow multiple selections, when
-        argument multiple=True. Multiple selections are separated by commas.
+    def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
+                 type = None, multiple = False, mapsets = None,
+                 updateOnPopup = True, onPopup = None):
+        """!Custom control to create a ComboBox with a tree control to
+        display and select GIS elements within acessible mapsets.
+        Elements can be selected with mouse. Can allow multiple
+        selections, when argument multiple=True. Multiple selections
+        are separated by commas.
+
+        @param type type of GIS elements ('raster, 'vector', ...)
+        @param multiple multiple input allowed?
+        @param mapsets force list of mapsets (otherwise search path)
+        @param updateOnPopup True for updating list of elements on popup
+        @param onPopup function to be called on Popup
         """
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
         self.GetChildren()[0].SetName("Select")
@@ -66,19 +73,17 @@
         self.SetPopupExtents(0,100)
         if type:
             self.tcp.SetData(type = type, mapsets = mapsets,
-                             exclude = exclude, multiple = multiple,
-                             updateOnPopup = updateOnPopup)
+                             multiple = multiple,
+                             updateOnPopup = updateOnPopup, onPopup = onPopup)
         
-    def SetElementList(self, type, mapsets = None, exclude = []):
+    def SetElementList(self, type, mapsets = None):
         """!Set element list
 
         @param type GIS element type
         @param mapsets list of acceptable mapsets (None for all in search path)
-        @param exclude list of GIS elements to be excluded
         """
-        self.tcp.SetData(type = type, mapsets = mapsets,
-                         exclude = exclude)
-
+        self.tcp.SetData(type = type, mapsets = mapsets)
+        
     def GetElementList(self):
         """!Load elements"""
         self.tcp.GetElementList()
@@ -119,9 +124,10 @@
         self.curitem = None
         self.multiple = False
         self.type = None
-        self.mapsets = []
-        self.exclude = []
-
+        self.mapsets = None
+        self.updateOnPopup = True
+        self.onPopup = None
+        
         self.SetFilter(None)
         
     def Create(self, parent):
@@ -173,17 +179,22 @@
         """!Limited only for first selected"""
         if not force and not self.updateOnPopup:
             return
+        if self.onPopup:
+            selected, exclude = self.onPopup()
+        else:
+            selected = None
+            exclude  = False
+            
+        self.GetElementList(selected, exclude)
     
-        self.GetElementList()
-    
-    def GetElementList(self):
+    def GetElementList(self, elements = None, exclude = False):
         """!Get filtered list of GIS elements in accessible mapsets
         and display as tree with all relevant elements displayed
         beneath each mapset branch
         """
         # update list
         self.seltree.DeleteAllItems()
-        self._getElementList(self.type, self.mapsets, self.exclude)
+        self._getElementList(self.type, self.mapsets, elements, exclude)
         
         if len(self.value) > 0:
             root = self.seltree.GetRootItem()
@@ -209,13 +220,14 @@
     def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
         return wx.Size(minWidth, min(200, maxHeight))
 
-    def _getElementList(self, element, mapsets=None, exclude=[]):
+    def _getElementList(self, element, mapsets = None, elements = None, exclude = False):
         """!Get list of GIS elements in accessible mapsets and display as tree
         with all relevant elements displayed beneath each mapset branch
 
         @param element GIS element
         @param mapsets list of acceptable mapsets (None for all mapsets in search path)
-        @param exclude list of GIS elements to be excluded
+        @param elements list of forced GIS elements
+        @param exclude True to exclude, False for forcing the list (elements)
         """
         # get current mapset
         curr_mapset = grass.gisenv()['MAPSET']
@@ -223,7 +235,7 @@
         # list of mapsets in current location
         if mapsets is None:
             mapsets = utils.ListOfMapsets()
-
+        
         # map element types to g.mlist types
         elementdict = {'cell':'rast',
                        'raster':'rast',
@@ -269,11 +281,11 @@
                        '3dview':'3dview',
                        '3D viewing parameters':'3dview',
                        '3D view parameters':'3dview'}
-
+        
         if element not in elementdict:
             self.AddItem(_('Not selectable element'))
             return
-
+        
         # get directory tree nodes
         # reorder mapsets based on search path (TODO)
         for i in range(len(mapsets)):
@@ -299,9 +311,11 @@
                 for elem in elem_list:
                     if elem != '':
                         fullqElem = elem + '@' + dir
-                        if len(exclude) > 0 and fullqElem in exclude:
-                            continue
-
+                        if elements:
+                            if (exclude and fullqElem in elements) or \
+                                    (not exclude and fullqElem not in elements):
+                                continue
+                        
                         if self.filterElements:
                             if self.filterElements(fullqElem):
                                 self.AddItem(fullqElem, parent=dir_node)
@@ -393,12 +407,12 @@
             self.type = kargs['type']
         if kargs.has_key('mapsets'):
             self.mapsets = kargs['mapsets']
-        if kargs.has_key('exclude'):
-            self.exclude = kargs['exclude']
         if kargs.has_key('multiple'):
             self.multiple = kargs['multiple']
         if kargs.has_key('updateOnPopup'):
             self.updateOnPopup = kargs['updateOnPopup']
+        if kargs.has_key('onPopup'):
+            self.onPopup = kargs['onPopup']
         
 class VectorDBInfo:
     """!Class providing information about attribute tables

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2010-06-01 20:34:56 UTC (rev 42428)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2010-06-01 21:45:37 UTC (rev 42429)
@@ -526,14 +526,25 @@
         self.win['vector'] = {}
         
         #
-        # desc
+        # selection
         #
-        desc = wx.StaticText(parent = panel, id = wx.ID_ANY,
-                             label = "")
+        box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
+                            label = " %s " % (_("Vector map")))
+        boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+        vmaps = gselect.Select(parent = panel, type = 'vector',
+                               onPopup = self.GselectOnPopup)
+        self.win['vector']['map'] = vmaps.GetId()
+        desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
         self.win['vector']['desc'] = desc.GetId()
-        pageSizer.Add(item = desc, proportion = 0,
-                      flag = wx.EXPAND | wx.ALL,
-                      border = 10)
+        boxSizer.Add(item = vmaps, proportion = 0,
+                     flag = wx.ALL,
+                     border = 3)
+        boxSizer.Add(item = desc, proportion = 0,
+                     flag = wx.ALL,
+                     border = 3)
+        pageSizer.Add(item = boxSizer, proportion = 0,
+                      flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
+                      border = 3)
         
         #
         # vector lines
@@ -758,6 +769,13 @@
         panel.Layout()
         return panel.GetBestSize()
 
+    def GselectOnPopup(self, exclude = False):
+        """Update gselect.Select() items"""
+        maps = list()
+        for layer in self.mapWindow.Map.GetListOfLayers(l_type='vector'):
+            maps.append(layer.GetName())
+        return maps, exclude
+    
     def _createVolumePage(self):
         """!Create view settings page"""
         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
@@ -2657,10 +2675,10 @@
                 nprimitives += int(value)
         
         if mapIs3D:
-            desc = _("Vector map <%s> is 3D") % layer.name
+            desc = _("Vector map is 3D")
             enable = False
         else:
-            desc = _("Vector map <%s> is 2D") % layer.name
+            desc = _("Vector map is 2D")
             enable = True
         desc += " - " + _("%(primitives)d primitives (%(points)d points)") % \
             { 'primitives' : nprimitives, 'points' : npoints }
@@ -2671,6 +2689,7 @@
             self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
             self.FindWindowById(self.win['vector'][v]['height']['spin']).Enable(enable)
             
+        self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
         self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
         #
         # lines



More information about the grass-commit mailing list