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
40 plugin = self["list"].l.getCurrentSelection()[0]
42 plugin(session=self.session)
46 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
47 for plugin in self.pluginlist:
48 self.list.append(PluginEntryComponent(plugin))
50 self["list"].l.setList(self.list)
53 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.REMOVE)
56 self.session.openWithCallback(self.updateList, PluginDownloadBrowser, PluginDownloadBrowser.DOWNLOAD)
58 class PluginDownloadBrowser(Screen):
62 def __init__(self, session, type):
63 Screen.__init__(self, session)
67 self.container = eConsoleAppContainer()
68 self.container.appClosed.get().append(self.runFinished)
69 self.container.dataAvail.get().append(self.dataAvail)
70 self.onLayoutFinish.append(self.startRun)
71 self.onShown.append(self.setWindowTitle)
74 self["list"] = PluginList(self.list)
78 if self.type == self.DOWNLOAD:
79 self["text"] = Label(_("Downloading plugin information. Please wait..."))
80 elif self.type == self.REMOVE:
81 self["text"] = Label(_("Getting plugin information. Please wait..."))
85 self["actions"] = ActionMap(["WizardActions"],
92 if type(self["list"].l.getCurrentSelection()[0]) is str: # category
93 if self["list"].l.getCurrentSelection()[0] in self.expanded:
94 self.expanded.remove(self["list"].l.getCurrentSelection()[0])
96 self.expanded.append(self["list"].l.getCurrentSelection()[0])
99 if self.type == self.DOWNLOAD:
100 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to download\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
101 elif self.type == self.REMOVE:
102 self.session.openWithCallback(self.runInstall, MessageBox, _("Do you really want to REMOVE\nthe plugin \"" + self["list"].l.getCurrentSelection()[0].name + "\"?"))
104 def runInstall(self, val):
106 if self.type == self.DOWNLOAD:
107 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg install " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
108 elif self.type == self.REMOVE:
109 self.session.openWithCallback(self.installFinished, Console, cmdlist = ["ipkg remove " + "enigma2-plugin-" + self["list"].l.getCurrentSelection()[0].name])
111 def setWindowTitle(self):
112 if self.type == self.DOWNLOAD:
113 self.setTitle(_("Downloadable new plugins"))
114 elif self.type == self.REMOVE:
115 self.setTitle(_("Remove plugins"))
118 self["list"].instance.hide()
119 if self.type == self.DOWNLOAD:
120 self.container.execute("ipkg update")
121 elif self.type == self.REMOVE:
123 self.container.execute("ipkg list_installed enigma2-plugin-*")
125 def installFinished(self):
126 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
129 def runFinished(self, retval):
132 if self.type == self.DOWNLOAD:
133 self.container.execute("ipkg list enigma2-plugin-*")
135 if len(self.pluginlist) > 0:
137 self["list"].instance.show()
139 self["text"].setText("No plugins found")
141 def dataAvail(self, str):
142 for x in str.split('\n'):
143 plugin = x.split(" - ")
145 plugin.append(plugin[0][15:])
147 self.pluginlist.append(plugin)
149 def updateList(self):
151 expandableIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expandable-plugins.png"))
152 expandedIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "expanded-plugins.png"))
153 verticallineIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "verticalline-plugins.png"))
156 for x in self.pluginlist:
157 split = x[3].split('-')
160 if not self.plugins.has_key(split[0]):
161 self.plugins[split[0]] = []
163 self.plugins[split[0]].append((PluginDescriptor(name = x[3], description = x[2], icon = verticallineIcon), split[1]))
165 for x in self.plugins.keys():
166 if x in self.expanded:
167 self.list.append(PluginCategoryComponent(x, expandedIcon))
168 for plugin in self.plugins[x]:
169 self.list.append(PluginDownloadComponent(plugin[0], plugin[1]))
171 self.list.append(PluginCategoryComponent(x, expandableIcon))
172 self["list"].l.setList(self.list)