mphelp: remove debug
[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                 self["key_blue"] = StaticText(">>")
46                 self["title"] = StaticText()
47                 self["detailtext"] = ScrollLabel()
48
49                 self.pages = pages
50                 self.curPage = 0
51
52                 self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
53                 {
54                         "back": self.close,
55                         "red": self.close,
56                         "up": self.pageUp,
57                         "down": self.pageDown,
58                         "left": self.pageUp,
59                         "right": self.pageDown,
60                         "yellow": self.prevPage,
61                         "blue": self.nextPage,
62                 }, -2)
63
64                 self.onLayoutFinish.append(self.layoutFinished)
65
66         def layoutFinished(self):
67                 if self.designatedTitle:
68                         self.setTitle(self.designatedTitle)
69                 self.setPage(0)
70
71         def setPage(self, newPage):
72                 try:
73                         title, text = self.pages[newPage]
74                 except IndexError:
75                         title = "Invalid Help Page"
76                         text = "You managed to jump to an invalid page. Stop it :-)"
77                         newPage = self.curPage
78                 self["title"].text = title
79                 self["detailtext"].setText(text)
80                 self.curPage = newPage
81         
82         def pageUp(self):
83                 self["detailtext"].pageUp()
84
85         def pageDown(self):
86                 self["detailtext"].pageDown()
87
88         def prevPage(self):
89                 if self.curPage > 0:
90                         self.setPage(self.curPage - 1)
91
92         def nextPage(self):
93                 if self.curPage < len(self.pages) - 1:
94                         self.setPage(self.curPage + 1)
95
96 __all__ = ['HelpPage', 'MPHelp']