intial commit of autotimer, epgrefresh and werbezapper to enigma2-plugins
[enigma2-plugins.git] / autotimer / src / AutoTimerPreview.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4
5 # GUI (Components)
6 from Components.ActionMap import ActionMap
7 from Components.Button import Button
8 from AutoTimerList import AutoTimerPreviewList
9
10 class AutoTimerPreview(Screen):
11         """Preview Timers which would be set"""
12
13         # <ePixmap position="140,220" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
14         # <widget name="key_green" position="140,220" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
15         # <ePixmap position="420,220" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
16         # <widget name="key_blue" position="420,220" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
17
18         skin = """<screen name="AutoTimerPreview" title="Preview AutoTimer" position="75,155" size="565,265">
19                 <widget name="timerlist" position="5,5" size="555,210" scrollbarMode="showOnDemand" />
20                 <ePixmap position="0,220" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
21                 <ePixmap position="280,220" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
22                 <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" />
23                 <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" />
24         </screen>"""
25
26         def __init__(self, session, timers):
27                 Screen.__init__(self, session)
28
29                 # Sort timers by begin
30                 timers.sort(key = lambda x: x[1])
31                 self.sort_type = 0
32
33                 self.timers = timers
34
35                 self["timerlist"] = AutoTimerPreviewList(self.timers)
36
37                 # Initialize Buttons
38                 self["key_red"] = Button(_("Cancel"))
39                 self["key_green"] = Button(_("???"))
40                 self["key_yellow"] = Button()
41                 self["key_blue"] = Button(_("???"))
42
43                 self.setSortDescription()
44
45                 # Define Actions
46                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
47                         {
48                                 "cancel": self.cancel,
49                                 "save": self.save,
50                                 "yellow": self.sort,
51                                 "blue": self.blue
52                         }
53                 )
54
55         def setSortDescription(self):
56                 if self.sort_type == 1:
57                         self["key_yellow"].setText(_("Sort Time"))
58                 else:
59                         self["key_yellow"].setText(_("Sort AutoTimer"))
60
61         def sort(self):
62                 if len(self.timers):
63                         timer = self["timerlist"].getCurrent()
64                         if self.sort_type == 1:
65                                 self.timers.sort(key=lambda x: x[1])
66                                 self.sort_type = 0
67                         else:
68                                 self.timers.sort(key = lambda x: x[4].lower())
69                                 self.sort_type = 1
70                         self["timerlist"].setList(self.timers)
71                         self["timerlist"].moveToEntry(timer)
72                         self.setSortDescription()
73
74         def blue(self):
75                 pass
76
77         def cancel(self):
78                 self.close(None)
79
80         def save(self):
81                 self.close(True)