Merge remote-tracking branch 'remotes/origin/master' into webif_js_rewrite
[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 getTitle(self):
12                 return self.__title
13         def getText(self):
14                 return self.__text
15
16         def __getitem__(self, item):
17                 if item == 0: return self.getTitle()
18                 elif item == 1: return self.getText()
19                 raise IndexError("no more items")
20
21 class MPHelp(Screen):
22         skin = """
23                 <screen name="MPHelp" flags="wfNoBorder" position="0,0" size="720,576">
24                         <ePixmap pixmap="skin_default/buttons/red.png" position="75,10" size="140,40" alphatest="on" />
25                         <ePixmap pixmap="skin_default/buttons/green.png" position="215,10" size="140,40" alphatest="on" />
26                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="355,10" size="140,40" alphatest="on" />
27                         <ePixmap pixmap="skin_default/buttons/blue.png" position="495,10" size="140,40" alphatest="on" />
28                         <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" />
29                         <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" />
30                         <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" />
31                         <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" />
32                         <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" />
33                         <widget name="detailtext" position="60,120" size="610,370" zPosition="10" font="Regular;21" transparent="1" halign="left" valign="top"/>
34                 </screen>"""
35
36         def __init__(self, session, pages, title="", additionalSkin=""):
37                 Screen.__init__(self, session)
38                 if additionalSkin:
39                         self.skinName = [additionalSkin, "MPHelp"]
40                 self.designatedTitle = title
41
42                 self["key_red"] = StaticText(_("Close"))
43                 self["key_green"] = StaticText()
44                 self["key_yellow"] = StaticText("")
45                 if len(pages) > 1:
46                         self["key_blue"] = StaticText(">>")
47                 else:
48                         self["key_blue"] = StaticText("")
49                 self["title"] = StaticText()
50                 self["detailtext"] = ScrollLabel()
51
52                 self.pages = pages
53                 self.curPage = 0
54
55                 self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
56                 {
57                         "back": self.close,
58                         "red": self.close,
59                         "up": self.pageUp,
60                         "down": self.pageDown,
61                         "left": self.pageUp,
62                         "right": self.pageDown,
63                         "yellow": self.prevPage,
64                         "blue": self.nextPage,
65                 }, -2)
66
67                 self.onLayoutFinish.append(self.layoutFinished)
68
69         def layoutFinished(self):
70                 if self.designatedTitle:
71                         self.setTitle(self.designatedTitle)
72                 self.setPage(0)
73
74         def setPage(self, newPage):
75                 try:
76                         title, text = self.pages[newPage]
77                 except IndexError:
78                         title = "Invalid Help Page"
79                         text = "You managed to jump to an invalid page. Stop it :-)"
80                         newPage = self.curPage
81                 self["title"].text = title.encode('utf-8', 'ignore')
82                 self["detailtext"].setText(text.encode('utf-8', 'ignore'))
83                 self.curPage = newPage
84         
85         def pageUp(self):
86                 self["detailtext"].pageUp()
87
88         def pageDown(self):
89                 self["detailtext"].pageDown()
90
91         def prevPage(self):
92                 curPage = self.curPage
93                 if curPage > 0:
94                         self.setPage(curPage - 1)
95
96                 self["key_blue"].setText(">>")
97                 if self.curPage > 0:
98                         self["key_yellow"].setText("<<")
99                 else:
100                         self["key_yellow"].setText("")
101
102         def nextPage(self):
103                 curPage = self.curPage
104                 Len = len(self.pages) - 1
105                 if curPage < Len:
106                         self.setPage(curPage + 1)
107
108                 self["key_yellow"].setText("<<")
109                 if self.curPage < Len:
110                         self["key_blue"].setText(">>")
111                 else:
112                         self["key_blue"].setText("")
113
114 __all__ = ['HelpPage', 'MPHelp']