Support focus animation for listbox
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / AnimationSetup / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import ActionMap
4 from Components.ConfigList import ConfigListScreen
5 from Components.MenuList import MenuList
6 from Components.Sources.StaticText import StaticText
7 from Components.config import config, ConfigNumber, ConfigSelection, ConfigSelectionNumber, getConfigListEntry
8 from Plugins.Plugin import PluginDescriptor
9
10 from enigma import setAnimation_current, setAnimation_speed, setAnimation_current_listbox
11
12 # default = slide to left
13 g_default = {
14         "current": 6,
15         "speed"  : 20,
16         "listbox": "2",
17 }
18 g_max_speed = 30
19
20 g_animation_paused = False
21 g_orig_show = None
22 g_orig_doClose = None
23
24 config.misc.window_animation_default = ConfigNumber(default=g_default["current"])
25 config.misc.window_animation_speed = ConfigSelectionNumber(1, g_max_speed, 1, default=g_default["speed"])
26 config.misc.listbox_animation_default = ConfigSelection(default = g_default["listbox"], choices = [ ("0", _("Disable")), ("1", _("Enable")), ("2", _("Same behavior as current animation")) ])
27
28 class AnimationSetupConfig(ConfigListScreen, Screen):
29         skin=   """
30                 <screen position="center,center" size="600,140" title="Animation Settings">
31                         <widget name="config" position="0,0" size="600,100" scrollbarMode="showOnDemand" />
32
33                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,100" size="140,40" alphatest="on" />
34                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,100" size="140,40" alphatest="on" />
35                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,100" size="140,40" alphatest="on" />
36
37                         <widget source="key_red" render="Label" position="0,100" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#9f1313" transparent="1" />
38                         <widget source="key_green" render="Label" position="140,100" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#1f771f" transparent="1" />
39                         <widget source="key_yellow" render="Label" position="280,100" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#a08500" transparent="1" />
40                 </screen>
41                 """
42
43         def __init__(self, session):
44                 self.session = session
45                 self.entrylist = []
46
47                 Screen.__init__(self, session)
48                 ConfigListScreen.__init__(self, self.entrylist)
49
50                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions",], {
51                         "ok"     : self.keyGreen,
52                         "green"  : self.keyGreen,
53                         "yellow" : self.keyYellow,
54                         "red"    : self.keyRed,
55                         "cancel" : self.keyRed,
56                 }, -2)
57                 self["key_red"]   = StaticText(_("Cancel"))
58                 self["key_green"] = StaticText(_("Save"))
59                 self["key_yellow"] = StaticText(_("Default"))
60
61                 self.makeConfigList()
62                 self.onLayoutFinish.append(self.layoutFinished)
63
64         def layoutFinished(self):
65                 self.setTitle(_('Animation Setup'))
66
67         def keyGreen(self):
68                 config.misc.window_animation_speed.save()
69                 setAnimation_speed(int(config.misc.window_animation_speed.value))
70                 config.misc.listbox_animation_default.save()
71                 setAnimation_current_listbox(int(config.misc.listbox_animation_default.value))
72                 self.close()
73
74         def keyRed(self):
75                 config.misc.window_animation_speed.cancel()
76                 config.misc.listbox_animation_default.cancel()
77                 self.close()
78
79         def keyYellow(self):
80                 global g_default
81
82                 config.misc.window_animation_speed.value = g_default["speed"]
83                 config.misc.listbox_animation_default.value = g_default["listbox"]
84                 self.makeConfigList()
85
86         def keyLeft(self):
87                 ConfigListScreen.keyLeft(self)
88
89         def keyRight(self):
90                 ConfigListScreen.keyRight(self)
91
92         def makeConfigList(self):
93                 self.entrylist = []
94
95                 entrySpeed = getConfigListEntry(_("Animation Speed"), config.misc.window_animation_speed)
96                 self.entrylist.append(entrySpeed)
97                 entryMoveSelection = getConfigListEntry(_("Enable Focus Animation"), config.misc.listbox_animation_default)
98                 self.entrylist.append(entryMoveSelection)
99
100                 self["config"].list = self.entrylist
101                 self["config"].l.setList(self.entrylist)
102
103
104 class AnimationSetupScreen(Screen):
105         animationSetupItems = [
106                 {"idx":0, "name":_("Disable Animations")},
107                 {"idx":1, "name":_("Simple fade")},
108                 {"idx":2, "name":_("Grow drop")},
109                 {"idx":3, "name":_("Grow from left")},
110                 {"idx":4, "name":_("Popup")},
111                 {"idx":5, "name":_("Slide drop")},
112                 {"idx":6, "name":_("Slide left to right")},
113                 {"idx":7, "name":_("Slide top to bottom")},
114                 {"idx":8, "name":_("Stripes")},
115         ]
116
117         skin = """
118                 <screen name="AnimationSetup" position="center,center" size="580,400" title="Animation Setup">
119                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" zPosition="1" alphatest="on" />
120                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" zPosition="1" alphatest="on" />
121                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" zPosition="1" alphatest="on" />
122                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" zPosition="1" alphatest="on" />
123
124                         <widget source="key_red" render="Label" position="0,0" zPosition="2" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#9f1313" transparent="1" />
125                         <widget source="key_green" render="Label" position="140,0" zPosition="2" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#1f771f" transparent="1" />
126                         <widget source="key_yellow" render="Label" position="280,0" zPosition="2" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#a08500" transparent="1" />
127                         <widget source="key_blue" render="Label" position="420,0" zPosition="2" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ffffff" backgroundColor="#18188b" transparent="1" />
128
129                         <widget name="list" position="10,60" size="560,364" scrollbarMode="showOnDemand" />
130                         <widget source="introduction" render="Label" position="0,370" size="560,40" zPosition="10" font="Regular;20" valign="center" backgroundColor="#25062748" transparent="1" />
131                 </screen>"""
132
133         def __init__(self, session):
134
135                 self.skin = AnimationSetupScreen.skin
136                 Screen.__init__(self, session)
137
138                 self.animationList = []
139
140                 self["introduction"] = StaticText(_("* current animation"))
141                 self["key_red"] = StaticText(_("Cancel"))
142                 self["key_green"] = StaticText(_("Save"))
143                 self["key_yellow"] = StaticText(_("Setting"))
144                 self["key_blue"] = StaticText(_("Preview"))
145
146                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
147                         {
148                                 "cancel": self.keyclose,
149                                 "save": self.ok,
150                                 "ok" : self.ok,
151                                 "yellow": self.config,
152                                 "blue": self.preview
153                         }, -3)
154
155                 self["list"] = MenuList(self.animationList)
156
157                 self.onLayoutFinish.append(self.layoutFinished)
158
159         def layoutFinished(self):
160                 l = []
161                 for x in self.animationSetupItems:
162                         key = x.get("idx", 0)
163                         name = x.get("name", "??")
164                         if key == config.misc.window_animation_default.value:
165                                 name = "* %s" % (name)
166                         l.append( (name, key) )
167
168                 self["list"].setList(l)
169
170         def ok(self):
171                 current = self["list"].getCurrent()
172                 if current:
173                         key = current[1]
174                         config.misc.window_animation_default.value = key
175                         config.misc.window_animation_default.save()
176                         setAnimation_current(key)
177                         setAnimation_current_listbox(int(config.misc.listbox_animation_default.value))
178                 self.close()
179
180         def keyclose(self):
181                 setAnimation_current(config.misc.window_animation_default.value)
182                 setAnimation_speed(int(config.misc.window_animation_speed.value))
183                 setAnimation_current_listbox(int(config.misc.listbox_animation_default.value))
184                 self.close()
185
186         def config(self):
187                 self.session.open(AnimationSetupConfig)
188
189         def preview(self):
190                 current = self["list"].getCurrent()
191                 if current:
192                         global g_animation_paused
193                         tmp = g_animation_paused
194                         g_animation_paused = False
195
196                         setAnimation_current(current[1])
197                         self.session.open(MessageBox, current[0], MessageBox.TYPE_INFO, timeout=3)
198                         g_animation_paused = tmp
199
200 def checkAttrib(self, paused):
201         global g_animation_paused
202         if g_animation_paused is paused and self.skinAttributes is not None:
203                 for (attr, value) in self.skinAttributes:
204                         if attr == "animationPaused" and value in ("1", "on"):
205                                 return True
206         return False
207
208 def screen_show(self):
209         global g_animation_paused
210         if g_animation_paused:
211                 setAnimation_current(0)
212
213         g_orig_show(self)
214
215         if checkAttrib(self, False):
216                 g_animation_paused = True
217
218 def screen_doClose(self):
219         global g_animation_paused
220         if checkAttrib(self, True):
221                 g_animation_paused = False
222                 setAnimation_current(config.misc.window_animation_default.value)
223         g_orig_doClose(self)
224
225 def animationSetupMain(session, **kwargs):
226         session.open(AnimationSetupScreen)
227
228 def startAnimationSetup(menuid):
229         if menuid != "system":
230                 return []
231
232         return [( _("Animations"), animationSetupMain, "animation_setup", None)]
233
234 def sessionAnimationSetup(session, reason, **kwargs):
235         setAnimation_current(config.misc.window_animation_default.value)
236         setAnimation_speed(int(config.misc.window_animation_speed.value))
237         setAnimation_current_listbox(int(config.misc.listbox_animation_default.value))
238
239         global g_orig_show, g_orig_doClose
240         if g_orig_show is None:
241                 g_orig_show = Screen.show
242         if g_orig_doClose is None:
243                 g_orig_doClose = Screen.doClose
244         Screen.show = screen_show
245         Screen.doClose = screen_doClose
246
247 def Plugins(**kwargs):
248         plugin_list = [
249                 PluginDescriptor(
250                         name = "Animations",
251                         description = "Setup UI animations",
252                         where = PluginDescriptor.WHERE_MENU,
253                         needsRestart = False,
254                         fnc = startAnimationSetup),
255                 PluginDescriptor(
256                         where = PluginDescriptor.WHERE_SESSIONSTART,
257                         needsRestart = False,
258                         fnc = sessionAnimationSetup),
259         ]
260         return plugin_list;