Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python kivy bind

from kivy.core.window import Window
from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.filemanager import MDFileManager
from kivymd.toast import toast


KV = '''
MDBoxLayout:
    orientation: 'vertical'

    MDToolbar:
        title: "MDFileManager"
        left_action_items: [['menu', lambda x: None]]
        elevation: 10

    MDFloatLayout:

        MDRoundFlatIconButton:
            text: "Open manager"
            icon: "folder"
            pos_hint: {'center_x': .5, 'center_y': .6}
            on_release: app.file_manager_open()
'''


class Example(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        Window.bind(on_keyboard=self.events)
        self.manager_open = False
        self.file_manager = MDFileManager(
            exit_manager=self.exit_manager,
            select_path=self.select_path,
            preview=True,
        )

    def build(self):
        return Builder.load_string(KV)

    def file_manager_open(self):
        self.file_manager.show('/')  # output manager to the screen
        self.manager_open = True

    def select_path(self, path):
        '''It will be called when you click on the file name
        or the catalog selection button.

        :type path: str;
        :param path: path to the selected directory or file;
        '''

        self.exit_manager()
        toast(path)

    def exit_manager(self, *args):
        '''Called when the user reaches the root of the directory tree.'''

        self.manager_open = False
        self.file_manager.close()

    def events(self, instance, keyboard, keycode, text, modifiers):
        '''Called when buttons are pressed on the mobile device.'''

        if keyboard in (1001, 27):
            if self.manager_open:
                self.file_manager.back()
        return True


Example().run()
Comment

PREVIOUS NEXT
Code Example
Python :: how to concatenate two strings in python 
Python :: read variable in a string python 
Python :: find item in list 
Python :: How to make a function repeat itself a specifc amount of times python 
Python :: ssl socket python 
Python :: automl classification tutorial sklearn 
Python :: Convert Int to String Using format() method 
Python :: assign multiple columns pandas 
Python :: task.loop discord.py 
Python :: python conditionals 
Python :: django change foreign key 
Python :: index start from 1 pandas 
Python :: how to refer to all columns in pandas 
Python :: image hashing 
Python :: from html to jupyter notebook 
Python :: Python enumerate Using enumerate() 
Python :: how to print python exception message 
Python :: optional parameter in python 
Python :: append and extend in python 
Python :: python sort list opposite 
Python :: Syntax of Opening a File in python 
Python :: remove emoji 
Python :: Python Program to Sort Words in Alphabetic Order 
Python :: python hash timestamp 
Python :: how to check if all values in list are equal python 
Python :: python Using for loop and list comprehension 
Python :: one-hot encode categorical variables standardize numerical variables 
Python :: division of 2 numbers in python 
Python :: argparse type 
Python :: get_queryset django rest framework 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =