forked from JackD83/PyMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNativeAppList.py
229 lines (166 loc) · 8.96 KB
/
NativeAppList.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import RenderObject, Configuration, AbstractList, ConfigMenu, Footer, ConfirmOverlay
import os, Keys, RenderControl, Common, SelectionMenu, FileChooser
import pygame, sys, ResumeHandler, os
import platform
import json
from operator import itemgetter
class NativeAppList(AbstractList.AbstractList):
folderIcon = Common.loadImage( "theme/folder.png")
fileIcon = Common.loadImage( "theme/file.png")
overlay = None
subComponent = None
configOptions = json.load(open('config/optionsNative.json'))
previewCache = {}
currentSelection = None
def render(self, screen):
if(self.subComponent != None):
self.subComponent.render(screen)
return
else:
AbstractList.AbstractList.render(self, screen)
if(self.overlay != None):
self.overlay.render(screen)
def renderEntry(self, screen, index, xOffset, yOffset):
text = self.entryList[index]["text"]
yTextOffset = (self.listEntryHeight - text.get_height()) / 2
screen.blit(text, (4 + xOffset, yOffset + yTextOffset + 1))
def onSelect(self):
if(len(self.entryList) > 0):
if("selector" in self.entryList[self.currentIndex]["options"] and self.entryList[self.currentIndex]["options"]["selector"]):
self.openSelection()
else:
ResumeHandler.setLastSelectedLine(self.currentIndex)
self.callback(self.entryList[self.currentIndex]["options"])
def onExit(self):
self.callback(None)
def openSelection(self):
options = {}
options["textColor"] = (55,55,55)
options["background"] = self.options["background"]
options["useSidebar"] = False
if("selectDescription" in self.entryList[self.currentIndex]["options"]):
options["description"] = self.entryList[self.currentIndex]["options"]["selectDescription"]
if("folderIcon" in self.options):
options["folderIcon"] = self.options["folderIcon"]
if("fileFilter" in self.entryList[self.currentIndex]["options"]):
options["fileFilter"] = self.entryList[self.currentIndex]["options"]["fileFilter"]
if("selectionPath" in self.entryList[self.currentIndex]["options"]):
selectionPath = self.entryList[self.currentIndex]["options"]["selectionPath"]
else:
selectionPath = "/"
self.subComponent = FileChooser.FileChooser(self.screen,self.entryList[self.currentIndex]["options"]["name"], selectionPath, False, options, self.selectionCallback)
footer = Footer.Footer([("theme/direction.png","select")], [("theme/b_button.png", "back"), ("theme/a_button.png", "select")], (255,255,255))
self.subComponent.setFooter(footer)
def selectionCallback(self, selection):
self.subComponent = None
if(selection is not None):
self.entryList[self.currentIndex]["options"]["selection"] = selection
ResumeHandler.setLastSelectedLine(self.currentIndex)
self.callback(self.entryList[self.currentIndex]["options"])
def onChange(self):
if(len(self.entryList) == 0):
self.previewPath = None
return
if(len(self.entryList) - 1 < self.currentIndex):
self.currentIndex = len(self.entryList) - 1
self.currentSelection = self.entryList[self.currentIndex]["options"]
if(os.path.isfile(self.currentSelection["preview"])):
self.previewPath = self.currentSelection["preview"]
else:
self.previewPath = None
if("description" in self.currentSelection):
self.entryDescription = self.currentSelection["description"]
else:
self.entryDescription = None
def handleEvents(self, events):
if(self.subComponent != None):
self.subComponent.handleEvents(events)
return
if(self.overlay != None):
self.overlay.handleEvents(events)
return
for event in events:
if event.type == pygame.KEYDOWN:
if event.key == Keys.DINGOO_BUTTON_SELECT:
if("allowEdit" in self.config["options"] and self.config["options"]["allowEdit"] ):
if(len(self.options) == 0):
self.overlay = SelectionMenu.SelectionMenu(self.screen, ["add"], self.optionsCallback)
else:
self.overlay = SelectionMenu.SelectionMenu(self.screen, ["add", "edit", "remove"], self.optionsCallback)
RenderControl.setDirty()
if(self.overlay is None):
AbstractList.AbstractList.handleEvents(self, events)
def initList(self):
self.entryList = []
for o in self.data:
entry = {}
entry["options"] = o
entry["name"] = o["name"]
entry["text"] = self.entryFont.render( entry["name"] , True, self.textColor)
self.entryList.append(entry)
self.onChange()
def optionsCallback(self, selection, text):
self.overlay = None
if(not Configuration.isRS97()):
self.configOptions = self.configOptions + json.load(open('config/legacy.json'))
if(selection == 0):
self.subComponent = ConfigMenu.ConfigMenu(self.screen, "Add new link",{"textColor":(55,55,55), "backgroundColor":(221,221,221), "useSidebar":True}, \
self.getEmptyData() ,self.configOptions ,self.addEditCallback)
footer = Footer.Footer([("theme/direction.png","select")], [("theme/b_button.png", "back"), ("theme/a_button.png", "change"), ("theme/start_button.png", "save")], (255,255,255))
self.subComponent.setFooter(footer)
self.subComponent.setConfigCallback(self.configCallback)
if(selection == 1):
self.subComponent = ConfigMenu.ConfigMenu(self.screen, "Edit link",{"textColor":(55,55,55), "backgroundColor":(221,221,221)}, \
self.currentSelection ,self.configOptions ,self.addEditCallback)
footer = Footer.Footer([("theme/direction.png","select")], [("theme/b_button.png", "back"), ("theme/a_button.png", "change"), ("theme/start_button.png", "save")], (255,255,255))
self.subComponent.setFooter(footer)
self.subComponent.setConfigCallback(self.configCallback)
if(selection == 2):
self.overlay = ConfirmOverlay.ConfirmOverlay("really delete?", (255,255,255), [("theme/b_button.png", "back"), ("theme/a_button.png", "delete")], self.deleteCallback)
RenderControl.setDirty()
def deleteCallback(self, res):
self.overlay = None
if(res == 1):
self.data.remove(self.currentSelection)
Configuration.saveConfiguration()
self.initList()
self.setSelection(self.currentIndex - 1)
def addEditCallback(self, configCallback):
if(configCallback != None and not configCallback in self.data):
self.data.append(configCallback)
Configuration.saveConfiguration()
self.subComponent = None
self.initList()
self.setSelection(self.currentIndex)
def configCallback(self, config):
if(config["name"] == None and ( config["cmd"] != None or config["cmd"] == "None" ) ):
name = os.path.basename(config["cmd"])
name = os.path.splitext(name)[0]
config["name"] = name
def getEmptyData(self):
emptyEntry = {
"name": None,
"cmd":".",
"icon":".",
"preview":".",
"legacy":False,
"screen":"default",
"overclock":"528"
}
return emptyEntry
def __init__(self, screen, titel, data, options, callback):
AbstractList.AbstractList.__init__(self, screen, titel, options)
self.callback = callback
self.data = data
self.yFolderOffset = (self.listEntryHeight - self.folderIcon.get_height()) / 2
self.xFolderOffset = (self.listEntryHeight - self.folderIcon.get_width()) / 2
self.yFileOffset = (self.listEntryHeight - self.fileIcon.get_height()) / 2
self.xFileOffset = (self.listEntryHeight - self.fileIcon.get_width()) / 2
self.initList()
res = ResumeHandler.getResumeFile()
if(res != None and res["line"] != None):
self.setSelection(res["line"])
self.onChange()
self.previewPath = self.currentSelection["preview"]
self.preview_final = self.previewPath
RenderControl.setDirty()