You want a natural ordering. To do this, you need to replace the function that orders the files using the sort_func
property of the class kivy.uix.filechooser.FileChooserController
.
An example based on the algorithm shown by @Darius Bacon in his answer to Natural Sorting algorithm:
main.py:
import re
from kivy.app import App
from kivy.properties import ObjectProperty
def natural_key(path):
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', path)]
def natural_sort(files, filesystem):
return (sorted((f for f in files if filesystem.is_dir(f)), key = natural_key) +
sorted((f for f in files if not filesystem.is_dir(f))))
class RootWidget(FloatLayout):
sort_func = ObjectProperty(natural_sort)
class MainApp(App):
def build(self):
return RootWidget()
if __name__ == '__main__':
MainApp().run()
main.kv:
<RootWidget>:
TabbedPanel:
do_default_tab: False
TabbedPanelItem:
text: 'List View'
BoxLayout:
orientation: 'vertical'
FileChooserListView:
sort_func: root.sort_func
TabbedPanelItem:
text: 'Icon View'
BoxLayout:
orientation: 'vertical'
FileChooserIconView:
sort_func: root.sort_func
Some screenshots as an example:

