2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.InputBox import InputBox
7 from Components.ActionMap import ActionMap
8 from Components.Button import Button
9 from Components.TimerList import TimerList
10 from Components.SelectionList import SelectionList, SelectionEntryComponent
13 from RecordTimer import AFTEREVENT
15 # Needed to convert our timestamp back and forth
16 from time import localtime
18 afterevent = { AFTEREVENT.NONE: _("do nothing"), AFTEREVENT.DEEPSTANDBY: _("go to deep standby"), AFTEREVENT.STANDBY: _("go to standby")}
20 class AutoTimerImportSelector(Screen):
21 def __init__(self, session, autotimer):
22 Screen.__init__(self, session)
23 self.skinName = "TimerEditList"
25 self.autotimer = autotimer
30 self["timerlist"] = TimerList(self.list)
32 self["key_red"] = Button(_("Cancel"))
33 self["key_green"] = Button(_("OK"))
34 self["key_yellow"] = Button("")
35 self["key_blue"] = Button("")
37 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
39 "ok": self.openImporter,
40 "cancel": self.cancel,
41 "green": self.openImporter,
44 self.onLayoutFinish.append(self.setCustomTitle)
46 def setCustomTitle(self):
47 self.setTitle(_("Select a Timer to Import"))
49 def fillTimerList(self):
52 for timer in self.session.nav.RecordTimer.timer_list:
53 self.list.append((timer, False))
55 for timer in self.session.nav.RecordTimer.processed_timers:
56 self.list.append((timer, True))
57 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
59 def importerClosed(self, ret):
64 def openImporter(self):
65 cur=self["timerlist"].getCurrent()
67 self.session.openWithCallback(
77 class AutoTimerImporter(Screen):
78 """Import AutoTimer from Timer"""
80 skin = """<screen name="AutoTimerImporter" title="Import AutoTimer" position="75,155" size="565,280">
81 <widget name="list" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
82 <ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
83 <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
84 <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
85 <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
86 <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
87 <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
88 <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
89 <widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
92 def __init__(self, session, timer, autotimer):
93 Screen.__init__(self, session)
96 self.autotimer = autotimer
99 self["key_red"] = Button(_("Cancel"))
100 self["key_green"] = Button(_("OK"))
101 self["key_yellow"] = Button()
102 self["key_blue"] = Button()
104 begin = localtime(timer.begin)
105 end = localtime(timer.end)
107 SelectionEntryComponent(
108 _("Match title: %s") % (timer.name),
113 SelectionEntryComponent(
114 _("Match Timespan: %02d:%02d - %02d:%02d") % (begin[3], begin[4], end[3], end[4]),
115 ((begin[3], begin[4]), (end[3], end[4])),
119 SelectionEntryComponent(
120 _("Only on Service: %s") % (timer.service_ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')),
121 str(timer.service_ref),
125 SelectionEntryComponent(
126 _("AfterEvent: %s") % (afterevent[timer.afterEvent]),
133 self["list"] = SelectionList(list)
136 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
138 "ok": self["list"].toggleSelection,
139 "cancel": self.cancel,
145 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
147 def cancelConfirm(self, ret):
151 def gotCustomMatch(self, ret):
153 self.autotimer.match = ret
154 # Check if we have a trailing whitespace
156 self.session.openWithCallback(
157 self.trailingWhitespaceRemoval,
159 _('You entered "%s" as Text to match.\nDo you want to remove trailing whitespaces?') % (ret)
163 self.close(self.autotimer)
165 def trailingWhitespaceRemoval(self, ret):
168 self.autotimer.match = self.autotimer.match.rstrip()
169 self.close(self.autotimer)
172 list = self["list"].getSelectionsList()
175 if item[2] == 0: # Match (should maybe be forced?)
176 self.autotimer.match = item[1]
177 if item[2] == 1: # Timespan
178 self.autotimer.timespan = item[1]
179 if item[2] == 2: # Service
182 # strip all after last :
183 pos = value.rfind(':')
185 value = value[:pos+1]
187 self.autotimer.services = [value]
188 if item[2] == 3: # AfterEvent
189 self.autotimer.afterevent = [(item[1], None)]
191 if self.autotimer.match == "":
192 self.session.openWithCallback(
195 title = _("Please provide a Text to Match")
198 self.close(self.autotimer)