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)
49 self.onLayoutFinish.append(self.saveListsize)
51 def saveListsize(self):
52 listsize = self["list"].instance.size()
53 self.listWidth = listsize.width()
54 self.listHeight = listsize.height()
56 def checkWarnings(self):
57 if len(plugins.warnings):
58 text = _("Some plugins are not available:\n")
59 for (pluginname, error) in plugins.warnings:
60 text += _("%s (%s)\n") % (pluginname, error)
61 plugins.resetWarnings()
62 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
68 plugin = self["list"].l.getCurrentSelection()[0]
69 plugin(session=self.session)
72 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
73 self.list = [PluginEntryComponent(plugin, self.listWidth) for plugin in self.pluginlist]
74 self["list"].l.setList(self.list)
75 if fileExists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/plugin.py")):
76 self["red"].setText(_("Manage extensions"))
77 self["green"].setText("")
78 self["SoftwareActions"].setEnabled(True)
79 self["PluginDownloadActions"].setEnabled(False)
81 self["red"].setText(_("Remove Plugins"))
82 self["green"].setText(_("Download Plugins"))
83 self["SoftwareActions"].setEnabled(False)
84 self["PluginDownloadActions"].setEnabled(True)
87 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
90 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
92 def PluginDownloadBrowserClosed(self):
96 def openExtensionmanager(self):
97 if fileExists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/plugin.py")):
99 from Plugins.SystemPlugins.SoftwareManager.plugin import PluginManager
101 self.session.open(MessageBox, _("The Softwaremanagement extension is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
103 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginManager)
105 class PluginDownloadBrowser(Screen):
108 lastDownloadDate = None
110 def __init__(self, session, type):
111 Screen.__init__(self, session)
115 self.container = eConsoleAppContainer()
116 self.container.appClosed.append(self.runFinished)
117 self.container.dataAvail.append(self.dataAvail)
118 self.onLayoutFinish.append(self.startRun)
119 self.onShown.append(self.setWindowTitle)
122 self["list"] = PluginList(self.list)
125 self.installedplugins = []
127 if self.type == self.DOWNLOAD:
128 self["text"] = Label(_("Downloading plugin information. Please wait..."))
129 elif self.type == self.REMOVE:
130 self["text"] = Label(_("Getting plugin information. Please wait..."))
134 self.remainingdata = ""
136 self["actions"] = ActionMap(["WizardActions"],
143 sel = self["list"].l.getCurrentSelection()
149 if isinstance(sel, str): # category
150 if sel in self.expanded:
151 self.expanded.remove(sel)
153 self.expanded.append(sel)
156 if self.type == self.DOWNLOAD:
157 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
158 elif self.type == self.REMOVE:
159 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
161 def runInstall(self, val):
163 if self.type == self.DOWNLOAD:
164 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["opkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
165 elif self.type == self.REMOVE:
166 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["opkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
168 def setWindowTitle(self):
169 if self.type == self.DOWNLOAD:
170 self.setTitle(_("Downloadable new plugins"))
171 elif self.type == self.REMOVE:
172 self.setTitle(_("Remove plugins"))
174 def startIpkgListInstalled(self):
175 self.container.execute("opkg list_installed enigma2-plugin-*")
177 def startIpkgListAvailable(self):
178 self.container.execute("opkg list enigma2-plugin-*")
181 listsize = self["list"].instance.size()
182 self["list"].instance.hide()
183 self.listWidth = listsize.width()
184 self.listHeight = listsize.height()
185 if self.type == self.DOWNLOAD:
186 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
187 # Only update from internet once per hour
188 self.container.execute("opkg update")
189 PluginDownloadBrowser.lastDownloadDate = time()
191 self.startIpkgListAvailable()
192 elif self.type == self.REMOVE:
194 self.startIpkgListInstalled()
196 def installFinished(self):
197 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
198 self.container.appClosed.remove(self.runFinished)
199 self.container.dataAvail.remove(self.dataAvail)
202 def runFinished(self, retval):
203 self.remainingdata = ""
206 if self.type == self.DOWNLOAD:
207 self.startIpkgListInstalled()
208 elif self.run == 1 and self.type == self.DOWNLOAD:
210 self.startIpkgListAvailable()
212 if len(self.pluginlist) > 0:
214 self["list"].instance.show()
216 self["text"].setText("No new plugins found")
218 def dataAvail(self, str):
219 #prepend any remaining data from the previous call
220 str = self.remainingdata + str
222 lines = str.split('\n')
223 #'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
225 #remember this data for next time
226 self.remainingdata = lines[-1]
229 self.remainingdata = ""
232 plugin = x.split(" - ")
234 if self.run == 1 and self.type == self.DOWNLOAD:
235 if plugin[0] not in self.installedplugins:
236 self.installedplugins.append(plugin[0])
238 if plugin[0] not in self.installedplugins:
239 plugin.append(plugin[0][15:])
241 self.pluginlist.append(plugin)
243 def updateList(self):
245 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
246 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
247 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
250 for x in self.pluginlist:
252 split = x[0].split('-',3)
253 if not self.plugins.has_key(split[2]):
254 self.plugins[split[2]] = []
255 self.plugins[split[2]].append((PluginDescriptor(name = x[2], description = " ", icon = verticallineIcon), split[3]))
258 split = x[3].split('-', 1)
261 if not self.plugins.has_key(split[0]):
262 self.plugins[split[0]] = []
264 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
266 for x in self.plugins.keys():
267 if x in self.expanded:
268 list.append(PluginCategoryComponent(x, expandedIcon, self.listWidth))
269 list.extend([PluginDownloadComponent(plugin[0], plugin[1], self.listWidth) for plugin in self.plugins[x]])
271 list.append(PluginCategoryComponent(x, expandableIcon, self.listWidth))
273 self["list"].l.setList(list)
275 language.addCallback(languageChanged)