1 from Screen import Screen
3 from enigma import eConsoleAppContainer, loadPNG
5 from Components.ActionMap import ActionMap
6 from Components.PluginComponent import plugins
7 from Components.PluginList import *
8 from Components.Label import Label
9 from Screens.MessageBox import MessageBox
10 from Screens.Console import Console
11 from Plugins.Plugin import PluginDescriptor
12 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
14 class PluginBrowser(Screen):
15 def __init__(self, session):
16 Screen.__init__(self, session)
18 self["red"] = Label(_("Remove Plugins"))
19 self["green"] = Label(_("Download Plugins"))
22 self["list"] = PluginList(self.list)
25 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
30 "green": self.download
32 self.onExecBegin.append(self.checkWarnings)
34 def checkWarnings(self):
35 if len(plugins.warnings):
36 text = _("Some plugins are not available:\n")
37 for (pluginname, error) in plugins.warnings:
38 text += _("%s (%s)\n") % (pluginname, error)
39 plugins.resetWarnings()
40 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
47 plugin = self["list"].l.getCurrentSelection()[0]
49 plugin(session=self.session)
53 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
54 for plugin in self.pluginlist:
55 self.list.append(PluginEntryComponent(plugin))
57 self["list"].l.setList(self.list)
60 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
63 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
65 class PluginDownloadBrowser(Screen):
69 def __init__(self, session, type):
70 Screen.__init__(self, session)
74 self.container = eConsoleAppContainer()
75 self.container.appClosed.get().append(self.runFinished)
76 self.container.dataAvail.get().append(self.dataAvail)
77 self.onLayoutFinish.append(self.startRun)
78 self.onShown.append(self.setWindowTitle)
81 self["list"] = PluginList(self.list)
84 self.installedplugins = []
86 if self.type == self.DOWNLOAD:
87 self["text"] = Label(_("Downloading plugin information. Please wait..."))
88 elif self.type == self.REMOVE:
89 self["text"] = Label(_("Getting plugin information. Please wait..."))
93 self["actions"] = ActionMap(["WizardActions"],
100 sel = self["list"].l.getCurrentSelection()
105 if type(sel[0]) is str: # category
106 if sel[0] in self.expanded:
107 self.expanded.remove(sel[0])
109 self.expanded.append(sel[0])
112 if self.type == self.DOWNLOAD:
113 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + sel[0].name + "\"?"))
114 elif self.type == self.REMOVE:
115 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"" + sel[0].name + "\"?"))
117 def runInstall(self, val):
119 if self.type == self.DOWNLOAD:
120 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
121 elif self.type == self.REMOVE:
122 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
124 def setWindowTitle(self):
125 if self.type == self.DOWNLOAD:
126 self.setTitle(_("Downloadable new plugins"))
127 elif self.type == self.REMOVE:
128 self.setTitle(_("Remove plugins"))
131 self["list"].instance.hide()
132 if self.type == self.DOWNLOAD:
133 self.container.execute("ipkg update")
134 elif self.type == self.REMOVE:
136 self.container.execute("ipkg list_installed enigma2-plugin-*")
138 def installFinished(self):
139 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
142 def runFinished(self, retval):
145 if self.type == self.DOWNLOAD:
146 self.container.execute("ipkg list_installed enigma2-plugin-*")
147 elif self.run == 1 and self.type == self.DOWNLOAD:
149 self.container.execute("ipkg list enigma2-plugin-*")
151 if len(self.pluginlist) > 0:
153 self["list"].instance.show()
155 self["text"].setText("No new plugins found")
157 def dataAvail(self, str):
158 for x in str.split('\n'):
159 plugin = x.split(" - ")
161 if self.run == 1 and self.type == self.DOWNLOAD:
162 self.installedplugins.append(plugin[0])
164 if plugin[0] not in self.installedplugins:
165 plugin.append(plugin[0][15:])
167 self.pluginlist.append(plugin)
169 def updateList(self):
171 expandableIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expandable-plugins.png"))
172 expandedIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expanded-plugins.png"))
173 verticallineIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "verticalline-plugins.png"))
176 for x in self.pluginlist:
177 split = x[3].split('-')
180 if not self.plugins.has_key(split[0]):
181 self.plugins[split[0]] = []
183 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
185 for x in self.plugins.keys():
186 if x in self.expanded:
187 self.list.append(PluginCategoryComponent(x, expandedIcon))
188 for plugin in self.plugins[x]:
189 self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
191 self.list.append(PluginCategoryComponent(x, expandableIcon))
192 self["list"].l.setList(self.list)