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)
54 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
55 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
57 self["list"].l.setList(self.list)
60 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
63 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
65 class PluginDownloadBrowser(Screen):
69 def __init__(self, session, type):
70 Screen.__init__(self, session)
74 self.container = eConsoleAppContainer()
75 self.container.appClosed.append(self.runFinished)
76 self.container.dataAvail.append(self.dataAvail)
77 self.onLayoutFinish.append(self.startRun)
78 self.onShown.append(self.setWindowTitle)
81 self["list"] = PluginList(self.list)
84 self.installedplugins = []
86 if self.type == self.DOWNLOAD:
87 self["text"] = Label(_("Downloading plugin information. Please wait..."))
88 elif self.type == self.REMOVE:
89 self["text"] = Label(_("Getting plugin information. Please wait..."))
93 self.remainingdata = ""
95 self["actions"] = ActionMap(["WizardActions"],
102 sel = self["list"].l.getCurrentSelection()
108 if isinstance(sel, str): # category
109 if sel in self.expanded:
110 self.expanded.remove(sel)
112 self.expanded.append(sel)
115 if self.type == self.DOWNLOAD:
116 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"%s\"?") % sel.name)
117 elif self.type == self.REMOVE:
118 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"%s\"?") % sel.name)
120 def runInstall(self, val):
122 if self.type == self.DOWNLOAD:
123 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
124 elif self.type == self.REMOVE:
125 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
127 def setWindowTitle(self):
128 if self.type == self.DOWNLOAD:
129 self.setTitle(_("Downloadable new plugins"))
130 elif self.type == self.REMOVE:
131 self.setTitle(_("Remove plugins"))
134 self["list"].instance.hide()
135 if self.type == self.DOWNLOAD:
136 self.container.execute("ipkg update")
137 elif self.type == self.REMOVE:
139 self.container.execute("ipkg list_installed enigma2-plugin-*")
141 def installFinished(self):
142 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
143 self.container.appClosed.remove(self.runFinished)
144 self.container.dataAvail.remove(self.dataAvail)
147 def runFinished(self, retval):
148 self.remainingdata = ""
151 if self.type == self.DOWNLOAD:
152 self.container.execute("ipkg list_installed enigma2-plugin-*")
153 elif self.run == 1 and self.type == self.DOWNLOAD:
155 self.container.execute("ipkg list enigma2-plugin-*")
157 if len(self.pluginlist) > 0:
159 self["list"].instance.show()
161 self["text"].setText("No new plugins found")
163 def dataAvail(self, str):
164 #prepend any remaining data from the previous call
165 str = self.remainingdata + str
167 lines = str.split('\n')
168 #'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
170 #remember this data for next time
171 self.remainingdata = lines[-1]
174 self.remainingdata = ""
177 plugin = x.split(" - ")
179 if self.run == 1 and self.type == self.DOWNLOAD:
180 self.installedplugins.append(plugin[0])
182 if plugin[0] not in self.installedplugins:
183 plugin.append(plugin[0][15:])
185 self.pluginlist.append(plugin)
187 def updateList(self):
189 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
190 expandedIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expanded-plugins.png"))
191 verticallineIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/verticalline-plugins.png"))
194 for x in self.pluginlist:
195 split = x[3].split('-')
198 if not self.plugins.has_key(split[0]):
199 self.plugins[split[0]] = []
201 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
203 for x in self.plugins.keys():
204 if x in self.expanded:
205 list.append(PluginCategoryComponent(x, expandedIcon))
206 list.extend([PluginDownloadComponent(plugin[0], plugin[1]) for plugin in self.plugins[x]])
208 list.append(PluginCategoryComponent(x, expandableIcon))
210 self["list"].l.setList(list)