mphelp: use custom object (HelpPage) for help pages
[enigma2-plugins.git] / mphelp / src / MPHelp.py
1 from Screens.Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ScrollLabel import ScrollLabel
4 from Components.Sources.StaticText import StaticText
5
6 class HelpPage:
7         def __init__(self, title, text):
8                 self.title = title
9                 self.text = text
10
11         def __getitem__(self, item):
12                 if item == 0: return self.title
13                 elif item == 1: return self.text
14                 raise IndexError("no more items")
15
16 class MPHelp(Screen):
17         skin = """
18                 <screen name="MPHelp" flags="wfNoBorder" position="0,0" size="720,576">
19                         <ePixmap pixmap="skin_default/buttons/red.png" position="75,10" size="140,40" alphatest="on" />
20                         <ePixmap pixmap="skin_default/buttons/green.png" position="215,10" size="140,40" alphatest="on" />
21                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="355,10" size="140,40" alphatest="on" />
22                         <ePixmap pixmap="skin_default/buttons/blue.png" position="495,10" size="140,40" alphatest="on" />
23                         <widget render="Label" source="key_red" position="75,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
24                         <!--<widget render="Label" source="key_green" position="215,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />-->
25                         <widget render="Label" source="key_yellow" position="355,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
26                         <widget render="Label" source="key_blue" position="495,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
27                         <widget render="Label" source="title" position="60,50" size="600,50" zPosition="5" valign="center" halign="left" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
28                         <widget name="detailtext" position="60,120" size="610,370" zPosition="10" font="Regular;21" transparent="1" halign="left" valign="top"/>
29                 </screen>"""
30
31         def __init__(self, session, pages, title="", additionalSkin=""):
32                 Screen.__init__(self, session)
33                 if additionalSkin:
34                         self.skinName = [additionalSkin, "MPHelp"]
35                 self.designatedTitle = title
36
37                 self["key_red"] = StaticText(_("Close"))
38                 #self["key_green"] = StaticText()
39                 self["key_yellow"] = StaticText("<<")
40                 self["key_blue"] = StaticText(">>")
41                 self["title"] = StaticText()
42                 self["detailtext"] = ScrollLabel()
43
44                 self.pages = pages
45                 self.curPage = 0
46
47                 self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
48                 {
49                         "back": self.close,
50                         "red": self.close,
51                         "up": self.pageUp,
52                         "down": self.pageDown,
53                         "left": self.pageUp,
54                         "right": self.pageDown,
55                         "yellow": self.prevPage,
56                         "blue": self.nextPage,
57                 }, -2)
58
59                 self.onLayoutFinish.append(self.layoutFinished)
60
61         def layoutFinished(self):
62                 if self.designatedTitle:
63                         self.setTitle(self.designatedTitle)
64                 self.setPage(0)
65
66         def setPage(self, newPage):
67                 try:
68                         title, text = self.pages[newPage]
69                 except IndexError:
70                         title = "Invalid Help Page"
71                         text = "You managed to jump to an invalid page. Stop it :-)"
72                         newPage = self.curPage
73                 self["title"].text = title
74                 self["detailtext"].setText(text)
75                 self.curPage = newPage
76         
77         def pageUp(self):
78                 self["detailtext"].pageUp()
79
80         def pageDown(self):
81                 self["detailtext"].pageDown()
82
83         def prevPage(self):
84                 if self.curPage > 0:
85                         self.setPage(self.curPage - 1)
86
87         def nextPage(self):
88                 if self.curPage < len(self.pages) - 1:
89                         self.setPage(self.curPage + 1)
90
91 __all__ = ['HelpPage', 'MPHelp']