-
Notifications
You must be signed in to change notification settings - Fork 9
/
SelectionList.py
132 lines (86 loc) · 3.78 KB
/
SelectionList.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
import RenderObject, Configuration, AbstractList, ConfigMenu, Footer, ConfirmOverlay
import os, Keys, RenderControl, Common, SelectionMenu, FileChooser
import pygame, sys, ResumeHandler, os, copy
import platform
import json
from operator import itemgetter
class SelectionList(AbstractList.AbstractList):
folderIcon = Common.loadImage( "theme/folder.png")
fileIcon = Common.loadImage( "theme/file.png")
overlay = None
subComponent = None
options = None
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(self.options["options"][self.currentIndex] in self.data):
self.data.remove(self.options["options"][self.currentIndex])
else:
self.data.append(self.options["options"][self.currentIndex])
self.initList()
RenderControl.setDirty()
def onExit(self):
self.callback(None)
def openSelection(self):
pass
def onChange(self):
if(len(self.entryList) == 0):
self.previewPath = None
return
elif (len(self.entryList) - 1 < self.currentIndex):
self.currentIndex = len(self.entryList) - 1
if(len(self.entryList) == 1):
self.currentIndex == 0
self.currentSelection = self.entryList[self.currentIndex]
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:
pass
if event.type == pygame.KEYUP:
if event.key == Keys.DINGOO_BUTTON_START:
self.callback(self.data)
return
if(self.overlay is None):
AbstractList.AbstractList.handleEvents(self, events)
def initList(self):
self.entryList = []
for idx, o in enumerate(self.options["names"]) :
entry = {}
if(self.options["options"][idx] in self.data):
char = "(X)"
else:
char = "( )"
entry["name"] = o
entry["text"] = self.entryFont.render( char + " " + o , True, self.textColor)
self.entryList.append(entry)
self.onChange()
def __init__(self, screen, titel, data, options, callback):
AbstractList.AbstractList.__init__(self, screen, titel, options)
if(data == None):
data = []
self.options = 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()