How to list only directories in Kivy FileChooser? I've read about callback filters, but didn't found any examples.
My Kv code:
<Saveto>:
select: select
chooser: chooser
orientation: 'vertical'
FileChooserIconView:
id: chooser
size_hint_y: 0.9
rootpath: home
dirselect: True
filters: ['How to list folders only?']
Button:
...select button...
Here's an example:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from os.path import join, isdir
Builder.load_string("""
<MyWidget>:
FileChooserListView:
filters: [root.is_dir]
""")
class MyWidget(BoxLayout):
def is_dir(self, directory, filename):
return isdir(join(directory, filename))
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()
Note that the property is called filters
, not filter
, because it's a list, for example, a list of callbacks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With