move the plugins into their own directory and every plugin has a main python file...
[vuplus_dvbapp] / lib / python / Components / PluginComponent.py
index f1a0a95..0b40702 100644 (file)
@@ -1,35 +1,55 @@
 import os
 
 from Tools.Directories import *
-#import Plugins
+from Screens.Menu import menuupdater
 
 class PluginComponent:
        def __init__(self):
                self.plugins = []
                self.setPluginPrefix("Plugins.")
+               self.menuEntries = []
                
        def setPluginPrefix(self, prefix):
                self.prefix = prefix
 
        def getPluginList(self):
                list = []
-               dir = os.listdir("/usr/lib/enigma2/python/Plugins/")
+               dir = os.listdir(resolveFilename(SCOPE_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()
-                               list.append((picturepath, pluginname , x[:-3]))
-                               #except:
-                                       #print "Failed to open module - wrong plugin!"
+                       path = resolveFilename(SCOPE_PLUGINS, x) + "/"
+                       if os.path.exists(path):
+                               if fileExists(path + "plugin.py"):
+                                       pluginmodule = self.prefix + x + ".plugin"
+                                       print "trying to import " + pluginmodule
+                                       exec "import " + pluginmodule
+                                       plugin = eval(pluginmodule)
+                                       picturepath = plugin.getPicturePath()
+                                       pluginname = plugin.getPluginName()
+                                       try:
+                                               for menuEntry in plugin.getMenuRegistrationList():
+                                                       self.menuEntries.append([menuEntry, pluginmodule])
+                                       except:
+                                               pass
+       
+                                       list.append((picturepath, pluginname , x))
+               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]
-                       eval(self.prefix + plugin[2]).main(session)
+                       exec "import " + self.prefix + plugin[2] + ".plugin"
+                       eval(self.prefix + plugin[2] + ".plugin").main(session)
                except:
                        print "exec of plugin failed!"