Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy FileChooser: List directories only

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...
like image 611
Cyber Tailor Avatar asked Dec 10 '15 09:12

Cyber Tailor


1 Answers

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.

like image 100
Nykakin Avatar answered Sep 27 '22 23:09

Nykakin