Browse Source

wxGUI/nviz: cosmetics in vector layer properties tab
siplified gselect.Select()


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42429 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 15 years ago
parent
commit
7e5b207504
2 changed files with 72 additions and 39 deletions
  1. 45 31
      gui/wxpython/gui_modules/gselect.py
  2. 27 8
      gui/wxpython/gui_modules/nviz_tools.py

+ 45 - 31
gui/wxpython/gui_modules/gselect.py

@@ -49,13 +49,20 @@ from debug import Debug
 wxGdalSelect, EVT_GDALSELECT = NewEvent()
 wxGdalSelect, EVT_GDALSELECT = NewEvent()
 
 
 class Select(wx.combo.ComboCtrl):
 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)
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
         self.GetChildren()[0].SetName("Select")
         self.GetChildren()[0].SetName("Select")
@@ -66,19 +73,17 @@ class Select(wx.combo.ComboCtrl):
         self.SetPopupExtents(0,100)
         self.SetPopupExtents(0,100)
         if type:
         if type:
             self.tcp.SetData(type = type, mapsets = mapsets,
             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
         """!Set element list
 
 
         @param type GIS element type
         @param type GIS element type
         @param mapsets list of acceptable mapsets (None for all in search path)
         @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):
     def GetElementList(self):
         """!Load elements"""
         """!Load elements"""
         self.tcp.GetElementList()
         self.tcp.GetElementList()
@@ -119,9 +124,10 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         self.curitem = None
         self.curitem = None
         self.multiple = False
         self.multiple = False
         self.type = None
         self.type = None
-        self.mapsets = []
-        self.exclude = []
-
+        self.mapsets = None
+        self.updateOnPopup = True
+        self.onPopup = None
+        
         self.SetFilter(None)
         self.SetFilter(None)
         
         
     def Create(self, parent):
     def Create(self, parent):
@@ -173,17 +179,22 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         """!Limited only for first selected"""
         """!Limited only for first selected"""
         if not force and not self.updateOnPopup:
         if not force and not self.updateOnPopup:
             return
             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
         """!Get filtered list of GIS elements in accessible mapsets
         and display as tree with all relevant elements displayed
         and display as tree with all relevant elements displayed
         beneath each mapset branch
         beneath each mapset branch
         """
         """
         # update list
         # update list
         self.seltree.DeleteAllItems()
         self.seltree.DeleteAllItems()
-        self._getElementList(self.type, self.mapsets, self.exclude)
+        self._getElementList(self.type, self.mapsets, elements, exclude)
         
         
         if len(self.value) > 0:
         if len(self.value) > 0:
             root = self.seltree.GetRootItem()
             root = self.seltree.GetRootItem()
@@ -209,13 +220,14 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
     def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
     def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
         return wx.Size(minWidth, min(200, 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
         """!Get list of GIS elements in accessible mapsets and display as tree
         with all relevant elements displayed beneath each mapset branch
         with all relevant elements displayed beneath each mapset branch
 
 
         @param element GIS element
         @param element GIS element
         @param mapsets list of acceptable mapsets (None for all mapsets in search path)
         @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
         # get current mapset
         curr_mapset = grass.gisenv()['MAPSET']
         curr_mapset = grass.gisenv()['MAPSET']
@@ -223,7 +235,7 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         # list of mapsets in current location
         # list of mapsets in current location
         if mapsets is None:
         if mapsets is None:
             mapsets = utils.ListOfMapsets()
             mapsets = utils.ListOfMapsets()
-
+        
         # map element types to g.mlist types
         # map element types to g.mlist types
         elementdict = {'cell':'rast',
         elementdict = {'cell':'rast',
                        'raster':'rast',
                        'raster':'rast',
@@ -269,11 +281,11 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
                        '3dview':'3dview',
                        '3dview':'3dview',
                        '3D viewing parameters':'3dview',
                        '3D viewing parameters':'3dview',
                        '3D view parameters':'3dview'}
                        '3D view parameters':'3dview'}
-
+        
         if element not in elementdict:
         if element not in elementdict:
             self.AddItem(_('Not selectable element'))
             self.AddItem(_('Not selectable element'))
             return
             return
-
+        
         # get directory tree nodes
         # get directory tree nodes
         # reorder mapsets based on search path (TODO)
         # reorder mapsets based on search path (TODO)
         for i in range(len(mapsets)):
         for i in range(len(mapsets)):
@@ -299,9 +311,11 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
                 for elem in elem_list:
                 for elem in elem_list:
                     if elem != '':
                     if elem != '':
                         fullqElem = elem + '@' + dir
                         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:
                             if self.filterElements(fullqElem):
                             if self.filterElements(fullqElem):
                                 self.AddItem(fullqElem, parent=dir_node)
                                 self.AddItem(fullqElem, parent=dir_node)
@@ -393,12 +407,12 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
             self.type = kargs['type']
             self.type = kargs['type']
         if kargs.has_key('mapsets'):
         if kargs.has_key('mapsets'):
             self.mapsets = kargs['mapsets']
             self.mapsets = kargs['mapsets']
-        if kargs.has_key('exclude'):
-            self.exclude = kargs['exclude']
         if kargs.has_key('multiple'):
         if kargs.has_key('multiple'):
             self.multiple = kargs['multiple']
             self.multiple = kargs['multiple']
         if kargs.has_key('updateOnPopup'):
         if kargs.has_key('updateOnPopup'):
             self.updateOnPopup = kargs['updateOnPopup']
             self.updateOnPopup = kargs['updateOnPopup']
+        if kargs.has_key('onPopup'):
+            self.onPopup = kargs['onPopup']
         
         
 class VectorDBInfo:
 class VectorDBInfo:
     """!Class providing information about attribute tables
     """!Class providing information about attribute tables

+ 27 - 8
gui/wxpython/gui_modules/nviz_tools.py

@@ -526,14 +526,25 @@ class NvizToolWindow(FN.FlatNotebook):
         self.win['vector'] = {}
         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()
         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
         # vector lines
@@ -758,6 +769,13 @@ class NvizToolWindow(FN.FlatNotebook):
         panel.Layout()
         panel.Layout()
         return panel.GetBestSize()
         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):
     def _createVolumePage(self):
         """!Create view settings page"""
         """!Create view settings page"""
         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
@@ -2657,10 +2675,10 @@ class NvizToolWindow(FN.FlatNotebook):
                 nprimitives += int(value)
                 nprimitives += int(value)
         
         
         if mapIs3D:
         if mapIs3D:
-            desc = _("Vector map <%s> is 3D") % layer.name
+            desc = _("Vector map is 3D")
             enable = False
             enable = False
         else:
         else:
-            desc = _("Vector map <%s> is 2D") % layer.name
+            desc = _("Vector map is 2D")
             enable = True
             enable = True
         desc += " - " + _("%(primitives)d primitives (%(points)d points)") % \
         desc += " - " + _("%(primitives)d primitives (%(points)d points)") % \
             { 'primitives' : nprimitives, 'points' : npoints }
             { 'primitives' : nprimitives, 'points' : npoints }
@@ -2671,6 +2689,7 @@ class NvizToolWindow(FN.FlatNotebook):
             self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
             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'][v]['height']['spin']).Enable(enable)
             
             
+        self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
         self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
         self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
         #
         #
         # lines
         # lines