1 from Screen import Screen
2 from Components.Language import language
3 from enigma import eConsoleAppContainer
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, fileExists, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
13 from Tools.LoadPixmap import LoadPixmap
17 def languageChanged():
18 plugins.clearPluginList()
19 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
21 class PluginBrowser(Screen):
22 def __init__(self, session):
23 Screen.__init__(self, session)
26 self["green"] = Label()
29 self["list"] = PluginList(self.list)
31 self["actions"] = ActionMap(["WizardActions"],
36 self["PluginDownloadActions"] = ActionMap(["ColorActions"],
39 "green": self.download
41 self["SoftwareActions"] = ActionMap(["ColorActions"],
43 "red": self.openExtensionmanager
45 self["PluginDownloadActions"].setEnabled(False)
46 self["SoftwareActions"].setEnabled(False)
47 self.onFirstExecBegin.append(self.checkWarnings)
48 self.onShown.append(self.updateList)
50 def checkWarnings(self):
51 if len(plugins.warnings):
52 text = _("Some plugins are not available:\n")
53 for (pluginname, error) in plugins.warnings:
54 text += _("%s (%s)\n") % (pluginname, error)
55 plugins.resetWarnings()
56 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
62 plugin = self["list"].l.getCurrentSelection()[0]
63 plugin(session=self.session)
66 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
67 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
68 self["list"].l.setList(self.list)
69 if fileExists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/plugin.py")):
70 self["red"].setText(_("Manage extensions"))
71 self["green"].setText("")
72 self["SoftwareActions"].setEnabled(True)
73 self["PluginDownloadActions"].setEnabled(False)
75 self["red"].setText(_("Remove Plugins"))
76 self["green"].setText(_("Download Plugins"))
77 self["SoftwareActions"].setEnabled(False)
78 self["PluginDownloadActions"].setEnabled(True)
81 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
84 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
86 def PluginDownloadBrowserClosed(self):
90 def openExtensionmanager(self):
91 if fileExists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/plugin.py")):
94 from Plugins.SystemPlugins.SoftwareManager.plugin import PluginManager
96 self.session.open(MessageBox, _("The Softwaremanagement extension is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
98 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginManager)
100 class PluginDownloadBrowser(Screen):
103 lastDownloadDate = None
105 def __init__(self, session, type):
106 Screen.__init__(self, session)
110 self.container = eConsoleAppContainer()
111 self.container.appClosed.append(self.runFinished)
112 self.container.dataAvail.append(self.dataAvail)
113 self.onLayoutFinish.append(self.startRun)
114 self.onShown.append(self.setWindowTitle)
117 self["list"] = PluginList(self.list)
120 self.installedplugins = []
122 if self.type == self.DOWNLOAD:
123 self["text"] = Label(_("Downloading plugin information. Please wait..."))
124 elif self.type == self.REMOVE:
125 self["text"] = Label(_("Getting plugin information. Please wait..."))
129 self.remainingdata = ""
131 self["actions"] = ActionMap(["WizardActions"],
138 sel = self["list"].l.getCurrentSelection()
144 if isinstance(sel, str): # category
145 if sel in self.expanded:
146 self.expanded.remove(sel)
148 self.expanded.append(sel)
151 if self.type == self.DOWNLOAD:
152 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
153 elif self.type == self.REMOVE:
154 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
156 def runInstall(self, val):
158 if self.type == self.DOWNLOAD:
159 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
160 elif self.type == self.REMOVE:
161 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
163 def setWindowTitle(self):
164 if self.type == self.DOWNLOAD:
165 self.setTitle(_("Downloadable new plugins"))
166 elif self.type == self.REMOVE:
167 self.setTitle(_("Remove plugins"))
169 def startIpkgListInstalled(self):
170 self.container.execute("ipkg list_installed enigma2-plugin-*")
172 def startIpkgListAvailable(self):
173 self.container.execute("ipkg list enigma2-plugin-*")
176 self["list"].instance.hide()
177 if self.type == self.DOWNLOAD:
178 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
179 # Only update from internet once per hour
180 self.container.execute("ipkg update")
181 PluginDownloadBrowser.lastDownloadDate = time()
183 self.startIpkgListAvailable()
184 elif self.type == self.REMOVE:
186 self.startIpkgListInstalled()
188 def installFinished(self):
189 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
190 self.container.appClosed.remove(self.runFinished)
191 self.container.dataAvail.remove(self.dataAvail)
194 def runFinished(self, retval):
195 self.remainingdata = ""
198 if self.type == self.DOWNLOAD:
199 self.startIpkgListInstalled()
200 elif self.run == 1 and self.type == self.DOWNLOAD:
202 self.startIpkgListAvailable()
204 if len(self.pluginlist) > 0:
206 self["list"].instance.show()
208 self["text"].setText("No new plugins found")
210 def dataAvail(self, str):
211 #prepend any remaining data from the previous call
212 str = self.remainingdata + str
214 lines = str.split('\n')
215 #'str' should end with '\n', so when splitting, the last line should be empty. If this is not the case, we received an incomplete line
217 #remember this data for next time
218 self.remainingdata = lines[-1]
221 self.remainingdata = ""
224 plugin = x.split(" - ", 2)
226 if self.run == 1 and self.type == self.DOWNLOAD:
227 if plugin[0] not in self.installedplugins:
228 self.installedplugins.append(plugin[0])
230 if plugin[0] not in self.installedplugins:
231 plugin.append(plugin[0][15:])
233 self.pluginlist.append(plugin)
235 def updateList(self):
237 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
238 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
239 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
242 for x in self.pluginlist:
243 split = x[3].split('-', 1)
246 if not self.plugins.has_key(split[0]):
247 self.plugins[split[0]] = []
249 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
251 for x in self.plugins.keys():
252 if x in self.expanded:
253 list.append(PluginCategoryComponent(x, expandedIcon))
254 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
256 list.append(PluginCategoryComponent(x, expandableIcon))
258 self["list"].l.setList(list)
260 language.addCallback(languageChanged)