1 from Screen import Screen
3 from enigma import eConsoleAppContainer, loadPNG
5 from Components.MenuList import MenuList
6 from Components.ActionMap import ActionMap
7 from Components.PluginComponent import plugins
8 from Components.PluginList import *
9 from Components.config import config
10 from Components.Label import Label
11 from Screens.MessageBox import MessageBox
12 from Screens.Console import Console
13 from Plugins.Plugin import PluginDescriptor
14 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
16 class PluginBrowser(Screen):
17 def __init__(self, session):
18 Screen.__init__(self, session)
20 self["red"] = Label(_("Remove Plugins"))
21 self["green"] = Label(_("Download Plugins"))
24 self["list"] = PluginList(self.list)
27 self["actions"] = ActionMap(["WizardActions", "ColorActions"],
32 "green": self.download
34 self.onExecBegin.append(self.checkWarnings)
36 def checkWarnings(self):
37 if len(plugins.warnings):
38 text = _("Some plugins are not available:\n")
39 for (pluginname, error) in plugins.warnings:
40 text += _("%s (%s)\n") % (pluginname, error)
41 plugins.resetWarnings()
42 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
49 plugin = self["list"].l.getCurrentSelection()[0]
51 plugin(session=self.session)
55 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
56 for plugin in self.pluginlist:
57 self.list.append(PluginEntryComponent(plugin))
59 self["list"].l.setList(self.list)
62 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
65 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
67 class PluginDownloadBrowser(Screen):
71 def __init__(self, session, type):
72 Screen.__init__(self, session)
76 self.container = eConsoleAppContainer()
77 self.container.appClosed.get().append(self.runFinished)
78 self.container.dataAvail.get().append(self.dataAvail)
79 self.onLayoutFinish.append(self.startRun)
80 self.onShown.append(self.setWindowTitle)
83 self["list"] = PluginList(self.list)
86 self.installedplugins = []
88 if self.type == self.DOWNLOAD:
89 self["text"] = Label(_("Downloading plugin information. Please wait..."))
90 elif self.type == self.REMOVE:
91 self["text"] = Label(_("Getting plugin information. Please wait..."))
95 self["actions"] = ActionMap(["WizardActions"],
102 if type(self["list"].l.getCurrentSelection()[0]) is str: # category
103 if self["list"].l.getCurrentSelection()[0] in self.expanded:
104 self.expanded.remove(self["list"].l.getCurrentSelection()[0])
106 self.expanded.append(self["list"].l.getCurrentSelection()[0])
109 if self.type == self.DOWNLOAD:
110 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
111 elif self.type == self.REMOVE:
112 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
114 def runInstall(self, val):
116 if self.type == self.DOWNLOAD:
117 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
118 elif self.type == self.REMOVE:
119 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
121 def setWindowTitle(self):
122 if self.type == self.DOWNLOAD:
123 self.setTitle(_("Downloadable new plugins"))
124 elif self.type == self.REMOVE:
125 self.setTitle(_("Remove plugins"))
128 self["list"].instance.hide()
129 if self.type == self.DOWNLOAD:
130 self.container.execute("ipkg update")
131 elif self.type == self.REMOVE:
133 self.container.execute("ipkg list_installed enigma2-plugin-*")
135 def installFinished(self):
136 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
139 def runFinished(self, retval):
142 if self.type == self.DOWNLOAD:
143 self.container.execute("ipkg list_installed enigma2-plugin-*")
144 elif self.run == 1 and self.type == self.DOWNLOAD:
146 self.container.execute("ipkg list enigma2-plugin-*")
148 if len(self.pluginlist) > 0:
150 self["list"].instance.show()
152 self["text"].setText("No new plugins found")
154 def dataAvail(self, str):
155 for x in str.split('\n'):
156 plugin = x.split(" - ")
158 if self.run == 1 and self.type == self.DOWNLOAD:
159 self.installedplugins.append(plugin[0])
161 if plugin[0] not in self.installedplugins:
162 plugin.append(plugin[0][15:])
164 self.pluginlist.append(plugin)
166 def updateList(self):
168 expandableIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expandable-plugins.png"))
169 expandedIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expanded-plugins.png"))
170 verticallineIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "verticalline-plugins.png"))
173 for x in self.pluginlist:
174 split = x[3].split('-')
177 if not self.plugins.has_key(split[0]):
178 self.plugins[split[0]] = []
180 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
182 for x in self.plugins.keys():
183 if x in self.expanded:
184 self.list.append(PluginCategoryComponent(x, expandedIcon))
185 for plugin in self.plugins[x]:
186 self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
188 self.list.append(PluginCategoryComponent(x, expandableIcon))
189 self["list"].l.setList(self.list)