Merge remote-tracking branch 'remotes/origin/master' into webif_js_rewrite
[enigma2-plugins.git] / mphelp / src / XMLHelp.py
1 from MPHelp import HelpPage
2 from xml.etree.cElementTree import parse as cet_parse
3
4 class XMLHelpPage(HelpPage):
5         def __init__(self, node):
6                 # calling HelpPage.__init__ is not required
7                 self.node = node
8
9         def getText(self):
10                 node = self.node.find('text')
11                 if node is not None:
12                         return _(node.get('value', ''))
13                 return ""
14
15         def getTitle(self):
16                 return _(self.node.get('title', ''))
17
18 class XMLHelpReader:
19         def __init__(self, filename):
20                 # this may raise an exception, it is up to the caller to handle that
21                 self.__dom = cet_parse(filename).getroot()
22
23         def __getitem__(self, index):
24                 if self.__dom:
25                         if index == 0:
26                                 caption = self.__dom.get('caption', '')
27                                 return lambda: _(caption)
28                         elif index == 1:
29                                 return lambda: [XMLHelpPage(x) for x in self.__dom.findall('page')]
30                         elif index == 2:
31                                 return self.__dom.get('skin', "") # additional skin name
32                         raise IndexError('no more indices')
33                 raise RuntimeError('no valid dom')
34
35 __all__ = ['XMLHelpReader']