浏览代码

fix VectorSelect filter

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38048 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 年之前
父节点
当前提交
94478e154c
共有 1 个文件被更改,包括 38 次插入16 次删除
  1. 38 16
      gui/wxpython/gui_modules/gselect.py

+ 38 - 16
gui/wxpython/gui_modules/gselect.py

@@ -1,4 +1,4 @@
-"""
+"""!
 @package gselect
 @package gselect
 
 
 @brief Custom control that selects elements
 @brief Custom control that selects elements
@@ -36,7 +36,8 @@ from preferences import globalSettings as UserSettings
 
 
 class Select(wx.combo.ComboCtrl):
 class Select(wx.combo.ComboCtrl):
     def __init__(self, parent, id, size = globalvar.DIALOG_GSELECT_SIZE,
     def __init__(self, parent, id, size = globalvar.DIALOG_GSELECT_SIZE,
-                 type=None, multiple=False, mapsets=None, exceptOf=[]):
+                 type = None, multiple = False, mapsets = None, exclude = [],
+                 updateOnPopup = True):
         """!Custom control to create a ComboBox with a tree control
         """!Custom control to create a ComboBox with a tree control
         to display and select GIS elements within acessible mapsets.
         to display and select GIS elements within acessible mapsets.
         Elements can be selected with mouse. Can allow multiple selections, when
         Elements can be selected with mouse. Can allow multiple selections, when
@@ -52,17 +53,23 @@ 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,
-                             exceptOf = exceptOf, multiple = multiple)
+                             exclude = exclude, multiple = multiple,
+                             updateOnPopup = updateOnPopup)
 
 
-    def SetElementList(self, type, mapsets = None, exceptOf = []):
+    def SetElementList(self, type, mapsets = None, exclude = []):
         """!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 exceptOf list of GIS elements to be excluded"""
+        @param exclude list of GIS elements to be excluded
+        """
         self.tcp.SetData(type = type, mapsets = mapsets,
         self.tcp.SetData(type = type, mapsets = mapsets,
-                         exceptOf = exceptOf)
-        
+                         exclude = exclude)
+
+    def GetElementList(self):
+        """!Load elements"""
+        self.tcp.GetElementList()
+    
 class VectorSelect(Select):
 class VectorSelect(Select):
     def __init__(self, parent, ftype, **kwargs):
     def __init__(self, parent, ftype, **kwargs):
         """!Custom to create a ComboBox with a tree control to display and
         """!Custom to create a ComboBox with a tree control to display and
@@ -74,6 +81,8 @@ class VectorSelect(Select):
         Select.__init__(self, parent = parent, id = wx.ID_ANY,
         Select.__init__(self, parent = parent, id = wx.ID_ANY,
                         type = 'vector', **kwargs)
                         type = 'vector', **kwargs)
         
         
+        self.ftype = ftype
+        
         # remove vector maps which do not contain given feature type
         # remove vector maps which do not contain given feature type
         self.tcp.SetFilter(self.__filterElements)
         self.tcp.SetFilter(self.__filterElements)
         
         
@@ -86,7 +95,8 @@ class VectorSelect(Select):
                 # skip Mapset items
                 # skip Mapset items
                 vectorName = self.tcp.seltree.GetItemText(item)
                 vectorName = self.tcp.seltree.GetItemText(item)
                 try:
                 try:
-                    if int(grass.vector_info_topo(vectorName)['points']) < 1:
+                    print vectorName, int(grass.vector_info_topo(vectorName)[self.ftype])
+                    if int(grass.vector_info_topo(vectorName)[self.ftype]) < 1:
                         self.tcp.seltree.Delete(item)
                         self.tcp.seltree.Delete(item)
                 except KeyError:
                 except KeyError:
                     self.tcp.seltree.Delete(item)
                     self.tcp.seltree.Delete(item)
@@ -111,7 +121,7 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         self.multiple = False
         self.multiple = False
         self.type = None
         self.type = None
         self.mapsets = []
         self.mapsets = []
-        self.exceptOf = []
+        self.exclude = []
 
 
         self.SetFilter(None)
         self.SetFilter(None)
         
         
@@ -160,11 +170,21 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         """!Set filter for GIS elements, see e.g. VectorSelect"""
         """!Set filter for GIS elements, see e.g. VectorSelect"""
         self.filterElements = filter
         self.filterElements = filter
         
         
-    def OnPopup(self):
+    def OnPopup(self, force = False):
         """!Limited only for first selected"""
         """!Limited only for first selected"""
+        if not force and not self.updateOnPopup:
+            return
+    
+        self.GetElementList()
+    
+    def GetElementList(self):
+        """!Get filtered list of GIS elements in accessible mapsets
+        and display as tree with all relevant elements displayed
+        beneath each mapset branch
+        """
         # update list
         # update list
         self.seltree.DeleteAllItems()
         self.seltree.DeleteAllItems()
-        self.GetElementList(self.type, self.mapsets, self.exceptOf)
+        self._getElementList(self.type, self.mapsets, self.exclude)
         if self.filterElements:
         if self.filterElements:
             self.filterElements(self.seltree.GetRootItem())
             self.filterElements(self.seltree.GetRootItem())
         
         
@@ -192,13 +212,13 @@ 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, exceptOf=[]):
+    def _getElementList(self, element, mapsets=None, exclude=[]):
         """!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 exceptOf list of GIS elements to be excluded
+        @param exclude list of GIS elements to be excluded
         """
         """
         # get current mapset
         # get current mapset
         curr_mapset = grass.gisenv()['MAPSET']
         curr_mapset = grass.gisenv()['MAPSET']
@@ -282,7 +302,7 @@ 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(exceptOf) > 0 and fullqElem in exceptOf:
+                        if len(exclude) > 0 and fullqElem in exclude:
                             continue
                             continue
                         self.AddItem(fullqElem, parent=dir_node)
                         self.AddItem(fullqElem, parent=dir_node)
             except:
             except:
@@ -371,10 +391,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('exceptOf'):
-            self.exceptOf = kargs['exceptOf']
+        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'):
+            self.updateOnPopup = kargs['updateOnPopup']
         
         
 class VectorDBInfo:
 class VectorDBInfo:
     """!Class providing information about attribute tables
     """!Class providing information about attribute tables