Skip to content

Commit 8dfb35b

Browse files
author
terrorgun
committed
bug fixed
1 parent a6091cc commit 8dfb35b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

PyInterpreter/FileBrowser.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from Utility import *
33

44
from Constants import *
5+
import traceback
56

67
global gFileBrowser
78

@@ -34,7 +35,7 @@ def __init__(self, ui):
3435
global gFileBrowser
3536
gFileBrowser = self
3637
self.ui = ui
37-
self.lastDir = os.path.abspath(".")
38+
self.lastDir = os.path.abspath("/")
3839
self.mode = ""
3940
# filename input layout
4041
self.filenameLayout = BoxLayout(orientation = "horizontal", size_hint=(1, None))
@@ -68,17 +69,23 @@ def func_ok(inst):
6869
self.popup = Popup(title = "File Browser", content=self.browserLayout, auto_dismiss=False, size_hint=(1, 0.8))
6970

7071
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
7280
self.curDir.text = self.lastDir
7381
self.fileLayout.clear_widgets()
74-
lastDir, dirList, fileList = os.walk(self.lastDir).next()
7582
fileList = sorted(fileList, key=lambda x:x.lower())
7683
dirList = sorted(dirList, key=lambda x:x.lower())
7784
fileList = dirList + fileList
7885
fileList.insert(0, "..")
7986
labelHeight = kivy.metrics.dp(25)
8087
for filename in fileList:
81-
absFilename = os.path.join(lastDir, filename)
88+
absFilename = os.path.join(self.lastDir, filename)
8289
label = TouchableLabel(text=filename, font_size="15dp", size_hint_y = None, size=(W*0.9, labelHeight), shorten=True, shorten_from="right", halign="left")
8390
label.text_size = label.size
8491
label.setType(os.path.isdir(absFilename))

0 commit comments

Comments
 (0)