diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-05 09:04:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-05 09:10:11 +0300 |
commit | 663b0bb04c324659f24e6b408ee4437cb3d5148b (patch) | |
tree | e195e7b116d7637555bd03cbb04cea5e91933699 | |
parent | 511ff8b6b4fb59b175483d1776881bcced3e65c6 (diff) |
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.
-rw-r--r-- | release/scripts/modules/bpy_types.py | 9 |
1 files changed, 5 insertions, 4 deletions
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) |