forked from Devil084/symdroid
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilebrowser.py
83 lines (74 loc) · 2.68 KB
/
filebrowser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import appuifw
import e32
import dir_iter
class Filebrowser:
def __init__(self):
self.script_lock = e32.Ao_lock()
self.dir_stack = []
self.current_dir = dir_iter.Directory_iter(e32.drive_list())
def run(self):
from key_codes import EKeyLeftArrow
entries = self.current_dir.list_repr()
if not self.current_dir.at_root:
entries.insert(0, (u"..", u""))
self.lb = appuifw.Listbox(entries, self.lbox_observe)
self.lb.bind(EKeyLeftArrow, lambda: self.lbox_observe(0))
old_title = appuifw.app.title
self.refresh()
self.script_lock.wait()
appuifw.app.title = old_title
appuifw.app.body = None
self.lb = None
def refresh(self):
appuifw.app.title = u"File browser"
appuifw.app.menu = []
appuifw.app.exit_key_handler = self.exit_key_handler
appuifw.app.body = self.lb
def do_exit(self):
self.exit_key_handler()
def exit_key_handler(self):
appuifw.app.exit_key_handler = None
self.script_lock.signal()
def lbox_observe(self, ind = None):
if not ind == None:
index = ind
else:
index = self.lb.current()
focused_item = 0
if self.current_dir.at_root:
self.dir_stack.append(index)
self.current_dir.add(index)
elif index == 0:
focused_item = self.dir_stack.pop()
self.current_dir.pop()
elif os.path.isdir(self.current_dir.entry(index-1)):
self.dir_stack.append(index)
self.current_dir.add(index-1)
else:
item = self.current_dir.entry(index-1)
if os.path.splitext(item)[1] == '.py':
i = appuifw.popup_menu([u"execfile()", u"Delete"])
else:
i = appuifw.popup_menu([u"Open", u"Delete"])
if i == 0:
if os.path.splitext(item)[1].lower() == u'.py':
execfile(item, globals())
self.refresh()
else:
try:
appuifw.Content_handler().open(item)
except:
import sys
type, value = sys.exc_info() [:2]
appuifw.note(unicode(str(type)+'\n'+str(value)), "info")
return
elif i == 1:
os.remove(item)
focused_item = index - 1
entries = self.current_dir.list_repr()
if not self.current_dir.at_root:
entries.insert(0, (u"..", u""))
self.lb.set_list(entries, focused_item)
if __name__ == '__main__':
Filebrowser().run()