pluginhider: add eventinfo support and rework setup dialog
[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.Setup import SetupSummary
7
8 # GUI (Components)
9 from Components.ActionMap import ActionMap
10 from Components.SelectionList import SelectionList, SelectionEntryComponent
11 from Components.Sources.StaticText import StaticText
12 from Components.Pixmap import MultiPixmap
13
14 # Configuration
15 from Components.config import config
16
17 from Components.PluginComponent import plugins
18 from Plugins.Plugin import PluginDescriptor
19
20 LIST_PLUGINS = 0
21 LIST_EXTENSIONS = 1
22 LIST_EVENTINFO = 2
23 class PluginHiderSetup(Screen):
24         skin = """<screen name="PluginHiderSetup" title="PluginHider Setup" position="center,center" size="565,395">
25                 <ePixmap position="0,358" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
26                 <ePixmap position="140,358" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
27                 <ePixmap position="280,358" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
28                 <ePixmap position="420,358" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
29                 <widget source="key_red" render="Label" position="0,358" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
30                 <widget source="key_green" render="Label" position="140,358" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget source="key_yellow" render="Label" position="280,358" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32                 <widget source="key_blue" render="Label" position="420,358" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
33                 <ePixmap size="551,336" alphatest="on" position="5,21" pixmap="skin_default/border_epg.png" zPosition="3" />
34                 <widget size="320,25" alphatest="on" position="5,1" zPosition="1" name="tabbar" pixmaps="skin_default/epg_now.png,skin_default/epg_next.png,skin_default/epg_more.png" />
35                 <widget valign="center" transparent="1" size="108,22" backgroundColor="#25062748" position="5,1" zPosition="2" source="plugins" render="Label" halign="center" font="Regular;18" />
36                 <widget valign="center" transparent="1" size="108,22" backgroundColor="#25062748" position="111,1" zPosition="2" source="extensions" render="Label" halign="center" font="Regular;18" />
37                 <widget valign="center" transparent="1" size="108,22" backgroundColor="#25062748" position="216,1" zPosition="2" source="eventinfo" render="Label" halign="center" font="Regular;18" />
38                 <widget name="list" position="11,26" size="540,330" scrollbarMode="showOnDemand" />
39         </screen>"""
40
41         def __init__(self, session):
42                 Screen.__init__(self, session)
43
44                 # Initialize widgets
45                 self["key_green"] = StaticText(_("OK"))
46                 self["key_red"] = StaticText(_("Cancel"))
47                 self["key_yellow"] = StaticText(_("Previous"))
48                 self["key_blue"] = StaticText(_("Next"))
49                 self["plugins"] = StaticText(_("Plugins"))
50                 self["extensions"] = StaticText(_("Extensions"))
51                 self["eventinfo"] = StaticText(_("Eventinfo"))
52                 self["tabbar"] = MultiPixmap()
53
54                 self["list"] = SelectionList([])
55                 self.selectedList = LIST_PLUGINS
56                 self.updateList()
57
58                 self["ColorActions"] = ActionMap(["OkCancelActions", "ColorActions"],
59                         {
60                                 "ok": self["list"].toggleSelection,
61                                 "cancel": self.cancel,
62                                 "red": self.cancel,
63                                 "green": self.save,
64                                 "yellow": self.previous,
65                                 "blue": self.next,
66                         }, -1
67                 )
68
69                 self.onLayoutFinish.append(self.setCustomTitle)
70
71         def cancel(self):
72                 config.plugins.pluginhider.hideplugins.cancel()
73                 config.plugins.pluginhider.hideextensions.cancel()
74                 self.close()
75
76         def save(self):
77                 self.keepCurrent()
78                 config.plugins.pluginhider.save()
79                 self.close()
80
81         def previous(self):
82                 self.keepCurrent()
83                 self.selectedList -= 1
84                 if self.selectedList < 0:
85                         self.selectedList = LIST_EVENTINFO
86                 self.updateList()
87
88         def next(self):
89                 self.keepCurrent()
90                 self.selectedList += 1
91                 if self.selectedList > LIST_EVENTINFO:
92                         self.selectedList = LIST_PLUGINS
93                 self.updateList()
94
95         def setCustomTitle(self):
96                 self.setTitle(_("PluginHider Setup"))
97
98         def updateList(self):
99                 if hasattr(plugins, 'pluginHider_baseGetPlugins'):
100                         fnc = plugins.pluginHider_baseGetPlugins
101                 else:
102                         fnc = plugins.getPlugins
103
104                 if self.selectedList == LIST_PLUGINS:
105                         list = fnc([PluginDescriptor.WHERE_PLUGINMENU])
106                         selected = config.plugins.pluginhider.hideplugins.value
107                 elif self.selectedList == LIST_EXTENSIONS:
108                         list = fnc([PluginDescriptor.WHERE_EXTENSIONSMENU])
109                         selected = config.plugins.pluginhider.hideextensions.value
110                 else: #if self.selectedList == LIST_EVENTINFO:
111                         list = fnc([PluginDescriptor.WHERE_EVENTINFO])
112                         selected = config.plugins.pluginhider.hideeventinfo.value
113                 self["tabbar"].setPixmapNum(self.selectedList)
114
115                 res = []
116                 i = 0
117                 for plugin in list:
118                         if plugin.description:
119                                 name = "%s (%s)" % (plugin.name, plugin.description)
120                         else:
121                                 name = plugin.name
122
123                         res.append(SelectionEntryComponent(
124                                         name,
125                                         plugin.name,
126                                         i,
127                                         plugin.name in selected,
128                         ))
129                         i += 1
130                 self["list"].setList(res)
131                 if res:
132                         self["list"].moveToIndex(0)
133
134         def keepCurrent(self):
135                 selected = self["list"].getSelectionsList()
136                 if self.selectedList == LIST_PLUGINS:
137                         config.plugins.pluginhider.hideplugins.value = [x[1] for x in selected]
138                 elif self.selectedList == LIST_EXTENSIONS:
139                         config.plugins.pluginhider.hideextensions.value = [x[1] for x in selected]
140                 else: #if self.selectedList == LIST_EVENTINFO:
141                         config.plugins.pluginhider.hideeventinfo.value = [x[1] for x in selected]