remove unneeded imports
[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         # <ePixmap position="140,220" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
13         # <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" />
14         # <ePixmap position="420,220" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
15         # <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" />
16
17         skin = """<screen name="AutoTimerPreview" title="Preview AutoTimer" position="75,155" size="565,265">
18                 <widget name="timerlist" position="5,5" size="555,210" scrollbarMode="showOnDemand" />
19                 <ePixmap position="0,220" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
20                 <ePixmap position="280,220" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
21                 <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" />
22                 <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" />
23         </screen>"""
24
25         def __init__(self, session, timers):
26                 Screen.__init__(self, session)
27
28                 # Sort timers by begin
29                 timers.sort(key = lambda x: x[1])
30                 self.sort_type = 0
31
32                 self.timers = timers
33
34                 self["timerlist"] = AutoTimerPreviewList(self.timers)
35
36                 # Initialize Buttons
37                 self["key_red"] = Button(_("Cancel"))
38                 self["key_green"] = Button(_("???"))
39                 self["key_yellow"] = Button()
40                 self["key_blue"] = Button(_("???"))
41
42                 self.setSortDescription()
43
44                 # Define Actions
45                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
46                         {
47                                 "cancel": self.cancel,
48                                 "save": self.save,
49                                 "yellow": self.sort,
50                                 "blue": self.blue
51                         }
52                 )
53
54         def setSortDescription(self):
55                 if self.sort_type == 1:
56                         self["key_yellow"].setText(_("Sort Time"))
57                 else:
58                         self["key_yellow"].setText(_("Sort AutoTimer"))
59
60         def sort(self):
61                 if len(self.timers):
62                         timer = self["timerlist"].getCurrent()
63                         if self.sort_type == 1:
64                                 self.timers.sort(key=lambda x: x[1])
65                                 self.sort_type = 0
66                         else:
67                                 self.timers.sort(key = lambda x: x[4].lower())
68                                 self.sort_type = 1
69                         self["timerlist"].setList(self.timers)
70                         self["timerlist"].moveToEntry(timer)
71                         self.setSortDescription()
72
73         def blue(self):
74                 pass
75
76         def cancel(self):
77                 self.close(None)
78
79         def save(self):
80                 self.close(True)