1 from Screen import Screen
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, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
13 from Tools.LoadPixmap import LoadPixmap
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.append(self.runFinished)
78 self.container.dataAvail.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.remainingdata = ""
97 self["actions"] = ActionMap(["WizardActions"],
104 sel = self["list"].l.getCurrentSelection()
110 if isinstance(sel, str): # category
111 if sel in self.expanded:
112 self.expanded.remove(sel)
114 self.expanded.append(sel)
117 if self.type == self.DOWNLOAD:
118 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
119 elif self.type == self.REMOVE:
120 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
122 def runInstall(self, val):
124 if self.type == self.DOWNLOAD:
125 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
126 elif self.type == self.REMOVE:
127 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
129 def setWindowTitle(self):
130 if self.type == self.DOWNLOAD:
131 self.setTitle(_("Downloadable new plugins"))
132 elif self.type == self.REMOVE:
133 self.setTitle(_("Remove plugins"))
136 self["list"].instance.hide()
137 if self.type == self.DOWNLOAD:
138 self.container.execute("ipkg update")
139 elif self.type == self.REMOVE:
141 self.container.execute("ipkg list_installed enigma2-plugin-*")
143 def installFinished(self):
144 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
145 self.container.appClosed.remove(self.runFinished)
146 self.container.dataAvail.remove(self.dataAvail)
149 def runFinished(self, retval):
150 self.remainingdata = ""
153 if self.type == self.DOWNLOAD:
154 self.container.execute("ipkg list_installed enigma2-plugin-*")
155 elif self.run == 1 and self.type == self.DOWNLOAD:
157 self.container.execute("ipkg list enigma2-plugin-*")
159 if len(self.pluginlist) > 0:
161 self["list"].instance.show()
163 self["text"].setText("No new plugins found")
165 def dataAvail(self, str):
166 #prepend any remaining data from the previous call
167 str = self.remainingdata + str
169 lines = str.split('\n')
170 #'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
172 #remember this data for next time
173 self.remainingdata = lines[-1]
176 self.remainingdata = ""
179 plugin = x.split(" - ")
181 if self.run == 1 and self.type == self.DOWNLOAD:
182 self.installedplugins.append(plugin[0])
184 if plugin[0] not in self.installedplugins:
185 plugin.append(plugin[0][15:])
187 self.pluginlist.append(plugin)
189 def updateList(self):
191 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
192 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
193 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
196 for x in self.pluginlist:
197 split = x[3].split('-')
200 if not self.plugins.has_key(split[0]):
201 self.plugins[split[0]] = []
203 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
205 for x in self.plugins.keys():
206 if x in self.expanded:
207 self.list.append(PluginCategoryComponent(x, expandedIcon))
208 for plugin in self.plugins[x]:
209 self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
211 self.list.append(PluginCategoryComponent(x, expandableIcon))
212 self["list"].l.setList(self.list)