py4sci

Table Of Contents

Previous topic

Welcome to FileBrowser’s documentation!

This Page

The FileBrowser API

filebrowser

FileBrowser

The FileBrowser widget is an advanced file browser. You use it similarly to FileChooser usage.

It provides a shortcut bar with links to special and system directories. When touching next to a shortcut in the links bar, it’ll expand and show all the directories within that directory. It also facilitates specifying custom paths to be added to the shortcuts list.

It provides a icon and list view to choose files from. And it also accepts filter and filename inputs.

To create a FileBrowser which prints the currently selected file as well as the current text in the filename field when ‘Select’ is pressed, with a shortcut to the Documents directory added to the favorites bar:

ffrom kivy.app import App
from os.path import sep, expanduser, isdir, dirname

class TestApp(App):

    def build(self):
        if platform == 'win':
            user_path = dirname(expanduser('~')) + sep + 'Documents'
        else:
            user_path = expanduser('~') + sep + 'Documents'
        browser = FileBrowser(select_string='Select',
                              favorites=[(user_path, 'Documents')])
        browser.bind(
                    on_success=self._fbrowser_success,
                    on_canceled=self._fbrowser_canceled)
        return browser

    def _fbrowser_canceled(self, instance):
        print 'cancelled, Close self.'

    def _fbrowser_success(self, instance):
        print instance.selection

TestApp().run()
Events:
on_canceled:

Fired when the Cancel buttons on_release event is called.

on_success:

Fired when the Select buttons on_release event is called.

on_success:

Fired when a file has been selected with a double-tap.

_images/filebrowser.png
class __init__.FileBrowser(**kwargs)

Bases: kivy.uix.boxlayout.BoxLayout

FileBrowser class, see module documentation for more information.

cancel_state

State of the ‘cancel’ button, must be one of ‘normal’ or ‘down’. The state is ‘down’ only when the button is currently touched/clicked, otherwise ‘normal’. This button functions as the typical cancel button.

cancel_state is an OptionProperty.

cancel_string

Label of the ‘cancel’ button.

cancel_string is an StringProperty, defaults to ‘Cancel’.

dirselect

BooleanProperty, defaults to False. Determines whether directories are valid selections or not. See kivy.uix.filechooser.FileChooserController.dirselect.

New in version 1.1.

favorites

A list of the paths added to the favorites link bar. Each element is a tuple where the first element is a string containing the full path to the location, while the second element is a string with the name of path to be displayed.

favorites is an ListProperty, defaults to ‘[]’.

filename

The current text in the filename field. Read only. When multiselect is True, the list of selected filenames is shortened. If shortened, filename will contain an ellipsis.

filename is an StringProperty, defaults to ‘’.

Changed in version 1.1.

filter_dirs

BooleanProperty, defaults to False. Indicates whether filters should also apply to directories. See kivy.uix.filechooser.FileChooserController.filter_dirs.

New in version 1.1.

filters

ListProperty, defaults to [], equal to ‘*’. Specifies the filters to be applied to the files in the directory. See kivy.uix.filechooser.FileChooserController.filters.

Filering keywords that the user types into the filter field as a comma separated list will be reflected here.

New in version 1.1.

multiselect

BooleanProperty, defaults to False. Determines whether the user is able to select multiple files or not. See kivy.uix.filechooser.FileChooserController.multiselect.

New in version 1.1.

path

StringProperty, defaults to the current working directory as a unicode string. It specifies the path on the filesystem that browser should refer to. See kivy.uix.filechooser.FileChooserController.path.

New in version 1.1.

rootpath

Root path to use instead of the system root path. If set, it will not show a ”..” directory to go up to the root path. For example, if you set rootpath to /users/foo, the user will be unable to go to /users or to any other directory not starting with /users/foo. StringProperty, defaults to None. See kivy.uix.filechooser.FileChooserController.rootpath.

New in version 1.1.

select_state

State of the ‘select’ button, must be one of ‘normal’ or ‘down’. The state is ‘down’ only when the button is currently touched/clicked, otherwise ‘normal’. This button functions as the typical Ok/Select/Save button.

select_state is an OptionProperty.

select_string

Label of the ‘select’ button.

select_string is an StringProperty, defaults to ‘Ok’.

selection

Read-only ListProperty. Contains the list of files that are currently selected in the current tab. See kivy.uix.filechooser.FileChooserController.selection.

Changed in version 1.1.

show_hidden

BooleanProperty, defaults to False. Determines whether hidden files and folders should be shown. See kivy.uix.filechooser.FileChooserController.show_hidden.

New in version 1.1.