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