add possibility to have menu entries from a plugin
authorFelix Domke <tmbinc@elitedvb.net>
Tue, 10 Oct 2006 02:00:12 +0000 (02:00 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Tue, 10 Oct 2006 02:00:12 +0000 (02:00 +0000)
lib/python/Components/PluginComponent.py
lib/python/Screens/Menu.py

index dd29628..4356456 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import traceback
 
 from Tools.Directories import *
 from Tools.Import import my_import
@@ -43,13 +44,19 @@ class PluginComponent:
                                path = directory_category + "/" + x
                                if os.path.isdir(path):
                                        if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
-                                               plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
+                                               try:
+                                                       plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
 
-                                               if not plugin.__dict__.has_key("Plugins"):
-                                                       print "Plugin %s doesn't have 'Plugin'-call." % (x)
-                                                       continue
+                                                       if not plugin.__dict__.has_key("Plugins"):
+                                                               print "Plugin %s doesn't have 'Plugin'-call." % (x)
+                                                               continue
 
-                                               plugins = plugin.Plugins(path=path)
+                                                       plugins = plugin.Plugins(path=path)
+                                               except Exception, exc:
+                                                       print "Plugin ", path, "failed to load:", exc
+                                                       traceback.print_exc(file=sys.stdout)
+                                                       print "skipping plugin."
+                                                       continue
 
                                                # allow single entry not to be a list
                                                if type(plugins) is not list:
@@ -80,7 +87,13 @@ class PluginComponent:
                        for p in self.plugins.get(x, [ ]):
                                res.append(p)
                return res
-       
+
+       def getPluginsForMenu(self, menuid):
+               res = [ ]
+               for p in self.getPlugins(PluginDescriptor.WHERE_SETUP):
+                       res += p(menuid)
+               return res
+
        def clearPluginList(self):
                self.pluginList = []
                self.plugins = {}
index 6ef4cc4..d6ec901 100644 (file)
@@ -7,6 +7,7 @@ from Components.Label import Label
 from Components.ProgressBar import ProgressBar
 from Components.config import configfile
 from Components.Sources.Clock import Clock
+from Components.PluginComponent import plugins
 
 from Tools.Directories import resolveFilename, SCOPE_SKIN
 
@@ -109,7 +110,7 @@ class Menu(Screen):
                # FIXME. somehow
                if arg[0] != "":
                        exec "from " + arg[0] + " import *"
-                       
+
                self.openDialog(*eval(arg[1]))
 
        def nothing(self):                                                                                                                                      #dummy
@@ -183,9 +184,8 @@ class Menu(Screen):
                Screen.__init__(self, session)
                
                list = []
-               menuID = ""
-
-               menuID = -1
+               
+               menuID = None
                for x in childNode:                                             #walk through the actual nodelist
                        if x.nodeType != xml.dom.minidom.Element.nodeType:
                            continue
@@ -198,13 +198,19 @@ class Menu(Screen):
                        elif x.tagName == "id":
                                menuID = x.getAttribute("val")
                                count = 0
-                       if menuID != -1:
+
+                       if menuID is not None:
+                               # menuupdater?
                                if menuupdater.updatedMenuAvailable(menuID):
                                        for x in menuupdater.getUpdatedMenu(menuID):
                                                if x[1] == count:
                                                        list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
                                                        count += 1
 
+               if menuID is not None:
+                       # plugins
+                       for l in plugins.getPluginsForMenu(menuID):
+                               list.append((l[0], boundFunction(l[1], self.session)))
 
                self["menu"] = MenuList(list)