[WebInterface] - forward opener for externals to have access to functions of WebInterface
[enigma2-plugins.git] / pluginhider / src / PluginHiderSetup.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4
5 # GUI (Summary)
6 from Screens.HelpMenu import HelpableScreen
7 from Screens.MessageBox import MessageBox
8 from Screens.Setup import SetupSummary
9
10 # GUI (Components)
11 from Components.ActionMap import HelpableActionMap
12 from Components.SelectionList import SelectionList, SelectionEntryComponent
13 from Components.Sources.StaticText import StaticText
14 from Components.Label import Label, MultiColorLabel
15
16 # Configuration
17 from Components.config import config
18
19 from Components.PluginComponent import plugins
20 from Plugins.Plugin import PluginDescriptor
21
22 import inspect
23 from enigma import getDesktop
24
25 LIST_PLUGINS = 0
26 LIST_EXTENSIONS = 1
27 LIST_EVENTINFO = 2
28 LIST_MOVIELIST = 3
29
30 sz_w = getDesktop(0).size().width()
31
32 class PluginHiderSetup(Screen, HelpableScreen):
33
34         if sz_w == 1920:
35                 skin = """<screen name="PluginHiderSetup_New" position="center,170" size="1200,820" title="PluginHider Setup">
36                         <ePixmap pixmap="Default-FHD/skin_default/buttons/red.svg" position="10,5" scale="stretch" size="350,70" />
37                         <ePixmap pixmap="Default-FHD/skin_default/buttons/green.svg" position="360,5" scale="stretch" size="350,70" />
38                         <ePixmap pixmap="Default-FHD/skin_default/buttons/blue.svg" position="710,5" scale="stretch" size="350,70" />
39                         <widget backgroundColor="#9f1313" font="Regular;30" halign="center" position="10,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="350,70" source="key_red" transparent="1" valign="center" zPosition="1" />
40                         <widget backgroundColor="#1f771f" font="Regular;30" halign="center" position="360,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="350,70" source="key_green" transparent="1" valign="center" zPosition="1" />
41                         <widget backgroundColor="#18188b" font="Regular;30" halign="center" position="710,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="350,70" source="key_blue" transparent="1" valign="center" zPosition="1" />
42                         <ePixmap pixmap="Default-FHD/skin_default/icons/help.svg" position="1110,30" size="80,40" />
43                         <eLabel backgroundColor="grey" position="10,80" size="1180,1" />
44                         <widget enableWrapAround="1" name="list" position="10,140" scrollbarMode="showOnDemand" size="1180,675" />
45                         <widget name="plugins" position="17,88" zPosition="2" size="285,35" font="Regular;28" halign="center" valign="center" />
46                         <widget name="extensions" position="312,88" zPosition="2" size="285,35" font="Regular;28" halign="center" valign="center" />
47                         <widget name="eventinfo" position="607,88" zPosition="2" size="285,35" font="Regular;28" halign="center" valign="center" />
48                         <widget name="movielist" position="902,88" zPosition="2" size="285,35" font="Regular;28" halign="center" valign="center" />
49                         <widget name="selectedlistColors" backgroundColors="#777777,background" foregroundColors="foreground,yellow"/>
50                         <eLabel backgroundColor="grey" position="10,130" size="1180,2" />
51                 </screen>"""
52         else:
53                 skin = """<screen name="PluginHiderSetup_New" title="PluginHider Setup" position="center,120" size="820,520">
54                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" />
55                         <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" />
56                         <ePixmap pixmap="skin_default/buttons/blue.png" position="410,5" size="200,40" />
57                         <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" foregroundColor="white" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
58                         <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" foregroundColor="white" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
59                         <widget source="key_blue" render="Label" position="410,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" foregroundColor="white" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
60                         <ePixmap pixmap="skin_default/icons/help.png" position="750,15" size="60,30" />
61                         <widget name="list" position="10,93" size="800,420" enableWrapAround="1" scrollbarMode="showOnDemand" />
62                         <eLabel backgroundColor="grey" position="10,50" size="800,1" />
63                         <widget name="plugins" position="12,55" zPosition="2" size="195,25" font="Regular;20" halign="center" valign="center"/>
64                         <widget name="extensions" position="212,55" zPosition="2" size="195,25" font="Regular;20" halign="center" valign="center"/>
65                         <widget name="eventinfo" position="412,55" zPosition="2" size="195,25" font="Regular;20" halign="center" valign="center"/>
66                         <widget name="movielist" position="612,55" zPosition="2" size="195,25" font="Regular;20" halign="center" valign="center"/>
67                         <widget name="selectedlistColors" backgroundColors="#777777,background" foregroundColors="foreground,yellow"/>
68                         <eLabel backgroundColor="grey" position="10,85" size="800,1" />
69                 </screen>"""
70
71         def __init__(self, session):
72                 Screen.__init__(self, session)
73                 HelpableScreen.__init__(self)
74                 self.skinName="PluginHiderSetup_New"
75
76                 # Initialize widgets
77                 self["key_green"] = StaticText(_("OK"))
78                 self["key_red"] = StaticText(_("Cancel"))
79                 self["key_yellow"] = StaticText("")
80                 self["key_blue"] = StaticText(_("Run"))
81                 self["plugins"] = Label(_("Pluginbrowser"))
82                 self["extensions"] = Label(_("Extensions"))
83                 self["eventinfo"] = Label(_("Eventinfo"))
84                 self["movielist"] = Label(_("Movielist"))
85                 self["selectedlistColors"] = MultiColorLabel()
86
87                 self["list"] = SelectionList([])
88                 self.selectedList = LIST_PLUGINS
89
90                 self["PluginHiderSetupActions"] = HelpableActionMap(self, "PluginHiderSetupActions",
91                         {
92                                 "ok": (self["list"].toggleSelection, _("toggle selection")),
93                                 "cancel": (self.cancel, _("end editing")),
94                                 "green": (self.save, _("save")),
95                                 "blue": (self.run, _("run selected plugin")),
96                                 "next": (self.next, _("select next tab")),
97                                 "previous": (self.previous, _("select previous tab")),
98                         }, -1
99                 )
100
101                 self.onLayoutFinish.append(self.setCustomTitle)
102
103         def run(self):
104                 cur = self["list"].getCurrent()
105                 cur = cur and cur[0]
106                 if cur:
107                         plugin = cur[1]
108
109                         if self.selectedList == LIST_PLUGINS:
110                                 plugin(session=self.session)
111                         elif self.selectedList == LIST_MOVIELIST:
112                                         self.session.open(MessageBox, _("Could not start Plugin:") + "\n" + _("Could start only from the movie-menu."), type=MessageBox.TYPE_ERROR)
113                         else: #if self.selectedList == LIST_EXTENSIONS or self.selectedList == LIST_EVENTINFO:
114                                 from Screens.InfoBar import InfoBar
115                                 instance = InfoBar.instance
116                                 args = inspect.getargspec(plugin.__call__)[0]
117                                 if len(args) == 1:
118                                         plugin(session=self.session)
119                                 elif instance and instance.servicelist:
120                                         plugin(session=self.session,servicelist=instance.servicelist)
121                                 else:
122                                         session.open(MessageBox, _("Could not start Plugin:") + "\n" + _("Unable to access InfoBar."), type=MessageBox.TYPE_ERROR)
123
124         def cancel(self):
125                 config.plugins.pluginhider.hideplugins.cancel()
126                 config.plugins.pluginhider.hideextensions.cancel()
127                 config.plugins.pluginhider.hideeventinfo.cancel()
128                 config.plugins.pluginhider.hidemovielist.cancel()
129                 self.close()
130
131         def save(self):
132                 self.keepCurrent()
133                 config.plugins.pluginhider.save()
134                 self.close()
135
136         def previous(self):
137                 self.keepCurrent()
138                 self.selectedList -= 1
139                 if self.selectedList < 0:
140                         self.selectedList = LIST_MOVIELIST
141                 self.updateList()
142
143         def next(self):
144                 self.keepCurrent()
145                 self.selectedList += 1
146                 if self.selectedList > LIST_MOVIELIST:
147                         self.selectedList = LIST_PLUGINS
148                 self.updateList()
149
150         def setCustomTitle(self):
151                 self.setTitle(_("PluginHider Setup"))
152                 self.updateList()
153
154         def updateSelectedColor(self):
155                 
156                 try:
157                         pluginColor=extensionsColor=eventinfoColor=movielistColor=0
158                         
159                         if self.selectedList == 0: 
160                                 pluginColor=1
161                         elif self.selectedList == 1: 
162                                 extensionsColor=1
163                         elif self.selectedList == 2: 
164                                 eventinfoColor=1
165                         else: 
166                                 movielistColor=1
167                         
168                         self["plugins"].instance.setBackgroundColor(self["selectedlistColors"].backColors[pluginColor])
169                         self["plugins"].instance.setForegroundColor(self["selectedlistColors"].foreColors[pluginColor])
170                         self["plugins"].instance.invalidate()
171                         self['extensions'].instance.setBackgroundColor(self["selectedlistColors"].backColors[extensionsColor])
172                         self['extensions'].instance.setForegroundColor(self["selectedlistColors"].foreColors[extensionsColor])
173                         self['extensions'].instance.invalidate()
174                         self['eventinfo'].instance.setBackgroundColor(self["selectedlistColors"].backColors[eventinfoColor])
175                         self['eventinfo'].instance.setForegroundColor(self["selectedlistColors"].foreColors[eventinfoColor])
176                         self['eventinfo'].instance.invalidate()
177                         self['movielist'].instance.setBackgroundColor(self["selectedlistColors"].backColors[movielistColor])
178                         self['movielist'].instance.setForegroundColor(self["selectedlistColors"].foreColors[movielistColor])
179                         self['movielist'].instance.invalidate()
180                         
181                 except:
182                                 import traceback
183                                 traceback.print_exc()
184
185
186         def updateList(self):
187                 if hasattr(plugins, 'pluginHider_baseGetPlugins'):
188                         fnc = plugins.pluginHider_baseGetPlugins
189                 else:
190                         fnc = plugins.getPlugins
191
192                 if self.selectedList == LIST_PLUGINS:
193                         list = fnc([PluginDescriptor.WHERE_PLUGINMENU])
194                         selected = config.plugins.pluginhider.hideplugins.value
195                 elif self.selectedList == LIST_EXTENSIONS:
196                         list = fnc([PluginDescriptor.WHERE_EXTENSIONSMENU])
197                         selected = config.plugins.pluginhider.hideextensions.value
198                 elif self.selectedList == LIST_EVENTINFO:
199                         list = fnc([PluginDescriptor.WHERE_EVENTINFO])
200                         selected = config.plugins.pluginhider.hideeventinfo.value
201                 else: #if self.selectedList == LIST_MOVIELIST:
202                         list = fnc([PluginDescriptor.WHERE_MOVIELIST])
203                         selected = config.plugins.pluginhider.hidemovielist.value
204                 self.updateSelectedColor()
205
206                 res = []
207                 i = 0
208                 for plugin in list:
209                         if plugin.description:
210                                 name = "%s (%s)" % (plugin.name, plugin.description)
211                         else:
212                                 name = plugin.name
213
214                         res.append(SelectionEntryComponent(
215                                         name,
216                                         plugin,
217                                         i,
218                                         plugin.name in selected,
219                         ))
220                         i += 1
221                 self["list"].setList(res)
222                 if res:
223                         self["list"].moveToIndex(0)
224
225         def keepCurrent(self):
226                 selected = self["list"].getSelectionsList()
227                 if self.selectedList == LIST_PLUGINS:
228                         config.plugins.pluginhider.hideplugins.value = [x[1].name for x in selected]
229                 elif self.selectedList == LIST_EXTENSIONS:
230                         config.plugins.pluginhider.hideextensions.value = [x[1].name for x in selected]
231                 elif self.selectedList == LIST_EVENTINFO:
232                         config.plugins.pluginhider.hideeventinfo.value = [x[1].name for x in selected]
233                 else: #if self.selectedList == LIST_MOVIELIST:
234                         config.plugins.pluginhider.hidemovielist.value = [x[1].name for x in selected]