add multi epg to quickbutton options
[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 baserunPlugin = None
46 StartOnlyOneTime = False
47 DM8000 = False
48
49
50 def autostart(reason, **kwargs):
51         global baseInfoBarPlugins__init__, baserunPlugin, DM8000
52         if "session" in kwargs:
53                 session = kwargs["session"]
54                 if baseInfoBarPlugins__init__ is None:
55                         baseInfoBarPlugins__init__ = InfoBarPlugins.__init__
56                 if baserunPlugin is None:
57                         baserunPlugin = InfoBarPlugins.runPlugin
58                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
59                 InfoBarPlugins.runPlugin = runPlugin
60                 InfoBarPlugins.greenlong = greenlong
61                 InfoBarPlugins.yellowlong = yellowlong
62                 InfoBarPlugins.redlong = redlong
63                 InfoBarPlugins.bluelong = bluelong
64                 if HardwareInfo().get_device_name() == "dm8000":
65                         DM8000 = 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], fnc=setup))
75         return list
76
77 def InfoBarPlugins__init__(self):
78         global StartOnlyOneTime
79         if not StartOnlyOneTime: 
80                 StartOnlyOneTime = True
81                 x = {   "green_l": (self.greenlong, _("Assign plugin to long green key pressed")),
82                         "yellow_l": (self.yellowlong, _("Assign plugin to long yellow key pressed")),
83                         "red_l": (self.redlong, _("Assign plugin to long red key pressed")),
84                         "blue_l": (self.bluelong, _("Assign plugin to long blue key pressed"))}
85                 if DM8000:
86                         x["red_b"] = (self.red, _("Assign plugin to red key pressed"))
87                 self["QuickbuttonActions"] = HelpableActionMap(self, "QuickbuttonActions",x)
88         else:
89                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
90                 InfoBarPlugins.runPlugin = InfoBarPlugins.runPlugin
91                 InfoBarPlugins.greenlong = None
92                 InfoBarPlugins.yellowlong = None
93                 InfoBarPlugins.redlong = None
94                 InfoBarPlugins.bluelong = None
95                 if DM8000:
96                         InfoBarPlugins.red = None
97         baseInfoBarPlugins__init__(self)
98
99 def runPlugin(self, plugin):
100         baserunPlugin(self,plugin)
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                 else:
156                         plugin = None
157                         for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU]):
158                                 if pname == str(p.name):
159                                         plugin = p
160                         if plugin is not None:
161                                 try:
162                                         runPlugin(self,plugin)
163                                         no_plugin = False
164                                 except Exception, e:
165                                         msgText = _("Error!\nError Text: %s"%e)
166                         else: 
167                                 msgText = _("Plugin not found!")
168         else:
169                 msgText = _("No plugin assigned!")
170         if no_plugin:
171                 self.session.open(MessageBox,msgText, MessageBox.TYPE_INFO)
172
173
174 class QuickbuttonSetup(ConfigListScreen, Screen):
175         skin = """
176                 <screen position="center,center" size="550,400" title="Quickbutton Setup" >
177                         <widget name="config" position="20,10" size="510,330" scrollbarMode="showOnDemand" />
178                         <widget name="key_red" position="0,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
179                         <widget name="key_green" position="140,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
180                         <ePixmap name="red" pixmap="skin_default/buttons/red.png" position="0,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
181                         <ePixmap name="green" pixmap="skin_default/buttons/green.png" position="140,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
182                 </screen>"""
183
184         def __init__(self, session, args = None):
185                 Screen.__init__(self, session)
186                 self["key_red"] = Button(_("Cancel"))
187                 self["key_green"] = Button(_("OK"))
188                 self.entryguilist = []
189                 red_b_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.red_b.value)
190                 red_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.red.value)
191                 green_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.green.value)
192                 yellow_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.yellow.value)
193                 blue_selectedindex = self.getStaticPluginName(config.plugins.Quickbutton.blue.value)
194                 # feste Vorgaben...koennte man noch erweitern, da hole ich mir sinnvolle Vorschlaege aus Foren noch ein...
195                 self.entryguilist.append(("0",_("Nothing")))
196                 self.entryguilist.append(("1",_("Single EPG")))
197                 self.entryguilist.append(("2",_("Multi EPG")))
198                 self.entryguilist.append(("3",_("MediaPlayer")))
199                 self.entryguilist.append(("4",_("Plugin browser")))
200                 self.entryguilist.append(("5",_("switch 4:3 content display")))
201                 self.entryguilist.append(("6",_("Timer")))
202                 # Vorgaben aus EXTENSIONSMENU, PLUGINMENU
203                 index = 7
204                 for p in plugins.getPlugins(where = [PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU]):
205                         self.entryguilist.append((str(index),str(p.name)))
206                         if config.plugins.Quickbutton.red.value == str(p.name):
207                                 red_selectedindex = str(index)
208                         if config.plugins.Quickbutton.red_b.value == str(p.name):
209                                 red_b_selectedindex = str(index)
210                         if config.plugins.Quickbutton.green.value == str(p.name):
211                                 green_selectedindex = str(index)
212                         if config.plugins.Quickbutton.yellow.value == str(p.name):
213                                 yellow_selectedindex = str(index)
214                         if config.plugins.Quickbutton.blue.value == str(p.name):
215                                 blue_selectedindex = str(index)
216                         index = index + 1
217
218                 self.redchoice = ConfigSelection(default = red_selectedindex, choices = self.entryguilist)
219                 self.greenchoice = ConfigSelection(default = green_selectedindex, choices = self.entryguilist)
220                 self.yellowchoice = ConfigSelection(default = yellow_selectedindex, choices = self.entryguilist)
221                 self.bluechoice = ConfigSelection(default = blue_selectedindex, choices = self.entryguilist)
222                 cfglist = [
223                         getConfigListEntry(_("assigned to long red"), self.redchoice),
224                         getConfigListEntry(_("assigned to long green"), self.greenchoice),
225                         getConfigListEntry(_("assigned to long yellow"), self.yellowchoice),
226                         getConfigListEntry(_("assigned to long blue"), self.bluechoice)
227
228                         ]
229                 if DM8000:
230                         self.red_b_choice = ConfigSelection(default = red_b_selectedindex, choices = self.entryguilist)
231                         cfglist.append(getConfigListEntry(_("assigned to red"), self.red_b_choice))
232                 ConfigListScreen.__init__(self, cfglist, session)
233                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
234                 {
235                         "green": self.keySave,
236                         "cancel": self.keyClose,
237                         "ok": self.keySave,
238                 }, -2)
239
240         def getStaticPluginName(self,value):
241                 if value == _("Single EPG"):
242                         return "1"
243                 elif value == _("Multi EPG"):
244                         return "2"
245                 elif value == _("MediaPlayer"):
246                         return "3"
247                 elif value == _("Plugin browser"):
248                         return "4"
249                 elif value == _("switch 4:3 content display"):
250                         return "5"
251                 if value == _("Timer"):
252                         return "6"
253                 else:
254                         return "0"
255
256         def keySave(self):
257                 config.plugins.Quickbutton.red.value = self.entryguilist[int(self.redchoice.value)][1]
258                 config.plugins.Quickbutton.green.value = self.entryguilist[int(self.greenchoice.value)][1]
259                 config.plugins.Quickbutton.yellow.value = self.entryguilist[int(self.yellowchoice.value)][1]
260                 config.plugins.Quickbutton.blue.value = self.entryguilist[int(self.bluechoice.value)][1]
261                 if DM8000:
262                         config.plugins.Quickbutton.red_b.value = self.entryguilist[int(self.red_b_choice.value)][1]
263                 config.plugins.Quickbutton.save()
264                 configfile.save()
265                 self.close()
266
267         def keyClose(self):
268                 self.close()