From: Stefan Pluecken Date: Fri, 6 Jan 2006 15:48:47 +0000 (+0000) Subject: plugins can register their own menu now X-Git-Tag: 2.6.0~4505 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/bb438bec17665a907c28ca47d665766c7b26be79 plugins can register their own menu now menus have their own id now the update plugin for example adds a menu item to the Setup menu with the id "setup" --- diff --git a/data/menu.xml b/data/menu.xml index 7f0df144..cf17421e 100644 --- a/data/menu.xml +++ b/data/menu.xml @@ -1,5 +1,5 @@ - + + @@ -42,6 +45,7 @@ + @@ -60,6 +64,7 @@ + quitMainloop(2) quitMainloop(1) diff --git a/lib/python/Components/PluginComponent.py b/lib/python/Components/PluginComponent.py index f1a0a95a..5315d3d9 100644 --- a/lib/python/Components/PluginComponent.py +++ b/lib/python/Components/PluginComponent.py @@ -1,12 +1,14 @@ import os from Tools.Directories import * +from Screens.Menu import menuupdater #import Plugins class PluginComponent: def __init__(self): self.plugins = [] self.setPluginPrefix("Plugins.") + self.menuEntries = [] def setPluginPrefix(self, prefix): self.prefix = prefix @@ -14,18 +16,32 @@ class PluginComponent: def getPluginList(self): list = [] dir = os.listdir("/usr/lib/enigma2/python/Plugins/") + self.menuDelete() + self.menuEntries = [] for x in dir: if x[-3:] == ".py" and x[:-3] != "__init__": - #try: print "trying to import " + self.prefix + x[:-3] exec "import " + self.prefix + x[:-3] picturepath = eval(self.prefix + x[:-3]).getPicturePath() pluginname = eval(self.prefix + x[:-3]).getPluginName() + try: + for menuEntry in eval(self.prefix + x[:-3]).getMenuRegistrationList(): + self.menuEntries.append([menuEntry, self.prefix + x[:-3]]) + except: + pass + list.append((picturepath, pluginname , x[:-3])) - #except: - #print "Failed to open module - wrong plugin!" + self.menuUpdate() return list + def menuDelete(self): + for menuEntry in self.menuEntries: + menuupdater.delMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3]) + + def menuUpdate(self): + for menuEntry in self.menuEntries: + menuupdater.addMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3]) + def runPlugin(self, plugin, session): try: exec "import " + self.prefix + plugin[2] diff --git a/lib/python/Plugins/update.py b/lib/python/Plugins/update.py index d05d317e..e69de29b 100644 --- a/lib/python/Plugins/update.py +++ b/lib/python/Plugins/update.py @@ -1,62 +0,0 @@ -from enigma import * -from Screens.Screen import Screen -from Screens.MessageBox import MessageBox -from Components.ActionMap import ActionMap -from Components.Label import Label - -import os - -class Example(Screen): - skin = """ - - - """ - - def __init__(self, session): - self.skin = Example.skin - Screen.__init__(self, session) - - self["text"] = Label(_("Please press OK!")) - - self["actions"] = ActionMap(["WizardActions"], - { - "ok": self.go, - "back": self.close - }, -1) - - self.update = True - self.delayTimer = eTimer() - self.delayTimer.timeout.get().append(self.doUpdateDelay) - - def go(self): - if self.update: - self.session.openWithCallback(self.doUpdate, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!")) - else: - self.close() - - def doUpdateDelay(self): - lines = os.popen("ipkg update && ipkg upgrade", "r").readlines() - string = "" - for x in lines: - string += x - self["text"].setText(_("Updating finished. Here is the result:") + "\n\n" + string) - self.update = False - - - def doUpdate(self, val = False): - if val == True: - self["text"].setText(_("Updating... Please wait... This can take some minutes...")) - self.delayTimer.start(0, 1) - else: - self.close() - - -def main(session): - session.open(Example) - - -def getPicturePath(): - return "/usr/lib/enigma2/python/Plugins/update.png" - -def getPluginName(): - return "Softwareupdate" \ No newline at end of file diff --git a/lib/python/Screens/Menu.py b/lib/python/Screens/Menu.py index 0abc1735..4ad36d18 100644 --- a/lib/python/Screens/Menu.py +++ b/lib/python/Screens/Menu.py @@ -55,7 +55,27 @@ class boundFunction: self.args = args def __call__(self): self.fnc(*self.args) - + +class MenuUpdater: + def __init__(self): + self.updatedMenuItems = {} + + def addMenuItem(self, id, text, module, screen): + if not self.updatedMenuAvailable(id): + self.updatedMenuItems[id] = [] + self.updatedMenuItems[id].append([text, module, screen]) + + def delMenuItem(self, id, text, module, screen): + self.updatedMenuItems[id].remove([text, module, screen]) + + def updatedMenuAvailable(self, id): + return self.updatedMenuItems.has_key(id) + + def getUpdatedMenu(self, id): + return self.updatedMenuItems[id] + +menuupdater = MenuUpdater() + class Menu(Screen): def okbuttonClick(self): print "okbuttonClick" @@ -73,8 +93,8 @@ class Menu(Screen): # stuff which is just imported) # FIXME. somehow. if arg[0] != "": - exec "from Screens." + arg[0] + " import *" - + exec "from " + arg[0] + " import *" + self.openDialog(*eval(arg[1])) def nothing(self): #dummy @@ -100,7 +120,7 @@ class Menu(Screen): if x.nodeType != xml.dom.minidom.Element.nodeType: continue elif x.tagName == 'screen': - module = getValbyAttr(x, "module") + module = "Screens." + getValbyAttr(x, "module") screen = getValbyAttr(x, "screen") if len(screen) == 0: @@ -128,6 +148,7 @@ class Menu(Screen): Screen.__init__(self, session) list = [] + menuID = "" for x in childNode: #walk through the actual nodelist if x.nodeType != xml.dom.minidom.Element.nodeType: @@ -136,6 +157,12 @@ class Menu(Screen): self.addItem(list, x) elif x.tagName == 'menu': self.addMenu(list, x) + elif x.tagName == "id": + menuID = getValbyAttr(x, "val") + + if menuupdater.updatedMenuAvailable(menuID): + for x in menuupdater.getUpdatedMenu(menuID): + list.append((x[0], boundFunction(self.runScreen, (x[1], x[2] + ", ")))) self["menu"] = MenuList(list) diff --git a/mytest.py b/mytest.py index c55476fd..573a0072 100644 --- a/mytest.py +++ b/mytest.py @@ -24,6 +24,10 @@ from Tools.Directories import InitFallbackFiles InitFallbackFiles() eDVBDB.getInstance().reloadBouquets() +# initialize autorun plugins and plugin menu entries +from Components.PluginComponent import plugins +plugins.getPluginList() + had = dict() def dump(dir, p = ""):