[GRASS-SVN] r67070 - in grass/trunk: gui/wxpython/gui_core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 11 19:58:40 PST 2015


Author: annakrat
Date: 2015-12-11 19:58:40 -0800 (Fri, 11 Dec 2015)
New Revision: 67070

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/gui_core/gselect.py
   grass/trunk/lib/python/script/utils.py
Log:
wxGUI: natural sort for map selection and add many maps dialog, #2818

Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2015-12-12 03:08:28 UTC (rev 67069)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2015-12-12 03:58:40 UTC (rev 67070)
@@ -33,6 +33,7 @@
 import wx
 
 from grass.script import core as grass
+from grass.script.utils import natural_sort
 
 from grass.pydispatch.signal import Signal
 
@@ -1403,7 +1404,7 @@
         :param str mapset: mapset name
         """
         self.map_layers = grass.list_grouped(type = type)[mapset]
-        self.layers.Set(self.map_layers)
+        self.layers.Set(natural_sort(self.map_layers))
         
         # check all items by default
         for item in range(self.layers.GetCount()):

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2015-12-12 03:08:28 UTC (rev 67069)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2015-12-12 03:58:40 UTC (rev 67070)
@@ -556,7 +556,7 @@
         :param exclude: True to exclude, False for forcing the list
         :param node: parent node
         """
-        elist.sort()
+        elist = grass.natural_sort(elist)
         for elem in elist:
             if elem != '':
                 fullqElem = elem + '@' + mapset

Modified: grass/trunk/lib/python/script/utils.py
===================================================================
--- grass/trunk/lib/python/script/utils.py	2015-12-12 03:08:28 UTC (rev 67069)
+++ grass/trunk/lib/python/script/utils.py	2015-12-12 03:58:40 UTC (rev 67070)
@@ -22,6 +22,7 @@
 import shutil
 import locale
 import shlex
+import re
 
 def float_or_dms(s):
     """Convert DMS to float.
@@ -251,3 +252,14 @@
         return shlex.split(s.replace('\\', r'\\'))
     else:
         return shlex.split(s)
+
+
+# source:
+#    http://stackoverflow.com/questions/4836710/
+#    does-python-have-a-built-in-function-for-string-natural-sort/4836734#4836734
+def natural_sort(l):
+    """Returns sorted strings using natural sort
+    """
+    convert = lambda text: int(text) if text.isdigit() else text.lower()
+    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
+    return sorted(l, key=alphanum_key)



More information about the grass-commit mailing list