-
Notifications
You must be signed in to change notification settings - Fork 0
/
Folder.py
66 lines (54 loc) · 2.17 KB
/
Folder.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
from Key import Key
class Folder:
maxkey = -1
name = ""
keys = []
next_dir = None
prev_dir = None
selected_key = -1
def __init__(self, name, maxkey):
self.maxkey = maxkey
self.name = name
self.keys = [None] * maxkey
self.keys[maxkey-1] = Key(None, "Back", "back.png", None)
self.keys[maxkey-1].is_back_button = True
#todo back button
def set_key(self, keynr, text, icon, callback):
if issubclass(type(callback), Folder):
callback.prev_dir = self
self.keys[keynr] = Key(keynr, text, icon, callback)
def key_pressed_callback(self, keynr):
if self.next_dir != None:
self.next_dir.key_pressed_callback(keynr)
return
if self.keys[keynr] != None and self.keys[keynr].is_back_button:
self.prev_dir.next_dir = None
elif self.keys[keynr] == None or self.keys[keynr].callback == None:
print("button " + str(keynr) + " in folder " + str(self.name) + " does not work")
elif issubclass(type(self.keys[keynr].callback), Folder):
self.next_dir = self.keys[keynr].callback
self.next_dir.on_open()
else:
self.keys[keynr].callback()
def current_dir(self):
if self.next_dir:
self.next_dir.current_dir()
elif self.next_dir == None:
print(self.name)
def show_dir(self, depth = 0):
indent = '\t' * depth
for i in range(self.maxkey):
if self.keys[i] != None:
print(indent + str(i) + ": " + self.keys[i].text)
if issubclass(type(self.keys[i].callback), Folder):
self.keys[i].callback.show_dir(depth+1)
def get_keys(self):
if self.next_dir != None:
return self.next_dir.get_keys() #recursion
res = {}
for i in range(self.maxkey):
if self.keys[i] != None:
res[i] = [self.keys[i].icon, self.keys[i].text]
return res
def on_open(self):
pass # override, for updating content when opened