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