add plugins
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Wed, 21 Dec 2005 04:41:36 +0000 (04:41 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Wed, 21 Dec 2005 04:41:36 +0000 (04:41 +0000)
to test it: uncomment the example.py in lib/python/Plugins/Makefile.am
plugins can be added at runtime

12 files changed:
configure.ac
data/menu.xml
data/skin.xml
lib/python/Components/Makefile.am
lib/python/Components/PluginComponent.py [new file with mode: 0644]
lib/python/Components/PluginList.py [new file with mode: 0644]
lib/python/Makefile.am
lib/python/Plugins/Makefile.am [new file with mode: 0644]
lib/python/Plugins/__init__.py [new file with mode: 0644]
lib/python/Plugins/example.py [new file with mode: 0644]
lib/python/Screens/Makefile.am
lib/python/Screens/PluginBrowser.py [new file with mode: 0644]

index 0f52031cdd241f6900a6e23157760a88fdb7ef6c..3179c57a6d1986269cdfdb2ac3bbe69254be29a7 100644 (file)
@@ -56,6 +56,7 @@ lib/nav/Makefile
 lib/python/Makefile
 lib/python/Components/Makefile
 lib/python/Screens/Makefile
+lib/python/Plugins/Makefile
 lib/python/Tools/Makefile
 lib/service/Makefile
 lib/components/Makefile
index dabdd76e4ba5d1746773fc460409a0125d900f7a..be0119fcb0659046be91f8721c9a522b52b9c23b 100644 (file)
@@ -24,7 +24,7 @@
                        <item text="About..."><screen module="About" /></item>
                </menu>
 
-               <item text="Games / Plugins"><screen module="PluginBrowser" /></item>
+               <item text="Games / Plugins"><screen module="PluginBrowser" screen="PluginBrowser" /></item>
                <menu text="Setup">
                        <!--<menu text="Service Organising">
                                <item text="New Bouquets"></item>
index a98d10999efbc381b2dce6d52129fc627e87c5ce..2724612fe38b5a68c2d34a531de9611f120f6053 100644 (file)
@@ -73,6 +73,9 @@
                <screen name="LanguageSelection" position="200,125" size="220,250" title="Language selection">
                        <widget name="list" position="10,0" size="190,240" scrollbarMode="showOnDemand" />
                </screen>
+               <screen name="PluginBrowser" position="100,125" size="400,350" title="Plugin browser">
+                       <widget name="list" position="10,0" size="380,340" scrollbarMode="showOnDemand" />
+               </screen>
                <screen name="NimSelection" position="140,165" size="400,100" title="select Slot">
                        <widget name="nimlist" position="20,10" size="360,75" />
                </screen>
                        <widget name="config" position="10,50" size="420,175" scrollbarMode="showOnDemand" />
                        <widget name="introduction" position="10,230" size="400,30" font="Arial;23" />
                </screen>
-               <screen name="PluginBrowser" position="190,125" size="360,250" title="Plugins">
-                       <widget name="title" position="10,10" size="280,35" font="Arial;23" />
-                       <widget name="pluginlist" position="10,50" size="320,200" />
-               </screen>
                <screen name="About" position="140,125" size="360,250" title="About">
                        <widget name="text" position="10,30" size="420,40" font="Arial;18"/>
                        <widget name="tuner" position="10,80" size="420,20" font="Arial;18"/>
index f83403b41ae61a5a67fe5300bb84cbfe6e0b405a..340730a67e9483f6720be61e4e5416ade55c7ff4 100644 (file)
@@ -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 (file)
index 0000000..2638206
--- /dev/null
@@ -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 (file)
index 0000000..d2ae64a
--- /dev/null
@@ -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
index e94d36f450f79b174667f31c1d9dd4f5a737fa41..1cc01544a9d9cee4a0494e5215e5ca8ea947a838 100644 (file)
@@ -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 (file)
index 0000000..d963b3c
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/lib/python/Plugins/example.py b/lib/python/Plugins/example.py
new file mode 100644 (file)
index 0000000..86e2cd1
--- /dev/null
@@ -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 = """
+               <screen position="100,100" size="200,200" title="Example plugin..." >
+                       <widget name="text" position="0,0" size="100,50" font="Arial;23" />
+               </screen>"""
+               
+       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
index 15b56d41961e71c6f3870281b0fc73d2f8c6e792..d191a5ba9a51027980c55615d42c98f3202efbc4 100644 (file)
@@ -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 (file)
index 0000000..c03aa91
--- /dev/null
@@ -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)