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")):
93 from Plugins.SystemPlugins.SoftwareManager.plugin import PluginManager
95 self.session.open(MessageBox, _("The Softwaremanagement extension is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
97 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginManager)
99 class PluginDownloadBrowser(Screen):
102 lastDownloadDate = None
104 def __init__(self, session, type):
105 Screen.__init__(self, session)
109 self.container = eConsoleAppContainer()
110 self.container.appClosed.append(self.runFinished)
111 self.container.dataAvail.append(self.dataAvail)
112 self.onLayoutFinish.append(self.startRun)
113 self.onShown.append(self.setWindowTitle)
116 self["list"] = PluginList(self.list)
119 self.installedplugins = []
121 if self.type == self.DOWNLOAD:
122 self["text"] = Label(_("Downloading plugin information. Please wait..."))
123 elif self.type == self.REMOVE:
124 self["text"] = Label(_("Getting plugin information. Please wait..."))
128 self.remainingdata = ""
130 self["actions"] = ActionMap(["WizardActions"],
137 sel = self["list"].l.getCurrentSelection()
143 if isinstance(sel, str): # category
144 if sel in self.expanded:
145 self.expanded.remove(sel)
147 self.expanded.append(sel)
150 if self.type == self.DOWNLOAD:
151 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
152 elif self.type == self.REMOVE:
153 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
155 def runInstall(self, val):
157 if self.type == self.DOWNLOAD:
158 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
159 elif self.type == self.REMOVE:
160 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
162 def setWindowTitle(self):
163 if self.type == self.DOWNLOAD:
164 self.setTitle(_("Downloadable new plugins"))
165 elif self.type == self.REMOVE:
166 self.setTitle(_("Remove plugins"))
168 def startIpkgListInstalled(self):
169 self.container.execute("ipkg list_installed enigma2-plugin-*")
171 def startIpkgListAvailable(self):
172 self.container.execute("ipkg list enigma2-plugin-*")
175 self["list"].instance.hide()
176 if self.type == self.DOWNLOAD:
177 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
178 # Only update from internet once per hour
179 self.container.execute("ipkg update")
180 PluginDownloadBrowser.lastDownloadDate = time()
182 self.startIpkgListAvailable()
183 elif self.type == self.REMOVE:
185 self.startIpkgListInstalled()
187 def installFinished(self):
188 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
189 self.container.appClosed.remove(self.runFinished)
190 self.container.dataAvail.remove(self.dataAvail)
193 def runFinished(self, retval):
194 self.remainingdata = ""
197 if self.type == self.DOWNLOAD:
198 self.startIpkgListInstalled()
199 elif self.run == 1 and self.type == self.DOWNLOAD:
201 self.startIpkgListAvailable()
203 if len(self.pluginlist) > 0:
205 self["list"].instance.show()
207 self["text"].setText("No new plugins found")
209 def dataAvail(self, str):
210 #prepend any remaining data from the previous call
211 str = self.remainingdata + str
213 lines = str.split('\n')
214 #'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
216 #remember this data for next time
217 self.remainingdata = lines[-1]
220 self.remainingdata = ""
223 plugin = x.split(" - ", 2)
225 if self.run == 1 and self.type == self.DOWNLOAD:
226 if plugin[0] not in self.installedplugins:
227 self.installedplugins.append(plugin[0])
229 if plugin[0] not in self.installedplugins:
230 plugin.append(plugin[0][15:])
232 self.pluginlist.append(plugin)
234 def updateList(self):
236 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
237 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
238 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
241 for x in self.pluginlist:
242 split = x[3].split('-', 1)
245 if not self.plugins.has_key(split[0]):
246 self.plugins[split[0]] = []
248 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
250 for x in self.plugins.keys():
251 if x in self.expanded:
252 list.append(PluginCategoryComponent(x, expandedIcon))
253 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
255 list.append(PluginCategoryComponent(x, expandableIcon))
257 self["list"].l.setList(list)
259 language.addCallback(languageChanged)