1 from Screen import Screen
3 from enigma import eConsoleAppContainer, loadPNG
5 from Components.MenuList import MenuList
6 from Components.ActionMap import ActionMap
7 from Components.PluginComponent import plugins
8 from Components.PluginList import *
9 from Components.config import config
10 from Components.Label import Label
11 from Screens.MessageBox import MessageBox
12 from Screens.Console import Console
13 from Plugins.Plugin import PluginDescriptor
14 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
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.get().append(self.runFinished)
78 self.container.dataAvail.get().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["actions"] = ActionMap(["WizardActions"],
102 sel = self["list"].l.getCurrentSelection()
107 if type(sel[0]) is str: # category
108 if sel[0] in self.expanded:
109 self.expanded.remove(sel[0])
111 self.expanded.append(sel[0])
114 if self.type == self.DOWNLOAD:
115 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + sel[0].name + "\"?"))
116 elif self.type == self.REMOVE:
117 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"" + sel[0].name + "\"?"))
119 def runInstall(self, val):
121 if self.type == self.DOWNLOAD:
122 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
123 elif self.type == self.REMOVE:
124 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
126 def setWindowTitle(self):
127 if self.type == self.DOWNLOAD:
128 self.setTitle(_("Downloadable new plugins"))
129 elif self.type == self.REMOVE:
130 self.setTitle(_("Remove plugins"))
133 self["list"].instance.hide()
134 if self.type == self.DOWNLOAD:
135 self.container.execute("ipkg update")
136 elif self.type == self.REMOVE:
138 self.container.execute("ipkg list_installed enigma2-plugin-*")
140 def installFinished(self):
141 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
144 def runFinished(self, retval):
147 if self.type == self.DOWNLOAD:
148 self.container.execute("ipkg list_installed enigma2-plugin-*")
149 elif self.run == 1 and self.type == self.DOWNLOAD:
151 self.container.execute("ipkg list enigma2-plugin-*")
153 if len(self.pluginlist) > 0:
155 self["list"].instance.show()
157 self["text"].setText("No new plugins found")
159 def dataAvail(self, str):
160 for x in str.split('\n'):
161 plugin = x.split(" - ")
163 if self.run == 1 and self.type == self.DOWNLOAD:
164 self.installedplugins.append(plugin[0])
166 if plugin[0] not in self.installedplugins:
167 plugin.append(plugin[0][15:])
169 self.pluginlist.append(plugin)
171 def updateList(self):
173 expandableIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expandable-plugins.png"))
174 expandedIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expanded-plugins.png"))
175 verticallineIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "verticalline-plugins.png"))
178 for x in self.pluginlist:
179 split = x[3].split('-')
182 if not self.plugins.has_key(split[0]):
183 self.plugins[split[0]] = []
185 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
187 for x in self.plugins.keys():
188 if x in self.expanded:
189 self.list.append(PluginCategoryComponent(x, expandedIcon))
190 for plugin in self.plugins[x]:
191 self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
193 self.list.append(PluginCategoryComponent(x, expandableIcon))
194 self["list"].l.setList(self.list)