mphelp: initial checkin
[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 MPHelp(Screen):
7         skin = """
8                 <screen name="MPHelp" flags="wfNoBorder" position="0,0" size="720,576">
9                         <ePixmap pixmap="skin_default/buttons/red.png" position="75,10" size="140,40" alphatest="on" />
10                         <ePixmap pixmap="skin_default/buttons/green.png" position="215,10" size="140,40" alphatest="on" />
11                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="355,10" size="140,40" alphatest="on" />
12                         <ePixmap pixmap="skin_default/buttons/blue.png" position="495,10" size="140,40" alphatest="on" />
13                         <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" />
14                         <!--<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" />-->
15                         <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" />
16                         <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" />
17                         <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" />
18                         <widget name="detailtext" position="60,120" size="610,370" zPosition="10" font="Regular;21" transparent="1" halign="left" valign="top"/>
19                 </screen>"""
20
21         def __init__(self, session, pages, title="", additionalSkin=""):
22                 Screen.__init__(self, session)
23                 if additionalSkin:
24                         self.skinName = [additionalSkin, "MPHelp"]
25                 self.designatedTitle = title
26
27                 self["key_red"] = StaticText(_("Close"))
28                 #self["key_green"] = StaticText()
29                 self["key_yellow"] = StaticText("<<")
30                 self["key_blue"] = StaticText(">>")
31                 self["title"] = StaticText()
32                 self["detailtext"] = ScrollLabel()
33
34                 self.pages = pages
35                 self.curPage = 0
36
37                 self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
38                 {
39                         "back": self.close,
40                         "red": self.close,
41                         "up": self.pageUp,
42                         "down": self.pageDown,
43                         "left": self.pageUp,
44                         "right": self.pageDown,
45                         "yellow": self.prevPage,
46                         "blue": self.nextPage,
47                 }, -2)
48
49                 self.onLayoutFinish.append(self.layoutFinished)
50
51         def layoutFinished(self):
52                 if self.designatedTitle:
53                         self.setTitle(self.designatedTitle)
54                 self.setPage(0)
55
56         def setPage(self, newPage):
57                 try:
58                         title, text = self.pages[newPage]
59                 except IndexError:
60                         title = "Invalid Help Page"
61                         text = "You managed to jump to an invalid page. Stop it :-)"
62                         newPage = self.curPage
63                 self["title"].text = title
64                 self["detailtext"].setText(text)
65                 self.curPage = newPage
66         
67         def pageUp(self):
68                 self["detailtext"].pageUp()
69
70         def pageDown(self):
71                 self["detailtext"].pageDown()
72
73         def prevPage(self):
74                 if self.curPage > 0:
75                         self.setPage(self.curPage - 1)
76
77         def nextPage(self):
78                 if self.curPage < len(self.pages) - 1:
79                         self.setPage(self.curPage + 1)
80