فهرست منبع

wxGUI: natural sort for map selection and add many maps dialog, https://trac.osgeo.org/grass/ticket/2818 (merge from trunk, https://trac.osgeo.org/grass/changeset/67070)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@67774 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 9 سال پیش
والد
کامیت
e635eacaa8
3فایلهای تغییر یافته به همراه14 افزوده شده و 2 حذف شده
  1. 2 1
      gui/wxpython/gui_core/dialogs.py
  2. 1 1
      gui/wxpython/gui_core/gselect.py
  3. 11 0
      lib/python/script/utils.py

+ 2 - 1
gui/wxpython/gui_core/dialogs.py

@@ -43,6 +43,7 @@ import wx.lib.mixins.listctrl as listmix
 
 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 @@ class MapLayersDialogBase(wx.Dialog):
         :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()):

+ 1 - 1
gui/wxpython/gui_core/gselect.py

@@ -553,7 +553,7 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
         :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

+ 11 - 0
lib/python/script/utils.py

@@ -20,6 +20,7 @@ for details.
 import os
 import shutil
 import locale
+import re
 
 
 def float_or_dms(s):
@@ -241,3 +242,13 @@ def get_num_suffix(number, max_number):
     """
     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)