PluginHiderSetup: fix skin
[enigma2-plugins.git] / pluginhider / src / PluginHiderSetup.py
1 from . import _
2
3 # GUI (Screens)
4 from Screens.Screen import Screen
5 from Components.ConfigList import ConfigListScreen
6
7 # GUI (Summary)
8 from Screens.HelpMenu import HelpableScreen
9 from Screens.MessageBox import MessageBox
10 from Screens.Setup import SetupSummary
11
12 # GUI (Components)
13 from Components.ActionMap import HelpableActionMap
14 from Components.SelectionList import SelectionList, SelectionEntryComponent
15 from Components.Sources.StaticText import StaticText
16 from Components.Pixmap import MultiPixmap
17
18 # Configuration
19 from Components.config import config
20
21 from Components.PluginComponent import plugins
22 from Plugins.Plugin import PluginDescriptor
23
24 import inspect
25
26 LIST_PLUGINS = 0
27 LIST_EXTENSIONS = 1
28 LIST_EVENTINFO = 2
29 class PluginHiderSetup(Screen, HelpableScreen):
30         skin = """<screen name="PluginHiderSetup" title="PluginHider Setup" position="center,120" size="820,520">
31                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" alphatest="on" />
32                 <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" alphatest="on" />
33                 <ePixmap pixmap="skin_default/buttons/blue.png" position="610,5" size="200,40" alphatest="on" />
34                 <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
35                 <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
36                 <widget source="key_blue" render="Label" position="610,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
37                 <widget name="list" position="10,93" size="800,420" enableWrapAround="1" scrollbarMode="showOnDemand" />
38                 <widget position="0,50" zPosition="1" size="950,35" name="tabbar" pixmaps="skin_default/epg_now.png,skin_default/epg_next.png,skin_default/epg_more.png" />
39                 <widget source="plugins" render="Label" position="31,55" zPosition="2" size="200,25" font="Regular;20" halign="center" valign="center" backgroundColor="background" transparent="1" />
40                 <widget source="extensions" render="Label" position="231,55" zPosition="2" size="200,25" font="Regular;20" halign="center" valign="center" backgroundColor="background" transparent="1" />
41                 <widget source="eventinfo" render="Label" position="431,55" zPosition="2" size="200,25" font="Regular;20" halign="center" valign="center" backgroundColor="background" transparent="1" />
42         </screen>"""
43
44         def __init__(self, session):
45                 Screen.__init__(self, session)
46                 HelpableScreen.__init__(self)
47
48                 # Initialize widgets
49                 self["key_green"] = StaticText(_("OK"))
50                 self["key_red"] = StaticText(_("Cancel"))
51                 self["key_yellow"] = StaticText("")
52                 self["key_blue"] = StaticText(_("Run"))
53                 self["plugins"] = StaticText(_("Plugins"))
54                 self["extensions"] = StaticText(_("Extensions"))
55                 self["eventinfo"] = StaticText(_("Eventinfo"))
56                 self["tabbar"] = MultiPixmap()
57
58                 self["list"] = SelectionList([])
59                 self.selectedList = LIST_PLUGINS
60                 self.updateList()
61
62                 self["PluginHiderSetupActions"] = HelpableActionMap(self, "PluginHiderSetupActions",
63                         {
64                                 "ok": (self["list"].toggleSelection, _("toggle selection")),
65                                 "cancel": (self.cancel, _("end editing")),
66                                 "green": (self.save, _("save")),
67                                 "blue": (self.run, _("run selected plugin")),
68                                 "next": (self.next, _("select next tab")),
69                                 "previous": (self.previous, _("select previous tab")),
70                         }, -1
71                 )
72
73                 self.onLayoutFinish.append(self.setCustomTitle)
74
75         def run(self):
76                 cur = self["list"].getCurrent()
77                 cur = cur and cur[0]
78                 if cur:
79                         plugin = cur[1]
80
81                         if self.selectedList == LIST_PLUGINS:
82                                 plugin(session=self.session)
83                         else: #if self.selectedList == LIST_EXTENSIONS or self.selectedList == LIST_EVENTINFO:
84                                 from Screens.InfoBar import InfoBar
85                                 instance = InfoBar.instance
86                                 args = inspect.getargspec(plugin.__call__)[0]
87                                 if len(args) == 1:
88                                         plugin(session=self.session)
89                                 elif instance and instance.servicelist:
90                                         plugin(session=self.session,servicelist=instance.servicelist)
91                                 else:
92                                         session.open(MessageBox, _("Could not start Plugin:") + "\n" + _("Unable to access InfoBar."), type=MessageBox.TYPE_ERROR)
93
94         def cancel(self):
95                 config.plugins.pluginhider.hideplugins.cancel()
96                 config.plugins.pluginhider.hideextensions.cancel()
97                 self.close()
98
99         def save(self):
100                 self.keepCurrent()
101                 config.plugins.pluginhider.save()
102                 self.close()
103
104         def previous(self):
105                 self.keepCurrent()
106                 self.selectedList -= 1
107                 if self.selectedList < 0:
108                         self.selectedList = LIST_EVENTINFO
109                 self.updateList()
110
111         def next(self):
112                 self.keepCurrent()
113                 self.selectedList += 1
114                 if self.selectedList > LIST_EVENTINFO:
115                         self.selectedList = LIST_PLUGINS
116                 self.updateList()
117
118         def setCustomTitle(self):
119                 self.setTitle(_("PluginHider Setup"))
120
121         def updateList(self):
122                 if hasattr(plugins, 'pluginHider_baseGetPlugins'):
123                         fnc = plugins.pluginHider_baseGetPlugins
124                 else:
125                         fnc = plugins.getPlugins
126
127                 if self.selectedList == LIST_PLUGINS:
128                         list = fnc([PluginDescriptor.WHERE_PLUGINMENU])
129                         selected = config.plugins.pluginhider.hideplugins.value
130                 elif self.selectedList == LIST_EXTENSIONS:
131                         list = fnc([PluginDescriptor.WHERE_EXTENSIONSMENU])
132                         selected = config.plugins.pluginhider.hideextensions.value
133                 else: #if self.selectedList == LIST_EVENTINFO:
134                         list = fnc([PluginDescriptor.WHERE_EVENTINFO])
135                         selected = config.plugins.pluginhider.hideeventinfo.value
136                 self["tabbar"].setPixmapNum(self.selectedList)
137
138                 res = []
139                 i = 0
140                 for plugin in list:
141                         if plugin.description:
142                                 name = "%s (%s)" % (plugin.name, plugin.description)
143                         else:
144                                 name = plugin.name
145
146                         res.append(SelectionEntryComponent(
147                                         name,
148                                         plugin,
149                                         i,
150                                         plugin.name in selected,
151                         ))
152                         i += 1
153                 self["list"].setList(res)
154                 if res:
155                         self["list"].moveToIndex(0)
156
157         def keepCurrent(self):
158                 selected = self["list"].getSelectionsList()
159                 if self.selectedList == LIST_PLUGINS:
160                         config.plugins.pluginhider.hideplugins.value = [x[1].name for x in selected]
161                 elif self.selectedList == LIST_EXTENSIONS:
162                         config.plugins.pluginhider.hideextensions.value = [x[1].name for x in selected]
163                 else: #if self.selectedList == LIST_EVENTINFO:
164                         config.plugins.pluginhider.hideeventinfo.value = [x[1].name for x in selected]