Merge remote-tracking branch 'remotes/origin/master' into webif_js_rewrite
[enigma2-plugins.git] / mphelp / src / plugin.py
1 #from Plugins.Plugin import PluginDescriptor
2 from MPHelp import MPHelp
3
4 from collections import Callable
5
6 helpList = []
7
8 class PluginHelp(object):
9         def __init__(self, getNameFunc, getPagesFunc, additionalSkin=""):
10                 if not isinstance(getNameFunc, Callable):
11                         getNameFunc = lambda x: getNameFunc
12                 self.getNameFunc = getNameFunc
13
14                 if not isinstance(getPagesFunc, Callable):
15                         getPagesFunc = lambda x: getPagesFunc
16                 self.getPagesFunc = getPagesFunc
17
18                 self.additionalSkin = additionalSkin
19
20         def __getattr__(self, attr):
21                 if attr == "name": return self.getNameFunc()
22                 elif attr == "pages": return self.getPagesFunc()
23                 return object.__getattr__(self, attr)
24
25         def open(self, session):
26                 session.open(MPHelp, self.pages, title=self.name, additionalSkin=self.additionalSkin)
27
28         def openWithCallback(self, session, callback):
29                 assert isinstance(callback, Callable), "callback has to be callable!"
30                 session.openWithCallback(callback, MPHelp, self.pages, title=self.name, additionalSkin=self.additionalSkin)
31
32 def registerHelp(getNameFunc, getPagesFunc, additionalSkin=""):
33         curName = getNameFunc()
34         for x in helpList:
35                 if x.name == curName:
36                         return x
37         x = PluginHelp(getNameFunc, getPagesFunc, additionalSkin=additionalSkin)
38         helpList.append(x)
39         return x
40
41 def showHelp(session, curName, callback=None):
42         for x in helpList:
43                 if x.name == curName:
44                         if callback:
45                                 x.openWithCallback(session, callback)
46                         else:
47                                 x.open(session)
48                         return True
49         return False
50
51 def Plugins(**kwargs):
52         return [
53         ]
54
55 __all__ = ['Plugins', 'registerHelp', 'showHelp', 'PluginHelp']