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["PluginDownloadActions"].setEnabled(False)
42 self.onFirstExecBegin.append(self.checkWarnings)
43 self.onShown.append(self.updateList)
45 def checkWarnings(self):
46 if len(plugins.warnings):
47 text = _("Some plugins are not available:\n")
48 for (pluginname, error) in plugins.warnings:
49 text += _("%s (%s)\n") % (pluginname, error)
50 plugins.resetWarnings()
51 self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
57 plugin = self["list"].l.getCurrentSelection()[0]
58 plugin(session=self.session)
61 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
62 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
63 self["list"].l.setList(self.list)
64 if fileExists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/plugin.py")):
65 self["red"].setText("")
66 self["green"].setText("")
67 self["PluginDownloadActions"].setEnabled(False)
69 self["red"].setText(_("Remove Plugins"))
70 self["green"].setText(_("Download Plugins"))
71 self["PluginDownloadActions"].setEnabled(True)
74 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
77 self.session.openWithCallback(self.PluginDownloadBrowserClosed, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
79 def PluginDownloadBrowserClosed(self):
84 class PluginDownloadBrowser(Screen):
87 lastDownloadDate = None
89 def __init__(self, session, type):
90 Screen.__init__(self, session)
94 self.container = eConsoleAppContainer()
95 self.container.appClosed.append(self.runFinished)
96 self.container.dataAvail.append(self.dataAvail)
97 self.onLayoutFinish.append(self.startRun)
98 self.onShown.append(self.setWindowTitle)
101 self["list"] = PluginList(self.list)
104 self.installedplugins = []
106 if self.type == self.DOWNLOAD:
107 self["text"] = Label(_("Downloading plugin information. Please wait..."))
108 elif self.type == self.REMOVE:
109 self["text"] = Label(_("Getting plugin information. Please wait..."))
113 self.remainingdata = ""
115 self["actions"] = ActionMap(["WizardActions"],
122 sel = self["list"].l.getCurrentSelection()
128 if isinstance(sel, str): # category
129 if sel in self.expanded:
130 self.expanded.remove(sel)
132 self.expanded.append(sel)
135 if self.type == self.DOWNLOAD:
136 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
137 elif self.type == self.REMOVE:
138 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
140 def runInstall(self, val):
142 if self.type == self.DOWNLOAD:
143 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
144 elif self.type == self.REMOVE:
145 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
147 def setWindowTitle(self):
148 if self.type == self.DOWNLOAD:
149 self.setTitle(_("Downloadable new plugins"))
150 elif self.type == self.REMOVE:
151 self.setTitle(_("Remove plugins"))
153 def startIpkgListInstalled(self):
154 self.container.execute("ipkg list_installed enigma2-plugin-*")
156 def startIpkgListAvailable(self):
157 self.container.execute("ipkg list enigma2-plugin-*")
160 self["list"].instance.hide()
161 if self.type == self.DOWNLOAD:
162 if not PluginDownloadBrowser.lastDownloadDate or (time() - PluginDownloadBrowser.lastDownloadDate) > 3600:
163 # Only update from internet once per hour
164 self.container.execute("ipkg update")
165 PluginDownloadBrowser.lastDownloadDate = time()
167 self.startIpkgListAvailable()
168 elif self.type == self.REMOVE:
170 self.startIpkgListInstalled()
172 def installFinished(self):
173 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
174 self.container.appClosed.remove(self.runFinished)
175 self.container.dataAvail.remove(self.dataAvail)
178 def runFinished(self, retval):
179 self.remainingdata = ""
182 if self.type == self.DOWNLOAD:
183 self.startIpkgListInstalled()
184 elif self.run == 1 and self.type == self.DOWNLOAD:
186 self.startIpkgListAvailable()
188 if len(self.pluginlist) > 0:
190 self["list"].instance.show()
192 self["text"].setText("No new plugins found")
194 def dataAvail(self, str):
195 #prepend any remaining data from the previous call
196 str = self.remainingdata + str
198 lines = str.split('\n')
199 #'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
201 #remember this data for next time
202 self.remainingdata = lines[-1]
205 self.remainingdata = ""
208 plugin = x.split(" - ", 2)
210 if self.run == 1 and self.type == self.DOWNLOAD:
211 if plugin[0] not in self.installedplugins:
212 self.installedplugins.append(plugin[0])
214 if plugin[0] not in self.installedplugins:
215 plugin.append(plugin[0][15:])
217 self.pluginlist.append(plugin)
219 def updateList(self):
221 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
222 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
223 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
226 for x in self.pluginlist:
227 split = x[3].split('-', 1)
230 if not self.plugins.has_key(split[0]):
231 self.plugins[split[0]] = []
233 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
235 for x in self.plugins.keys():
236 if x in self.expanded:
237 list.append(PluginCategoryComponent(x, expandedIcon))
238 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
240 list.append(PluginCategoryComponent(x, expandableIcon))
242 self["list"].l.setList(list)
244 language.addCallback(languageChanged)