1 # -*- coding: UTF-8 -*-
2 # for localized messages
6 from Screens.Screen import Screen
9 from Components.ActionMap import ActionMap
10 from Components.Button import Button
11 from Components.Sources.List import List
13 from ServiceReference import ServiceReference
14 from Tools.FuzzyDate import FuzzyTime
16 class AutoTimerPreview(Screen):
17 """Preview Timers which would be set"""
19 skin = """<screen name="AutoTimerPreview" title="Preview AutoTimer" position="75,155" size="565,265">
20 <widget source="timerlist" render="Listbox" position="5,5" size="555,210" scrollbarMode="showOnDemand">
21 <convert type="TemplatedMultiContent">
23 MultiContentEntryText(pos=(2,2), size=(550,24), text = 3, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
24 MultiContentEntryText(pos=(2,26), size=(555,30), text = 0, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
25 MultiContentEntryText(pos=(2,50), size=(400,20), text = 4, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
26 MultiContentEntryText(pos=(320,50), size=(233,20), text = 2, font = 1, flags = RT_HALIGN_RIGHT|RT_VALIGN_CENTER),
28 "fonts": [gFont("Regular", 20),gFont("Regular", 18)],
33 <ePixmap position="0,220" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
34 <ePixmap position="280,220" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
35 <widget name="key_red" position="0,220" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
36 <widget name="key_yellow" position="280,220" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
39 def __init__(self, session, timers):
40 Screen.__init__(self, session)
42 # Sort timers by begin
43 timers.sort(key = lambda x: x[1])
46 # name, begin, end, serviceref, timername -> name, begin, timername, sname, timestr
49 ServiceReference(x[3]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '').encode('utf-8', 'ignore'),
50 (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(x[1]) + FuzzyTime(x[2])[1:] + ((x[2] - x[1]) / 60,))))
54 self["timerlist"] = List(self.timers)
57 self["key_red"] = Button(_("Cancel"))
58 self["key_yellow"] = Button()
60 self.setSortDescription()
63 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
65 "cancel": self.cancel,
71 self.onLayoutFinish.append(self.setCustomTitle)
73 def setCustomTitle(self):
74 self.setTitle(_("Preview AutoTimer"))
76 def setSortDescription(self):
77 if self.sort_type == 1:
78 self["key_yellow"].setText(_("Sort Time"))
80 self["key_yellow"].setText(_("Sort AutoTimer"))
85 current = self["timerlist"].current
91 if self.sort_type == 1:
92 timers.sort(key=lambda x: x[1])
95 timers.sort(key = lambda x: x[4].lower())
97 self["timerlist"].updateList(timers)
98 self["timerlist"].index = idx
99 self.setSortDescription()