smaller fixes, bump required e2 version, add sample for custom destination path
[enigma2-plugins.git] / autotimer / src / AutoTimerPreview.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3
4 # GUI (Components)
5 from Components.ActionMap import ActionMap
6 from Components.Button import Button
7 from AutoTimerList import AutoTimerPreviewList
8
9 class AutoTimerPreview(Screen):
10         """Preview Timers which would be set"""
11
12         skin = """<screen name="AutoTimerPreview" title="Preview AutoTimer" position="75,155" size="565,265">
13                 <widget name="timerlist" position="5,5" size="555,210" scrollbarMode="showOnDemand" />
14                 <ePixmap position="0,220" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
15                 <ePixmap position="280,220" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
16                 <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" />
17                 <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" />
18         </screen>"""
19
20         def __init__(self, session, timers):
21                 Screen.__init__(self, session)
22
23                 # Sort timers by begin
24                 timers.sort(key = lambda x: x[1])
25                 self.sort_type = 0
26
27                 self.timers = timers
28
29                 self["timerlist"] = AutoTimerPreviewList(self.timers)
30
31                 # Initialize Buttons
32                 self["key_red"] = Button(_("Cancel"))
33                 self["key_yellow"] = Button()
34
35                 self.setSortDescription()
36
37                 # Define Actions
38                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
39                         {
40                                 "cancel": self.cancel,
41                                 "save": self.save,
42                                 "yellow": self.sort
43                         }
44                 )
45
46         def setSortDescription(self):
47                 if self.sort_type == 1:
48                         self["key_yellow"].setText(_("Sort Time"))
49                 else:
50                         self["key_yellow"].setText(_("Sort AutoTimer"))
51
52         def sort(self):
53                 if len(self.timers):
54                         timer = self["timerlist"].getCurrent()
55                         if self.sort_type == 1:
56                                 self.timers.sort(key=lambda x: x[1])
57                                 self.sort_type = 0
58                         else:
59                                 self.timers.sort(key = lambda x: x[4].lower())
60                                 self.sort_type = 1
61                         self["timerlist"].setList(self.timers)
62                         self["timerlist"].moveToEntry(timer)
63                         self.setSortDescription()
64
65         def cancel(self):
66                 self.close(None)
67
68         def save(self):
69                 self.close(True)