/
PowerTimerList.py
220 lines (190 loc) · 8.1 KB
/
PowerTimerList.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
from enigma import eListboxPythonMultiContent, eListbox, gFont, \
RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_BOTTOM
from Components.GUIComponent import GUIComponent
from skin import parseFont, parseScale
from Tools.FuzzyDate import FuzzyTime
from Tools.LoadPixmap import LoadPixmap
from timer import TimerEntry
from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
from PowerTimer import AFTEREVENT, TIMERTYPE
class PowerTimerList(GUIComponent):
#
# | <Service> <Name of the Timer> |
# | <start, end> <state> |
#
def buildTimerEntry(self, timer, processed):
timertype = {
TIMERTYPE.WAKEUP: _("Wake Up"),
TIMERTYPE.WAKEUPTOSTANDBY: _("Wake Up To Standby"),
TIMERTYPE.STANDBY: _("Standby"),
TIMERTYPE.AUTOSTANDBY: _("Auto Standby"),
TIMERTYPE.AUTODEEPSTANDBY: _("Auto Deep Standby"),
TIMERTYPE.DEEPSTANDBY: _("Deep Standby"),
TIMERTYPE.REBOOT: _("Reboot"),
TIMERTYPE.RESTART: _("Restart GUI")
}[timer.timerType]
afterevent = {
AFTEREVENT.NONE: _("Nothing"),
AFTEREVENT.WAKEUPTOSTANDBY: _("Wake Up To Standby"),
AFTEREVENT.STANDBY: _("Standby"),
AFTEREVENT.DEEPSTANDBY: _("Deep Standby")
}[timer.afterEvent]
height = self.l.getItemSize().height()
width = self.l.getItemSize().width()
res = [None]
x = width / 2
res.append((eListboxPythonMultiContent.TYPE_TEXT, self.iconWidth + self.iconMargin, 2, width, self.rowSplit, 0, RT_HALIGN_LEFT | RT_VALIGN_BOTTOM, timertype))
if timer.timerType == TIMERTYPE.AUTOSTANDBY or timer.timerType == TIMERTYPE.AUTODEEPSTANDBY:
if self.iconRepeat and timer.autosleeprepeat != "once":
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, self.iconMargin / 2, self.rowSplit + (self.itemHeight - self.rowSplit - self.iconHeight) / 2, self.iconWidth, self.iconHeight, self.iconRepeat))
icon = None
if not processed:
if timer.state == TimerEntry.StateWaiting:
state = _("waiting")
icon = self.iconWait
elif timer.state == TimerEntry.StatePrepared or timer.state == TimerEntry.StateRunning:
state = _("running...")
icon = self.iconZapped
elif timer.state == TimerEntry.StateEnded:
state = _("done!")
icon = self.iconDone
else:
state = _("<unknown>")
icon = None
else:
state = _("done!")
icon = self.iconDone
res.append((eListboxPythonMultiContent.TYPE_TEXT, 148, 26, width - 150, self.itemHeight - self.rowSplit, 2, RT_HALIGN_RIGHT | RT_VALIGN_BOTTOM, _("Delay:") + " " + str(timer.autosleepdelay) + "(" + _("mins") + ")"))
else:
res.append((eListboxPythonMultiContent.TYPE_TEXT, x + 24, 2, x - 2 - 24, self.itemHeight - self.rowSplit, 2, RT_HALIGN_RIGHT | RT_VALIGN_BOTTOM, _('At End:') + ' ' + afterevent))
days = (_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun"))
begin = FuzzyTime(timer.begin)
if timer.repeated:
repeatedtext = []
flags = timer.repeated
for x in (0, 1, 2, 3, 4, 5, 6):
if flags & 1 == 1:
repeatedtext.append(days[x])
flags >>= 1
if repeatedtext == [_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")]:
repeatedtext = _('Everyday')
elif repeatedtext == [_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri")]:
repeatedtext = _('Weekday')
elif repeatedtext == [_("Sat"), _("Sun")]:
repeatedtext = _('Weekend')
else:
repeatedtext = ", ".join(repeatedtext)
if self.iconRepeat:
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, 2, self.rowSplit, self.iconWidth, self.iconHeight, self.iconRepeat))
else:
repeatedtext = begin[0] # date
text = repeatedtext + ((" %s ... %s (%d " + _("mins") + ")") % (begin[1], FuzzyTime(timer.end)[1], (timer.end - timer.begin) / 60))
res.append((eListboxPythonMultiContent.TYPE_TEXT, 148, self.itemHeight - self.rowSplit, width - 150, self.rowSplit, 2, RT_HALIGN_RIGHT | RT_VALIGN_BOTTOM, text))
icon = None
if not processed:
if timer.state == TimerEntry.StateWaiting:
state = _("waiting")
icon = self.iconWait
elif timer.state == TimerEntry.StatePrepared:
state = _("about to start")
icon = self.iconPrepared
elif timer.state == TimerEntry.StateRunning:
state = _("running...")
icon = self.iconZapped
elif timer.state == TimerEntry.StateEnded:
state = _("done!")
icon = self.iconDone
else:
state = _("<unknown>")
icon = None
else:
state = _("done!")
icon = self.iconDone
if timer.disabled:
state = _("disabled")
icon = self.iconDisabled
if timer.failed:
state = _("failed")
icon = self.iconFailed
icon and res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, self.iconMargin / 2, (self.rowSplit - self.iconHeight) / 2, self.iconWidth, self.iconHeight, icon))
res.append((eListboxPythonMultiContent.TYPE_TEXT, self.iconMargin + self.iconWidth, self.rowSplit, 180, height - self.rowSplit, 2, RT_HALIGN_LEFT | RT_VALIGN_BOTTOM, state))
line = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "div-h.png"))
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, 0, height - 2, width, 2, line))
return res
def __init__(self, list):
GUIComponent.__init__(self)
self.onSelectionChanged = []
self.l = eListboxPythonMultiContent() # noqa: E741
self.l.setBuildFunc(self.buildTimerEntry)
self.serviceNameFont = gFont("Regular", 20)
self.font = gFont("Regular", 18)
self.eventNameFont = gFont("Regular", 18)
self.l.setList(list)
self.listCount = len(list) # used by pager
self.itemHeight = 50
self.rowSplit = 25
self.iconMargin = 4
self.satPosLeft = 160
self.iconWait = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_wait.png"))
self.iconWidth = self.iconWait.size().width()
self.iconHeight = self.iconWait.size().height()
self.iconRecording = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_rec.png"))
self.iconPrepared = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_prep.png"))
self.iconDone = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_done.png"))
self.iconRepeat = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_rep.png"))
self.iconZapped = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_zap.png"))
self.iconDisabled = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_off.png"))
self.iconFailed = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "icons/timer_failed.png"))
def applySkin(self, desktop, parent):
def itemHeight(value):
self.itemHeight = parseScale(value)
def setServiceNameFont(value):
self.serviceNameFont = parseFont(value, ((1, 1), (1, 1)))
def setEventNameFont(value):
self.eventNameFont = parseFont(value, ((1, 1), (1, 1)))
def setFont(value):
self.font = parseFont(value, ((1, 1), (1, 1)))
def rowSplit(value):
self.rowSplit = parseScale(value)
def iconMargin(value):
self.iconMargin = parseScale(value)
def satPosLeft(value):
self.satPosLeft = parseScale(value)
for (attrib, value) in self.skinAttributes[:]:
try:
locals().get(attrib)(value)
self.skinAttributes.remove((attrib, value))
except:
pass
self.l.setItemHeight(self.itemHeight)
self.l.setFont(0, self.serviceNameFont)
self.l.setFont(1, self.font)
self.l.setFont(2, self.eventNameFont)
self.selectionChanged()
return GUIComponent.applySkin(self, desktop, parent)
def getCurrent(self):
cur = self.l.getCurrentSelection()
return cur and cur[0]
GUI_WIDGET = eListbox
def postWidgetCreate(self, instance):
instance.selectionChanged.get().append(self.selectionChanged)
instance.setContent(self.l)
self.instance = instance
def preWidgetRemove(self, instance):
instance.selectionChanged.get().remove(self.selectionChanged)
instance.setContent(None)
def selectionChanged(self):
for x in self.onSelectionChanged:
x()
def moveToIndex(self, index):
self.instance.moveSelectionTo(index)
def getCurrentIndex(self):
return self.instance.getCurrentIndex()
currentIndex = property(getCurrentIndex, moveToIndex)
currentSelection = property(getCurrent)
def moveDown(self):
self.instance.moveSelection(self.instance.moveDown)
def invalidate(self):
self.l.invalidate()
def entryRemoved(self, idx):
self.l.entryRemoved(idx)