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