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