mphelp: use custom object (HelpPage) for help pages
[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                         print "NOT CALLABLE?!"
12                         getNameFunc = lambda x: getNameFunc
13                 self.getNameFunc = getNameFunc
14
15                 if not isinstance(getPagesFunc, Callable):
16                         print "NOT CALLABLE EITHER?!"
17                         getPagesFunc = lambda x: getPagesFunc
18                 self.getPagesFunc = getPagesFunc
19
20                 self.additionalSkin = additionalSkin
21
22         def __getattr__(self, attr):
23                 if attr == "name": return self.getNameFunc()
24                 elif attr == "pages": return self.getPagesFunc()
25                 return object.__getattr__(self, attr)
26
27         def open(self, session):
28                 session.open(MPHelp, self.pages, title=self.name, additionalSkin=self.additionalSkin)
29
30         def openWithCallback(self, session, callback):
31                 assert isinstance(callback, Callable), "callback has to be callable!"
32                 session.openWithCallback(callback, MPHelp, self.pages, title=self.name, additionalSkin=self.additionalSkin)
33
34 def registerHelp(getNameFunc, getPagesFunc, additionalSkin=""):
35         curName = getNameFunc()
36         for x in helpList:
37                 if x.name == curName:
38                         return x
39         x = PluginHelp(getNameFunc, getPagesFunc, additionalSkin=additionalSkin)
40         helpList.append(x)
41         return x
42
43 def showHelp(session, curName, callback=None):
44         for x in helpList:
45                 if x.name == curName:
46                         if callback:
47                                 x.openWithCallback(session, callback)
48                         else:
49                                 x.open(session)
50                         return True
51         return False
52
53 def Plugins(**kwargs):
54         return [
55         ]
56
57 __all__ = ['Plugins', 'registerHelp', 'showHelp']