Kivy - change location FileChooser defaul

Right now, selecting the file opens the very root directory as the default location, but I want it to skip this and open the default internal storage (sdcard), and the user can go down.

this is my debugged code so far Class:

class LoadDialog(FloatLayout): load = ObjectProperty(None) cancel = ObjectProperty(None) 

Definition in kv file

 <LoadDialog>: BoxLayout: size: root.size pos: root.pos orientation: "vertical" FileChooserListView: id: filechooser BoxLayout: size_hint_y: None height: 30 Button: text: "Cancel" on_release: root.cancel() Button: text: "Load" on_release: root.load(filechooser.path, filechooser.selection) 

Actual download code:

 def show_load(self): content = LoadDialog(load=self.load, cancel=self.dismiss_popup) self._popup = Popup(title="Load file", content=content, size_hint=(0.9, 0.9)) self._popup.open() def load(self, path, filename): wimg = os.path.join(path, filename[0]) self.image_source = wimg self.dismiss_popup() 

Thus, basically the user does not need to go up 1 directory to get to the SD card, it should already be. In the worst case scenario, the filter will filter all other folders except those containing the word sdcard.

+5
source share
1 answer

Set the path attribute.

 FileChooserListView: id: filechooser path: "/your/path" 

To find a directory on your system using python, you can do something like this:

 import os for root, dirs, files in os.walk("/"): for name in dirs: if name == "DCIM": print(root, name) 

Just keep in mind that it can find two or more directories named DCIM on your SD card and internal memory.

+6
source

Source: https://habr.com/ru/post/1264824/


All Articles