[Bf-blender-cvs] [c2a8676544a] master: Presets: Improve sort order of presets
Aaron Carlisle
noreply at git.blender.org
Fri Mar 5 05:36:45 CET 2021
Commit: c2a8676544a6a1b4ef6ee08e8fba470b207cb2ef
Author: Aaron Carlisle
Date: Thu Mar 4 23:20:31 2021 -0500
Branches: master
https://developer.blender.org/rBc2a8676544a6a1b4ef6ee08e8fba470b207cb2ef
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
===================================================================
M release/scripts/modules/bpy_types.py
===================================================================
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)
More information about the Bf-blender-cvs
mailing list