1 # -*- coding: UTF-8 -*-
2 # for localized messages
6 from Screens.Screen import Screen
9 from Components.ActionMap import ActionMap
10 from Components.Sources.List import List
11 from Components.Sources.StaticText import StaticText
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="center,center" size="565,280">
20 <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
21 <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
22 <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
23 <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
24 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
25 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
26 <widget source="timerlist" render="Listbox" position="5,45" size="555,220" scrollbarMode="showAlways">
27 <convert type="TemplatedMultiContent">
29 MultiContentEntryText(pos=(2,2), size=(550,24), text = 3, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
30 MultiContentEntryText(pos=(2,26), size=(555,30), text = 0, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
31 MultiContentEntryText(pos=(2,50), size=(400,20), text = 4, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
32 MultiContentEntryText(pos=(290,50), size=(233,20), text = 2, font = 1, flags = RT_HALIGN_RIGHT|RT_VALIGN_CENTER),
34 "fonts": [gFont("Regular", 20),gFont("Regular", 18)],
41 def __init__(self, session, timers):
42 Screen.__init__(self, session)
44 # Sort timers by begin
45 timers.sort(key = lambda x: x[1])
48 # name, begin, end, serviceref, timername -> name, begin, timername, sname, timestr
51 ServiceReference(x[3]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '').encode('utf-8', 'ignore'),
52 (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(x[1]) + FuzzyTime(x[2])[1:] + ((x[2] - x[1]) / 60,))))
56 self["timerlist"] = List(self.timers)
59 self["key_red"] = StaticText(_("Cancel"))
60 self["key_yellow"] = StaticText()
62 self.setSortDescription()
65 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
67 "cancel": self.cancel,
73 self.onLayoutFinish.append(self.setCustomTitle)
75 def setCustomTitle(self):
76 self.setTitle(_("Preview AutoTimer"))
78 def setSortDescription(self):
79 if self.sort_type == 1:
80 self["key_yellow"].text = _("Sort Time")
82 self["key_yellow"].text = _("Sort AutoTimer")
87 current = self["timerlist"].current
93 if self.sort_type == 1:
94 timers.sort(key=lambda x: x[1])
97 timers.sort(key = lambda x: x[4].lower())
99 self["timerlist"].updateList(timers)
100 self["timerlist"].index = idx
101 self.setSortDescription()