plugins can register their own menu now
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Fri, 6 Jan 2006 15:48:47 +0000 (15:48 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Fri, 6 Jan 2006 15:48:47 +0000 (15:48 +0000)
menus have their own id now
the update plugin for example adds a menu item to the Setup menu with the id "setup"

data/menu.xml
lib/python/Components/PluginComponent.py
lib/python/Plugins/update.py
lib/python/Screens/Menu.py
mytest.py

index 7f0df14..cf17421 100644 (file)
@@ -1,5 +1,5 @@
 <menu text="Mainmenu" title="Mainmenu">
-
+       <id val="mainmenu" />
 <!-- the following types are allowed:
        <screen [module="mod"] [screen="classname"]>[arguments]</screen> 
                executes Screen called "classname" from module "Screen.mod"
                <item text="VCR scart"><screen module="Scart" screen="Scart" /></item>
 
                <menu text="Information">
+                       <id val="information" />
                        <item text="Service"><screen module="ServiceInfo" screen="ServiceInfo"/></item>
                        <item text="About..."><screen module="About" /></item>
                </menu>
 
                <item text="Games / Plugins"><screen module="PluginBrowser" screen="PluginBrowser" /></item>
                <menu text="Setup">
+                       <id val="setup" />
                        <!--<menu text="Service Organising">
                                <item text="New Bouquets"></item>
                                <item text="Add to Bouquets"></item>
                                <item text="Edit Bouquets"></item>
                        </menu>-->
                        <menu text="Service Searching">
+                               <id val="scan" />
                                <item text="Satelliteconfig"><screen module="Satconfig" screen="NimSelection" /></item>
                                <item text="Automatic Scan"><screen module="ScanSetup" screen="ScanSimple" /></item>
                                <!--<item text="Automatic Scan"><screen module="ServiceScan" /></item>-->
@@ -42,6 +45,7 @@
                                <!--<item text="Satfinder"></item>-->
                        </menu>
                        <menu text="System">
+                               <id val="system" />
                                <item text="Language"><screen module="LanguageSelection" /></item>
                                <item text="Recording"><setup id="recording" /></item>
                                <item text="Timezone"><setup id="timezone" /></item>
@@ -60,6 +64,7 @@
                </menu>
                <!--<item text="Unser Setup">self.openSetup("Blaselfasel")</item>-->
                <menu text="Standby / Restart">
+                       <id val="shutdown" />
                        <!--<item text="Standby"><code>quitMainloop(0)</code></item>-->
                        <item text="Restart"><code>quitMainloop(2)</code></item>
                        <item text="Deep Standby"><code>quitMainloop(1)</code></item>
index f1a0a95..5315d3d 100644 (file)
@@ -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]
index d05d317..e69de29 100644 (file)
@@ -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 = """
-               <screen position="100,100" size="550,400" title="IPKG upgrade..." >
-                       <widget name="text" position="0,0" size="550,400" font="Regular;15" />
-               </screen>"""
-               
-       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
index 0abc173..4ad36d1 100644 (file)
@@ -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)   
                                                        
index c55476f..573a007 100644 (file)
--- 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 = ""):