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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 26 07:16:46 EST 2010


Author: martinl
Date: 2010-12-26 04:16:45 -0800 (Sun, 26 Dec 2010)
New Revision: 44726

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
Log:
wxGUI/GSelect: filtering items in progress, see #1251
patch by Anna Kratochvilova
(merge r44725 from trunk)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2010-12-26 12:13:52 UTC (rev 44725)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2010-12-26 12:16:45 UTC (rev 44726)
@@ -186,6 +186,7 @@
         self.filterElements = filter
         
     def _startsWith(self, text):
+        """!Filter items - currently unused"""
         return True if text.startswith(self.GetCombo().GetValue()) else False
     
     def OnPopup(self, force = False):
@@ -197,14 +198,22 @@
         else:
             selected = None
             exclude  = False
-        
-        text = self.GetCombo().GetValue().strip()
-        if grass.find_file(name = text, element = self.type)['fullname']:
-            self.SetFilter(None)
-        else:
-            self.SetFilter(self._startsWith)   
+ 
         self.GetElementList(selected, exclude)
         
+        # selects map starting according to written text
+        inputText = self.GetCombo().GetValue().strip()
+        if inputText:
+            root = self.seltree.GetRootItem()
+            match = self.FindItem(root, inputText, startLetters = True)
+            if wx.TreeItemId.IsOk(self.seltree.GetPrevSibling(match)):
+                match = self.seltree.GetPrevSibling(match)
+            else: 
+                match = self.seltree.GetItemParent(match)
+            self.seltree.EnsureVisible(match)
+            self.seltree.SelectItem(match)
+            
+      
     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
@@ -371,17 +380,22 @@
             self.seltree.SelectItem(first_dir)
     
     # helpers
-    def FindItem(self, parentItem, text):
+    def FindItem(self, parentItem, text, startLetters = False):
+        """!Finds item with given name or starting with given text"""
+        startletters = startLetters
         item, cookie = self.seltree.GetFirstChild(parentItem)
-        while item:
+        while wx.TreeItemId.IsOk(item):
             if self.seltree.GetItemText(item) == text:
                 return item
             if self.seltree.ItemHasChildren(item):
-                item = self.FindItem(item, text)
+                item = self.FindItem(item, text, startLetters = startletters)
+                if wx.TreeItemId.IsOk(item):
+                    return item
+            elif startletters and self.seltree.GetItemText(item).startswith(text.split('@')[0]):
+                return item
             item, cookie = self.seltree.GetNextChild(parentItem, cookie)
         return wx.TreeItemId()
-
-
+    
     def AddItem(self, value, parent=None):
         if not parent:
             root = self.seltree.GetRootItem()
@@ -411,6 +425,21 @@
                     if item == self.seltree.GetFirstChild(self.seltree.GetRootItem())[0]:
                         itemPrev = item
             self.seltree.SelectItem(itemPrev)
+        
+        # selects first item starting with the written text in next mapset
+        elif event.GetKeyCode() == wx.WXK_TAB:
+            selected = self.seltree.GetSelection()
+            if self.seltree.ItemHasChildren(selected):
+                parent = selected
+            else:
+                parent = self.seltree.GetItemParent(selected)
+            nextSibling = self.seltree.GetNextSibling(parent)
+            if wx.TreeItemId.IsOk(nextSibling):
+                match = self.FindItem(nextSibling, self.GetCombo().GetValue().strip(), True) 
+            else: 
+                match = self.FindItem(self.seltree.GetFirstChild(self.seltree.GetItemParent(parent))[0],
+                                        self.GetCombo().GetValue().strip(), True) 
+            self.seltree.SelectItem(match)
             
         elif event.GetKeyCode() == wx.WXK_RIGHT:
             if self.seltree.ItemHasChildren(item):



More information about the grass-commit mailing list