diff options
| author | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2006-01-06 15:48:47 +0000 |
|---|---|---|
| committer | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2006-01-06 15:48:47 +0000 |
| commit | bb438bec17665a907c28ca47d665766c7b26be79 (patch) | |
| tree | 498dd3e71e349dc5845cdb5e48312c166328c0dd | |
| parent | eec9fe4a7e1381ee158c75431bc5fdd685b8f552 (diff) | |
| download | enigma2-bb438bec17665a907c28ca47d665766c7b26be79.tar.gz enigma2-bb438bec17665a907c28ca47d665766c7b26be79.zip | |
plugins can register their own menu now
menus have their own id now
the update plugin for example adds a menu item to the Setup menu with the id "setup"
| -rw-r--r-- | data/menu.xml | 7 | ||||
| -rw-r--r-- | lib/python/Components/PluginComponent.py | 22 | ||||
| -rw-r--r-- | lib/python/Plugins/update.py | 62 | ||||
| -rw-r--r-- | lib/python/Screens/Menu.py | 35 | ||||
| -rw-r--r-- | mytest.py | 4 |
5 files changed, 60 insertions, 70 deletions
diff --git a/data/menu.xml b/data/menu.xml index 7f0df144..cf17421e 100644 --- a/data/menu.xml +++ b/data/menu.xml @@ -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" @@ -21,18 +21,21 @@ <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> diff --git a/lib/python/Components/PluginComponent.py b/lib/python/Components/PluginComponent.py index f1a0a95a..5315d3d9 100644 --- a/lib/python/Components/PluginComponent.py +++ b/lib/python/Components/PluginComponent.py @@ -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] diff --git a/lib/python/Plugins/update.py b/lib/python/Plugins/update.py index d05d317e..e69de29b 100644 --- a/lib/python/Plugins/update.py +++ b/lib/python/Plugins/update.py @@ -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 diff --git a/lib/python/Screens/Menu.py b/lib/python/Screens/Menu.py index 0abc1735..4ad36d18 100644 --- a/lib/python/Screens/Menu.py +++ b/lib/python/Screens/Menu.py @@ -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) @@ -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 = ""): |
