python kivy bind

Solutions on MaxInterview for python kivy bind by the best coders in the world

showing results for - "python kivy bind"
Dolores
12 May 2019
1from kivy.core.window import Window
2from kivy.lang import Builder
3
4from kivymd.app import MDApp
5from kivymd.uix.filemanager import MDFileManager
6from kivymd.toast import toast
7
8
9KV = '''
10MDBoxLayout:
11    orientation: 'vertical'
12
13    MDToolbar:
14        title: "MDFileManager"
15        left_action_items: [['menu', lambda x: None]]
16        elevation: 10
17
18    MDFloatLayout:
19
20        MDRoundFlatIconButton:
21            text: "Open manager"
22            icon: "folder"
23            pos_hint: {'center_x': .5, 'center_y': .6}
24            on_release: app.file_manager_open()
25'''
26
27
28class Example(MDApp):
29    def __init__(self, **kwargs):
30        super().__init__(**kwargs)
31        Window.bind(on_keyboard=self.events)
32        self.manager_open = False
33        self.file_manager = MDFileManager(
34            exit_manager=self.exit_manager,
35            select_path=self.select_path,
36            preview=True,
37        )
38
39    def build(self):
40        return Builder.load_string(KV)
41
42    def file_manager_open(self):
43        self.file_manager.show('/')  # output manager to the screen
44        self.manager_open = True
45
46    def select_path(self, path):
47        '''It will be called when you click on the file name
48        or the catalog selection button.
49
50        :type path: str;
51        :param path: path to the selected directory or file;
52        '''
53
54        self.exit_manager()
55        toast(path)
56
57    def exit_manager(self, *args):
58        '''Called when the user reaches the root of the directory tree.'''
59
60        self.manager_open = False
61        self.file_manager.close()
62
63    def events(self, instance, keyboard, keycode, text, modifiers):
64        '''Called when buttons are pressed on the mobile device.'''
65
66        if keyboard in (1001, 27):
67            if self.manager_open:
68                self.file_manager.back()
69        return True
70
71
72Example().run()
73