From ccb8d260ed5e51f6f65205be04744a9e8322aa6f Mon Sep 17 00:00:00 2001 From: Stefan Pluecken Date: Wed, 21 Dec 2005 04:41:36 +0000 Subject: add plugins to test it: uncomment the example.py in lib/python/Plugins/Makefile.am plugins can be added at runtime --- lib/python/Components/Makefile.am | 3 ++- lib/python/Components/PluginComponent.py | 33 +++++++++++++++++++++++ lib/python/Components/PluginList.py | 42 +++++++++++++++++++++++++++++ lib/python/Makefile.am | 2 +- lib/python/Plugins/Makefile.am | 5 ++++ lib/python/Plugins/__init__.py | 0 lib/python/Plugins/example.py | 34 +++++++++++++++++++++++ lib/python/Screens/Makefile.am | 2 +- lib/python/Screens/PluginBrowser.py | 46 ++++++++++++++++++++++++++++++++ 9 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 lib/python/Components/PluginComponent.py create mode 100644 lib/python/Components/PluginList.py create mode 100644 lib/python/Plugins/Makefile.am create mode 100644 lib/python/Plugins/__init__.py create mode 100644 lib/python/Plugins/example.py create mode 100644 lib/python/Screens/PluginBrowser.py (limited to 'lib/python') diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index f83403b4..340730a6 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -10,4 +10,5 @@ install_PYTHON = \ InputDevice.py ServicePosition.py SetupDevices.py Harddisk.py \ AVSwitch.py Network.py RFmod.py DiskInfo.py NimManager.py Lcd.py \ EpgList.py ScrollLabel.py Timezones.py Language.py HelpMenuList.py \ - BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py + BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \ + PluginList.py PluginComponent.py diff --git a/lib/python/Components/PluginComponent.py b/lib/python/Components/PluginComponent.py new file mode 100644 index 00000000..26382063 --- /dev/null +++ b/lib/python/Components/PluginComponent.py @@ -0,0 +1,33 @@ +import os + +from Tools.Directories import * +#import Plugins + +class PluginComponent: + def __init__(self): + self.plugins = [] + self.setPluginPrefix("Plugins.") + + def setPluginPrefix(self, prefix): + self.prefix = prefix + + def getPluginList(self): + list = [] + dir = os.listdir("/usr/lib/enigma2/python/Plugins/") + 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!" + return list + + def runPlugin(self, plugin, session): + exec "import " + self.prefix + plugin[2] + eval(self.prefix + plugin[2]).main(session) + +plugins = PluginComponent() diff --git a/lib/python/Components/PluginList.py b/lib/python/Components/PluginList.py new file mode 100644 index 00000000..d2ae64a7 --- /dev/null +++ b/lib/python/Components/PluginList.py @@ -0,0 +1,42 @@ +from HTMLComponent import * +from GUIComponent import * + +from MenuList import MenuList + +from Tools.Directories import * + +from enigma import * + +RT_HALIGN_LEFT = 0 +RT_HALIGN_RIGHT = 1 +RT_HALIGN_CENTER = 2 +RT_HALIGN_BLOCK = 4 + +RT_VALIGN_TOP = 0 +RT_VALIGN_CENTER = 8 +RT_VALIGN_BOTTOM = 16 + +def PluginEntryComponent(picture, name): + res = [ None ] + res.append((80, 10, 200, 50, 0, RT_HALIGN_LEFT , name)) + png = loadPNG(picture) + if png == None: + png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/countries/missing.png")) + res.append((10, 5, 60, 40, png)) + + return res + + +class PluginList(HTMLComponent, GUIComponent, MenuList): + def __init__(self, list): + GUIComponent.__init__(self) + self.l = eListboxPythonMultiContent() + self.list = list + self.l.setList(list) + self.l.setFont(0, gFont("Arial", 20)) + self.l.setFont(1, gFont("Arial", 10)) + + def GUIcreate(self, parent): + self.instance = eListbox(parent) + self.instance.setContent(self.l) + self.instance.setItemHeight(50) \ No newline at end of file diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index e94d36f4..1cc01544 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/src -SUBDIRS = Components Tools Screens +SUBDIRS = Components Tools Screens Plugins noinst_LIBRARIES = libenigma_python.a diff --git a/lib/python/Plugins/Makefile.am b/lib/python/Plugins/Makefile.am new file mode 100644 index 00000000..d963b3c0 --- /dev/null +++ b/lib/python/Plugins/Makefile.am @@ -0,0 +1,5 @@ +installdir = $(LIBDIR)/enigma2/python/Plugins + +install_PYTHON = \ + __init__.py \ + example.py \ No newline at end of file diff --git a/lib/python/Plugins/__init__.py b/lib/python/Plugins/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lib/python/Plugins/example.py b/lib/python/Plugins/example.py new file mode 100644 index 00000000..86e2cd14 --- /dev/null +++ b/lib/python/Plugins/example.py @@ -0,0 +1,34 @@ +from enigma import * +from Screens.Screen import Screen +from Components.ActionMap import ActionMap +from Components.Label import Label + +class Example(Screen): + skin = """ + + + """ + + def __init__(self, session): + self.skin = Example.skin + Screen.__init__(self, session) + + self["text"] = Label("Small test") + + self["actions"] = ActionMap(["WizardActions"], + { + "ok": self.ok + }, -1) + + def ok(self): + self.close() + +def main(session): + session.open(Example) + + +def getPicturePath(): + return "/usr/share/enigma2/record.png" + +def getPluginName(): + return "Fancy example-plugin" \ No newline at end of file diff --git a/lib/python/Screens/Makefile.am b/lib/python/Screens/Makefile.am index 15b56d41..d191a5ba 100644 --- a/lib/python/Screens/Makefile.am +++ b/lib/python/Screens/Makefile.am @@ -8,4 +8,4 @@ install_PYTHON = \ EpgSelection.py EventView.py Mute.py Standby.py ServiceInfo.py \ AudioSelection.py InfoBarGenerics.py HelpMenu.py Wizard.py __init__.py \ Dish.py SubserviceSelection.py LanguageSelection.py StartWizard.py \ - TutorialWizard.py + TutorialWizard.py PluginBrowser.py diff --git a/lib/python/Screens/PluginBrowser.py b/lib/python/Screens/PluginBrowser.py new file mode 100644 index 00000000..c03aa910 --- /dev/null +++ b/lib/python/Screens/PluginBrowser.py @@ -0,0 +1,46 @@ +from Screen import Screen + +from Components.MenuList import MenuList +from Components.ActionMap import ActionMap +from Components.PluginComponent import plugins +from Components.PluginList import * +from Components.config import config + + +class PluginBrowser(Screen): + def __init__(self, session): + Screen.__init__(self, session) + + self.list = [] + self["list"] = PluginList(self.list) + self.updateList() + + self["actions"] = ActionMap(["WizardActions"], + { + "ok": self.save, + "back": self.close, + "up": self.up, + "down": self.down + }, -1) + + def save(self): + #self.close() + self.run() + + def run(self): + plugin = self.pluginlist[self["list"].l.getCurrentSelectionIndex()] + plugins.runPlugin(plugin, self.session) + + def updateList(self): + self.list = [] + self.pluginlist = plugins.getPluginList() + for x in self.pluginlist: + self.list.append(PluginEntryComponent(x[0], x[1])) + + self["list"].l.setList(self.list) + + def up(self): + self["list"].instance.moveSelection(self["list"].instance.moveUp) + + def down(self): + self["list"].instance.moveSelection(self["list"].instance.moveDown) -- cgit v1.2.3