|
2 | 2 | from Utility import *
|
3 | 3 |
|
4 | 4 | from Constants import *
|
| 5 | +import traceback |
5 | 6 |
|
6 | 7 | global gFileBrowser
|
7 | 8 |
|
@@ -34,7 +35,7 @@ def __init__(self, ui):
|
34 | 35 | global gFileBrowser
|
35 | 36 | gFileBrowser = self
|
36 | 37 | self.ui = ui
|
37 |
| - self.lastDir = os.path.abspath(".") |
| 38 | + self.lastDir = os.path.abspath("/") |
38 | 39 | self.mode = ""
|
39 | 40 | # filename input layout
|
40 | 41 | self.filenameLayout = BoxLayout(orientation = "horizontal", size_hint=(1, None))
|
@@ -68,17 +69,23 @@ def func_ok(inst):
|
68 | 69 | self.popup = Popup(title = "File Browser", content=self.browserLayout, auto_dismiss=False, size_hint=(1, 0.8))
|
69 | 70 |
|
70 | 71 | def open_directory(self, lastDir):
|
71 |
| - self.lastDir = os.path.abspath(lastDir) |
| 72 | + absPath = os.path.abspath(lastDir) |
| 73 | + try: |
| 74 | + lastDir, dirList, fileList = os.walk(absPath).next() |
| 75 | + except: |
| 76 | + log(traceback.format_exc()) |
| 77 | + toast("Cannot open directory") |
| 78 | + return False |
| 79 | + self.lastDir = absPath |
72 | 80 | self.curDir.text = self.lastDir
|
73 | 81 | self.fileLayout.clear_widgets()
|
74 |
| - lastDir, dirList, fileList = os.walk(self.lastDir).next() |
75 | 82 | fileList = sorted(fileList, key=lambda x:x.lower())
|
76 | 83 | dirList = sorted(dirList, key=lambda x:x.lower())
|
77 | 84 | fileList = dirList + fileList
|
78 | 85 | fileList.insert(0, "..")
|
79 | 86 | labelHeight = kivy.metrics.dp(25)
|
80 | 87 | for filename in fileList:
|
81 |
| - absFilename = os.path.join(lastDir, filename) |
| 88 | + absFilename = os.path.join(self.lastDir, filename) |
82 | 89 | label = TouchableLabel(text=filename, font_size="15dp", size_hint_y = None, size=(W*0.9, labelHeight), shorten=True, shorten_from="right", halign="left")
|
83 | 90 | label.text_size = label.size
|
84 | 91 | label.setType(os.path.isdir(absFilename))
|
|
0 commit comments