10

Right now the file chooser opens the very root as the default location but i want it to skip that and open as default the internal storage (sdcard) and the user can go down from there.

this is a snipped of my code so far The class:

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

The definition in the 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)

The actual load 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()

So basically the user should not have to go up 1 directory to get to the sdcard, should already be there. Worst case scenario is filtering all the other folders there except the ones that contain the word sdcard.

Nick
  • 545
  • 12
  • 31
  • Paths to sd cards nowadays do not contain the word sdcard. And sd card is not internal storage. – greenapps Feb 28 '17 at 10:56
  • well from what i saw, in android 4 at least the internal storage is sdcard which is a symblink. The location I need is basically the parent of the DCIM folder – Nick Feb 28 '17 at 12:58
  • That will be getExternalStorageDirectory() then. – greenapps Mar 01 '17 at 09:17

1 Answers1

12

Set the path attribute.

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

To find a directory on your system with 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 be aware that it might find two or more directories named DCIM, on your sdcard and internal storage.

el3ien
  • 5,362
  • 1
  • 17
  • 33