Update embedded skins of dvdbackup, elektro, epgrefresh, movieepg and quickbutton
[enigma2-plugins.git] / quickbutton / src / plugin.py
1 #  Quickbutton
2 #
3 #  $Id$
4 #
5 #  Coded by Dr.Best (c) 2009
6 #  Support: www.dreambox-tools.info
7 #
8 #  This program is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU General Public License
10 #  as published by the Free Software Foundation; either version 2
11 #  of the License, or (at your option) any later version.
12 #
13 #  This program is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #  GNU General Public License for more details.
17 #
18
19 from Screens.Screen import Screen
20 from Screens.ChannelSelection import ChannelSelection
21 from Plugins.Plugin import PluginDescriptor
22 from Components.ActionMap import ActionMap, HelpableActionMap
23 from Components.PluginComponent import plugins
24 from Plugins.Plugin import PluginDescriptor
25 from Components.ConfigList import ConfigList, ConfigListScreen
26 from Components.config import ConfigSubsection, ConfigText, configfile, ConfigSelection, getConfigListEntry, ConfigYesNo
27 from Components.config import config
28 from Components.Button import Button
29 from Screens.MessageBox import MessageBox
30 # for localized messages
31 from . import _
32
33 config.plugins.Quickbutton = ConfigSubsection()
34 config.plugins.Quickbutton.overwritehbbtvredbutton = ConfigYesNo(default = False)
35 config.plugins.Quickbutton.red = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
36 config.plugins.Quickbutton.red_b = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
37 config.plugins.Quickbutton.green = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
38 config.plugins.Quickbutton.yellow = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
39 config.plugins.Quickbutton.blue = ConfigText(default = _("Nothing"), visible_width = 50, fixed_size = False)
40
41
42 from  Screens.InfoBarGenerics import InfoBarPlugins
43 baseInfoBarPlugins__init__ = None
44 ENABLE_RED_BUTTON = False
45
46 def getHBBTVInstalled():
47         try:
48                 from Plugins.Extensions.HbbTV.HbbTV import HbbTV
49                 return config.plugins.hbbtv.enabled.value
50         except ImportError:
51                 return False
52
53 def autostart(reason, **kwargs):
54         global baseInfoBarPlugins__init__,ENABLE_RED_BUTTON
55         if "session" in kwargs:
56                 session = kwargs["session"]
57                 if baseInfoBarPlugins__init__ is None:
58                         baseInfoBarPlugins__init__ = InfoBarPlugins.__init__
59                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
60                 InfoBarPlugins.greenlong = greenlong
61                 InfoBarPlugins.yellowlong = yellowlong
62                 InfoBarPlugins.redlong = redlong
63                 InfoBarPlugins.bluelong = bluelong
64                 if config.misc.rcused.value != 1:
65                         ENABLE_RED_BUTTON = True
66                         InfoBarPlugins.red = red
67
68 def setup(session,**kwargs):
69         session.open(QuickbuttonSetup)
70
71 def Plugins(**kwargs):
72
73         list = [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = autostart)] 
74         list.append(PluginDescriptor(name="Setup Quickbutton", description=_("setup for Quickbutton"), where = [PluginDescriptor.WHERE_PLUGINMENU], icon = "setup_quickbutton.png", fnc=setup))
75         return list
76
77 def InfoBarPlugins__init__(self):
78         from Screens.InfoBarGenerics import InfoBarEPG
79         if isinstance(self, InfoBarEPG):
80                 x = {   "green_l": (self.greenlong, _("Assign plugin to long green key pressed")),
81                         "yellow_l": (self.yellowlong, _("Assign plugin to long yellow key pressed")),
82                         "red_l": (self.redlong, _("Assign plugin to long red key pressed")),
83                         "blue_l": (self.bluelong, _("Assign plugin to long blue key pressed"))}
84                 if ENABLE_RED_BUTTON:
85                         x["red_b"] = (self.red, _("Assign plugin to red key pressed"))
86                         hbbtvinstalled = getHBBTVInstalled()
87                         if config.plugins.Quickbutton.overwritehbbtvredbutton.value and hbbtvinstalled:
88                                 self["HbbtvActions"].setEnabled(False)
89                 self["QuickbuttonActions"] = HelpableActionMap(self, "QuickbuttonActions",x)
90
91                         
92         else:
93                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
94                 InfoBarPlugins.greenlong = None
95                 InfoBarPlugins.yellowlong = None
96                 InfoBarPlugins.redlong = None
97                 InfoBarPlugins.bluelong = None
98                 if ENABLE_RED_BUTTON:
99                         InfoBarPlugins.red = None
100         baseInfoBarPlugins__init__(self)
101
102 def greenlong(self):
103         startPlugin(self,str(config.plugins.Quickbutton.green.value))
104
105 def yellowlong(self):
106         startPlugin(self, str(config.plugins.Quickbutton.yellow.value))
107
108 def redlong(self):
109         startPlugin(self, str(config.plugins.Quickbutton.red.value))
110
111 def bluelong(self):
112         startPlugin(self, str(config.plugins.Quickbutton.blue.value))
113
114 def red(self):
115         startPlugin(self, str(config.plugins.Quickbutton.red_b.value))
116
117 def startPlugin(self,pname):
118         msgText = _("Unknown Error")
119         no_plugin = True
120         if pname != _("Nothing"):
121                 if pname == _("Single EPG"):
122                         from Screens.InfoBarGenerics import InfoBarEPG
123                         if isinstance(self, InfoBarEPG):
124                                 self.openSingleServiceEPG()
125                         no_plugin = False
126                 elif pname == _("Multi EPG"):
127                         from Screens.InfoBarGenerics import InfoBarEPG
128                         if isinstance(self, InfoBarEPG):
129                                 self.openMultiServiceEPG()
130                         no_plugin = False
131                 elif pname == _("MediaPlayer"):
132                         try: # falls es nicht installiert ist
133                                 from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
134                                 self.session.open(MediaPlayer)
135                                 no_plugin = False
136                         except Exception, e:
137                                 msgText = _("Error!\nError Text: %s"%e)
138                 elif pname == _("Plugin browser"):
139                         from Screens.PluginBrowser import PluginBrowser
140                         self.session.open(PluginBrowser)
141                         no_plugin = False
142                 elif pname == _("switch 4:3 content display"):
143                         ar = {  "pillarbox": _("Pillarbox"), 
144                                 "panscan": _("Pan&Scan"),  
145                                 "scale": _("Just Scale")}
146                         switch = { "pillarbox":"panscan", "panscan":"scale", "scale":"pillarbox" }
147                         config.av.policy_43.value =  switch[config.av.policy_43.value]
148                         config.av.policy_43.save()
149                         self.session.open(MessageBox,_("Display 4:3 content as") + " " + ar[config.av.policy_43.value], MessageBox.TYPE_INFO, timeout = 3)
150                         no_plugin = False
151                 elif pname == _("Timer"):
152                         from Screens.TimerEdit import TimerEditList
153                         self.session.open(TimerEditList)
154                         no_plugin = False
155                 elif pname == _("HbbTV Applications"):
156                         try:
157                                 from Plugins.Extensions.HbbTV.HbbTV import HbbTV
158                                 no_plugin = not config.plugins.hbbtv.enabled.value
159                         except ImportError:
160                                 no_plugin = True
161                         finally:
162                                 if not no_plugin:
163                                         hbbtv_instance = HbbTV.instance
164                                         if hbbtv_instance:
165                                                 hbbtv_instance._showApplicationList()
166                 else:
167                         plugin = None
168                         for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU]):
169                                 if pname == str(p.name):
170                                         plugin = p
171                         if plugin is not None:
172                                 try:
173                                         self.runPlugin(plugin)
174                                         no_plugin = False
175                                 except Exception, e:
176                                         msgText = _("Error!\nError Text: %s"%e)
177                         else: 
178                                 msgText = _("Plugin not found!")
179         else:
180                 msgText = _("No plugin assigned!")
181         if no_plugin:
182                 self.session.open(MessageBox,msgText, MessageBox.TYPE_INFO)
183
184
185 class QuickbuttonSetup(ConfigListScreen, Screen):
186         skin = """
187                 <screen position="center,center" size="720,310" title="Quickbutton Setup">
188                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" alphatest="on" />
189                         <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" alphatest="on" />
190                         <widget name="key_red" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
191                         <widget name="key_green" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
192                         <eLabel position="10,50" size="700,1" backgroundColor="grey" />
193                         <widget name="config" position="10,60" size="700,240" enableWrapAround="1" scrollbarMode="showOnDemand" />
194                 </screen>"""
195
196         def __init__(self, session, args = None):
197                 Screen.__init__(self, session)
198                 self["key_red"] = Button(_("Cancel"))
199                 self["key_green"] = Button(_("OK"))
200                 self.entryguilist = []
201                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
202                 {
203                         "green": self.keySave,
204                         "cancel": self.keyClose,
205                         "ok": self.keySave,
206                         "left": self.keyLeft,
207                         "right": self.keyRight,
208                 }, -2)
209                 ConfigListScreen.__init__(self, [], session = session)
210                 self.hbbtvinstalled = getHBBTVInstalled()
211                 self.overwriteHBBTVButton = config.plugins.Quickbutton.overwritehbbtvredbutton
212                 self.createSetup("config")
213
214         def createSetup(self, widget):
215                 cfglist = []
216                 red_b_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.red_b.value)
217                 red_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.red.value)
218                 green_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.green.value)
219                 yellow_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.yellow.value)
220                 blue_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.blue.value)
221                 # feste Vorgaben...koennte man noch erweitern, da hole ich mir sinnvolle Vorschlaege aus Foren noch ein...
222                 self.entryguilist.append(("0",_("Nothing")))
223                 self.entryguilist.append(("1",_("Single EPG")))
224                 self.entryguilist.append(("2",_("Multi EPG")))
225                 self.entryguilist.append(("3",_("MediaPlayer")))
226                 self.entryguilist.append(("4",_("Plugin browser")))
227                 self.entryguilist.append(("5",_("switch 4:3 content display")))
228                 self.entryguilist.append(("6",_("Timer")))
229                 if self.hbbtvinstalled:
230                         self.entryguilist.append(("7",_("HbbTV Applications")))
231                         index = 8
232                 else:
233                         index = 7
234                 # Vorgaben aus EXTENSIONSMENU, PLUGINMENU
235                 for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU]):
236                         self.entryguilist.append((str(index),str(p.name)))
237                         if config.plugins.Quickbutton.red.value == str(p.name):
238                                 red_selectedindex = str(index)
239                         if config.plugins.Quickbutton.red_b.value == str(p.name):
240                                 red_b_selectedindex = str(index)
241                         if config.plugins.Quickbutton.green.value == str(p.name):
242                                 green_selectedindex = str(index)
243                         if config.plugins.Quickbutton.yellow.value == str(p.name):
244                                 yellow_selectedindex = str(index)
245                         if config.plugins.Quickbutton.blue.value == str(p.name):
246                                 blue_selectedindex = str(index)
247                         index = index + 1
248                 self.overwriteHBBTVButtonEntry = None
249                 if self.hbbtvinstalled and ENABLE_RED_BUTTON:
250                         self.overwriteHBBTVButtonEntry = getConfigListEntry(_("Overwrite HBBTV-red-button"), self.overwriteHBBTVButton)
251                         cfglist.append(self.overwriteHBBTVButtonEntry)
252                 self.redchoice = ConfigSelection(default = red_selectedindex, choices = self.entryguilist)
253                 self.greenchoice = ConfigSelection(default = green_selectedindex, choices = self.entryguilist)
254                 self.yellowchoice = ConfigSelection(default = yellow_selectedindex, choices = self.entryguilist)
255                 self.bluechoice = ConfigSelection(default = blue_selectedindex, choices = self.entryguilist)
256                 cfglist.append(getConfigListEntry(_("assigned to long red"), self.redchoice))
257                 cfglist.append(getConfigListEntry(_("assigned to long green"), self.greenchoice))
258                 cfglist.append(getConfigListEntry(_("assigned to long yellow"), self.yellowchoice))
259                 cfglist.append(getConfigListEntry(_("assigned to long blue"), self.bluechoice))
260                 if ENABLE_RED_BUTTON and (self.overwriteHBBTVButton.value or not self.hbbtvinstalled):
261                         self.red_b_choice = ConfigSelection(default = red_b_selectedindex, choices = self.entryguilist)
262                         cfglist.append(getConfigListEntry(_("assigned to red"), self.red_b_choice))
263                 self[widget].list = cfglist
264                 self[widget].l.setList(cfglist)
265
266         def getStaticPluginName(self,value):
267                 if value == _("Single EPG"):
268                         return "1"
269                 elif value == _("Multi EPG"):
270                         return "2"
271                 elif value == _("MediaPlayer"):
272                         return "3"
273                 elif value == _("Plugin browser"):
274                         return "4"
275                 elif value == _("switch 4:3 content display"):
276                         return "5"
277                 elif value == _("Timer"):
278                         return "6"
279                 elif value == _("HbbTV Applications"):
280                         return "7"
281                 else:
282                         return "0"
283
284         def keyLeft(self):
285                 ConfigListScreen.keyLeft(self)
286                 self.newConfig()
287
288         def keyRight(self):
289                 ConfigListScreen.keyRight(self)
290                 self.newConfig()
291
292         def newConfig(self):
293                 cur = self["config"].getCurrent()
294                 if cur and (cur == self.overwriteHBBTVButtonEntry):
295                         self.createSetup("config")
296
297         def keySave(self):
298                 config.plugins.Quickbutton.red.value = self.entryguilist[int(self.redchoice.value)][1]
299                 config.plugins.Quickbutton.green.value = self.entryguilist[int(self.greenchoice.value)][1]
300                 config.plugins.Quickbutton.yellow.value = self.entryguilist[int(self.yellowchoice.value)][1]
301                 config.plugins.Quickbutton.blue.value = self.entryguilist[int(self.bluechoice.value)][1]
302                 if ENABLE_RED_BUTTON and (self.overwriteHBBTVButton.value or not self.hbbtvinstalled):
303                         config.plugins.Quickbutton.red_b.value = self.entryguilist[int(self.red_b_choice.value)][1]
304                 self.overwriteHBBTVButton.save()
305                 config.plugins.Quickbutton.save()
306                 configfile.save()
307                 self.close()
308
309         def keyClose(self):
310                 self.close()