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.
This commit is contained in:
Campbell Barton 2021-03-05 17:04:19 +11:00
parent 511ff8b6b4
commit 663b0bb04c
1 changed files with 5 additions and 4 deletions

View File

@ -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)