f p f p - 3 months ago 48
Python Question

Kivy filechooser questions

I'm using filechooser based on the Kivy example demo:

The .kv file:

FileChooserListView:
id: list_view_tab
path: '.'
on_selection: nada = app.loader(list_view_tab.selection)

FileChooserIconView:
id: icon_view_tab
show_hidden: True
on_selection: nada = app.loader(icon_view_tab.selection)

...

TextInput:
size_hint: (None, 1)
id: filtro
text: '*.py'
multiline: False
on_text: list_view_tab.filters = icon_view_tab.filters = text.split(',')


There are no direct references to these widgets in the .py code, and it shows the file system ok both ways.

I have these questions:


  • The filter doesn't work. What have I missed?

  • In the
    FileChooserListView
    there are the column names
    Name
    and
    Size
    . How can I change these for other languages?

  • How can I select files by single click?


Answer

The filter doesn't work. What have I missed?

You set the filter property for both your FileChooserListViews, but this doesn't seem to exist. You should instead set the filters property, which must be a list of strings. This is documented here in the kivy doc.

In the FileChooserListView there are the column names Name and Size. How can I change these for other languages?

I don't think this is exposed in the api, though it probably should be. For now, you probably have to change your kivy source. The relevant lines are in the FileChooserListView rule of kivy/data/style.kv, you can find them here in kivy's github.

How can I select files by single click?

I'm not sure about the best way, but I might look into the selection property of the FileChooserListView. As a kivy property, this will call the method on_selection when the selection changes, so you can put your desired behaviour there.

There may be some fiddliness with exactly how and when the selection changes, but it seems like the right sort of thing.

Comments