[DreamExplorer]
[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" title="MPHelp" position="center,120" size="820,520">
24                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" alphatest="on"/>
25                     <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" alphatest="on"/>
26                     <ePixmap pixmap="skin_default/buttons/yellow.png" position="410,5" size="200,40" alphatest="on"/>
27                     <ePixmap pixmap="skin_default/buttons/blue.png" position="610,5" size="200,40" alphatest="on"/>
28                     <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
29                     <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
30                     <widget source="key_yellow" render="Label" position="410,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
31                     <widget source="key_blue" render="Label" position="610,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2"/>
32                     <eLabel     position="10,50" size="800,1" backgroundColor="grey"/>
33                     <widget render="Label" source="title" position="10,60" size="800,30" font="Regular;26"/>
34                     <widget name="detailtext" position="10,120" size="800,390" font="Regular;21"/>
35                 </screen>"""
36
37         def __init__(self, session, pages, title="", additionalSkin=""):
38                 Screen.__init__(self, session)
39                 if additionalSkin:
40                         self.skinName = [additionalSkin, "MPHelp"]
41                 self.designatedTitle = title
42
43                 self["key_red"] = StaticText(_("Close"))
44                 self["key_green"] = StaticText()
45                 self["key_yellow"] = StaticText("")
46                 if len(pages) > 1:
47                         self["key_blue"] = StaticText(">>")
48                 else:
49                         self["key_blue"] = StaticText("")
50                 self["title"] = StaticText()
51                 self["detailtext"] = ScrollLabel()
52
53                 self.pages = pages
54                 self.curPage = 0
55
56                 self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
57                 {
58                         "back": self.close,
59                         "red": self.close,
60                         "up": self.pageUp,
61                         "down": self.pageDown,
62                         "left": self.pageUp,
63                         "right": self.pageDown,
64                         "yellow": self.prevPage,
65                         "blue": self.nextPage,
66                 }, -2)
67
68                 self.onLayoutFinish.append(self.layoutFinished)
69
70         def layoutFinished(self):
71                 if self.designatedTitle:
72                         self.setTitle(self.designatedTitle)
73                 self.setPage(0)
74
75         def setPage(self, newPage):
76                 try:
77                         title, text = self.pages[newPage]
78                 except IndexError:
79                         title = "Invalid Help Page"
80                         text = "You managed to jump to an invalid page. Stop it :-)"
81                         newPage = self.curPage
82                 self["Title"].text = title.encode('utf-8', 'ignore')
83                 self["detailtext"].setText(text.encode('utf-8', 'ignore'))
84                 self.curPage = newPage
85         
86         def pageUp(self):
87                 self["detailtext"].pageUp()
88
89         def pageDown(self):
90                 self["detailtext"].pageDown()
91
92         def prevPage(self):
93                 curPage = self.curPage
94                 if curPage > 0:
95                         self.setPage(curPage - 1)
96
97                 self["key_blue"].setText(">>")
98                 if self.curPage > 0:
99                         self["key_yellow"].setText("<<")
100                 else:
101                         self["key_yellow"].setText("")
102
103         def nextPage(self):
104                 curPage = self.curPage
105                 Len = len(self.pages) - 1
106                 if curPage < Len:
107                         self.setPage(curPage + 1)
108
109                 self["key_yellow"].setText("<<")
110                 if self.curPage < Len:
111                         self["key_blue"].setText(">>")
112                 else:
113                         self["key_blue"].setText("")
114
115 __all__ = ['HelpPage', 'MPHelp']