diff options
author | Aaron Carlisle <carlisle.b3d@gmail.com> | 2021-03-05 07:20:31 +0300 |
---|---|---|
committer | Aaron Carlisle <carlisle.b3d@gmail.com> | 2021-03-05 07:22:47 +0300 |
commit | c2a8676544a6a1b4ef6ee08e8fba470b207cb2ef (patch) | |
tree | 0231748f98bad4a08aa2b4b1495611b8fe85b229 | |
parent | 78bd155f5c05a2f3147fee22d9b4af341b0a259b (diff) |
Presets: Improve sort order of presets
Pythons sort function does not sort naturally,
to solve this a custom sort key is used.
This issue is apparent when trying D10553
-rw-r--r-- | release/scripts/modules/bpy_types.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 5d89763f34b..faac3844c45 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -900,6 +900,7 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): layout = self.layout import os + import re import bpy.utils layout = self.layout @@ -920,7 +921,10 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): (filter_path(f))) ]) - files.sort() + # Python does not have a natural sort function + natural_sort = lambda s: [int(t) if t.isdigit() else t.lower() + for t in re.split('(\d+)', (str)(s))] + files.sort(key=natural_sort) col = layout.column(align=True) |