[GRASS-SVN] r67774 - in grass/branches/releasebranch_7_0: gui/wxpython/gui_core lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 7 14:12:59 PST 2016
Author: annakrat
Date: 2016-02-07 14:12:59 -0800 (Sun, 07 Feb 2016)
New Revision: 67774
Modified:
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
grass/branches/releasebranch_7_0/lib/python/script/utils.py
Log:
wxGUI: natural sort for map selection and add many maps dialog, #2818 (merge from trunk, r67070)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py 2016-02-07 21:58:37 UTC (rev 67773)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py 2016-02-07 22:12:59 UTC (rev 67774)
@@ -43,6 +43,7 @@
from grass.script import core as grass
from grass.script import task as gtask
+from grass.script.utils import natural_sort
from grass.pydispatch.signal import Signal
@@ -1414,7 +1415,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/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2016-02-07 21:58:37 UTC (rev 67773)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2016-02-07 22:12:59 UTC (rev 67774)
@@ -553,7 +553,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/branches/releasebranch_7_0/lib/python/script/utils.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/utils.py 2016-02-07 21:58:37 UTC (rev 67773)
+++ grass/branches/releasebranch_7_0/lib/python/script/utils.py 2016-02-07 22:12:59 UTC (rev 67774)
@@ -20,6 +20,7 @@
import os
import shutil
import locale
+import re
def float_or_dms(s):
@@ -241,3 +242,13 @@
"""
return '{number:0{width}d}'.format(width=len(str(max_number)),
number=number)
+
+# 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