[Bf-blender-cvs] [663b0bb04c3] master: UI: minor changes to preset sorting

Campbell Barton noreply at git.blender.org
Fri Mar 5 07:10:44 CET 2021


Commit: 663b0bb04c324659f24e6b408ee4437cb3d5148b
Author: Campbell Barton
Date:   Fri Mar 5 17:04:19 2021 +1100
Branches: master
https://developer.blender.org/rB663b0bb04c324659f24e6b408ee4437cb3d5148b

UI: minor changes to preset sorting

- Only sort by the preset name (not it's directory).
- Remove redundant string conversion.
- Only call lower() once on the input.
- Don't assign the lambda to a variable for single use.

===================================================================

M	release/scripts/modules/bpy_types.py

===================================================================

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index faac3844c45..e90739debf8 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -921,10 +921,11 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
                     (filter_path(f)))
             ])
 
-        # 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)
+        # Perform a "natural sort", so 20 comes after 3 (for example).
+        files.sort(
+            key=lambda file_path:
+            tuple(int(t) if t.isdigit() else t for t in re.split("(\d+)", file_path[0].lower())),
+        )
 
         col = layout.column(align=True)



More information about the Bf-blender-cvs mailing list