[GRASS-SVN] r70147 - grass/trunk/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 27 10:01:52 PST 2016


Author: wenzeslaus
Date: 2016-12-27 10:01:52 -0800 (Tue, 27 Dec 2016)
New Revision: 70147

Modified:
   grass/trunk/gui/wxpython/core/treemodel.py
Log:
wxGUI: case-insensitive matching for modules in Modules tab

Modified: grass/trunk/gui/wxpython/core/treemodel.py
===================================================================
--- grass/trunk/gui/wxpython/core/treemodel.py	2016-12-27 17:21:02 UTC (rev 70146)
+++ grass/trunk/gui/wxpython/core/treemodel.py	2016-12-27 18:01:52 UTC (rev 70147)
@@ -200,22 +200,28 @@
     def __init__(self, label, data=None):
         super(ModuleNode, self).__init__(label=label, data=data)
 
-    def match(self, key, value):
+    def match(self, key, value, case_sensitive=False):
         """Method used for searching according to command,
         keywords or description."""
         if not self.data:
             return False
-        if key in ('command', 'keywords', 'description'):
-            try:
-                return len(
-                    self.data[key]) and(
-                    value in self.data[key] or value == '*')
-            except KeyError:
-                return False
+        if key not in ('command', 'keywords', 'description'):
+            return False
+        try:
+            text = self.data[key]
+        except KeyError:
+            return False
+        if not text:
+            return False
+        if case_sensitive:
+            # start supported but unused, so testing last
+            return value in text or value == '*'
+        else:
+            # this works fully only for English and requires accents
+            # to be exact match (even Python 3 casefold() does not help)
+            return value.lower() in text.lower() or value == '*'
 
-        return False
 
-
 def main():
     import doctest
     doctest.testmod()



More information about the grass-commit mailing list