1 from enigma import iPlayableService, loadPNG, iRdsDecoder, ePoint, gRGB
2 from Screens.Screen import Screen
3 from Components.Sources.RdsDecoder import RdsDecoder
4 from Components.ActionMap import NumberActionMap
5 from Components.ServiceEventTracker import ServiceEventTracker
6 from Components.Pixmap import Pixmap
7 from Components.Label import Label
8 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
10 class RdsInfoDisplay(Screen):
13 def __init__(self, session):
14 Screen.__init__(self, session)
16 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
18 iPlayableService.evEnd: self.__serviceStopped,
19 iPlayableService.evUpdatedRadioText: self.RadioTextChanged,
20 iPlayableService.evUpdatedRtpText: self.RtpTextChanged,
21 iPlayableService.evUpdatedRassInteractivePicMask: self.RassInteractivePicMaskChanged,
24 self["RadioText"] = Label()
25 self["RtpText"] = Label()
26 self["RassLogo"] = Pixmap()
28 self.onLayoutFinish.append(self.hideWidgets)
29 self.rassInteractivePossible=False
30 self.onRassInteractivePossibilityChanged = [ ]
32 def hideWidgets(self):
33 for x in (self["RadioText"],self["RtpText"],self["RassLogo"]):
36 def RadioTextChanged(self):
37 service = self.session.nav.getCurrentService()
38 decoder = service and service.rdsDecoder()
39 rdsText = decoder and decoder.getText(iRdsDecoder.RadioText)
40 if rdsText and len(rdsText):
41 self["RadioText"].setText(rdsText)
42 self["RadioText"].show()
44 self["RadioText"].hide()
46 def RtpTextChanged(self):
47 service = self.session.nav.getCurrentService()
48 decoder = service and service.rdsDecoder()
49 rtpText = decoder and decoder.getText(iRdsDecoder.RtpText)
50 if rtpText and len(rtpText):
51 self["RtpText"].setText(rtpText)
52 self["RtpText"].show()
54 self["RtpText"].hide()
56 def RassInteractivePicMaskChanged(self):
57 if not self.rassInteractivePossible:
58 service = self.session.nav.getCurrentService()
59 decoder = service and service.rdsDecoder()
60 mask = decoder and decoder.getRassInteractiveMask()
61 if mask[0] & 1: #rass interactive index page available
62 self["RassLogo"].show()
63 self.rassInteractivePossible = True
64 for x in self.onRassInteractivePossibilityChanged:
67 def __serviceStopped(self):
69 if self.rassInteractivePossible:
70 self.rassInteractivePossible = False
71 for x in self.onRassInteractivePossibilityChanged:
74 class RassInteractive(Screen):
75 def __init__(self, session):
76 Screen.__init__(self, session)
78 self["actions"] = NumberActionMap( [ "NumberActions", "RassInteractiveActions" ],
81 "0": lambda x : self.numPressed(0),
82 "1": lambda x : self.numPressed(1),
83 "2": lambda x : self.numPressed(2),
84 "3": lambda x : self.numPressed(3),
85 "4": lambda x : self.numPressed(4),
86 "5": lambda x : self.numPressed(5),
87 "6": lambda x : self.numPressed(6),
88 "7": lambda x : self.numPressed(7),
89 "8": lambda x : self.numPressed(8),
90 "9": lambda x : self.numPressed(9),
91 "nextPage": self.nextPage,
92 "prevPage": self.prevPage,
93 "nextSubPage": self.nextSubPage,
94 "prevSubPage": self.prevSubPage
97 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
99 iPlayableService.evUpdatedRassInteractivePicMask: self.recvRassInteractivePicMaskChanged
102 self["subpages_1"] = Pixmap()
103 self["subpages_2"] = Pixmap()
104 self["subpages_3"] = Pixmap()
105 self["subpages_4"] = Pixmap()
106 self["subpages_5"] = Pixmap()
107 self["subpages_6"] = Pixmap()
108 self["subpages_7"] = Pixmap()
109 self["subpages_8"] = Pixmap()
110 self["subpages_9"] = Pixmap()
111 self["Marker"] = Label(">")
114 1 : self["subpages_1"],
115 2 : self["subpages_2"],
116 3 : self["subpages_3"],
117 4 : self["subpages_4"],
118 5 : self["subpages_5"],
119 6 : self["subpages_6"],
120 7 : self["subpages_7"],
121 8 : self["subpages_8"],
122 9 : self["subpages_9"] }
125 1 : loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "rass_page1.png")),
126 2 : loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "rass_page2.png")),
127 3 : loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "rass_page3.png")),
128 4 : loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "rass_page4.png")) }
131 self.current_subpage=0;
132 self.showRassPage(0,0)
133 self.onLayoutFinish.append(self.updateSubPagePixmaps)
135 def updateSubPagePixmaps(self):
136 service = self.session.nav.getCurrentService()
137 decoder = service and service.rdsDecoder()
138 if not decoder: # this should never happen
139 print "NO RDS DECODER in showRassPage"
141 mask = decoder.getRassInteractiveMask()
144 subpage_cnt = self.countAvailSubpages(page, mask)
145 subpage = self.subpage[page]
148 png = self.subpage_png[subpage_cnt]
150 subpage.instance.setPixmap(png)
153 print "rass png missing"
158 def recvRassInteractivePicMaskChanged(self):
159 self.updateSubPagePixmaps()
161 def showRassPage(self, page, subpage):
162 service = self.session.nav.getCurrentService()
163 decoder = service and service.rdsDecoder()
164 if not decoder: # this should never happen
165 print "NO RDS DECODER in showRassPage"
167 decoder.showRassInteractivePic(page, subpage)
168 page_diff = page - self.current_page
169 self.current_page = page
171 current_pos = self["Marker"].getPosition()
174 self["Marker"].setPosition(current_pos[0],y)
176 def getMaskForPage(self, page, masks=None):
178 service = self.session.nav.getCurrentService()
179 decoder = service and service.rdsDecoder()
180 if not decoder: # this should never happen
181 print "NO RDS DECODER in getMaskForPage"
182 masks = decoder.getRassInteractiveMask()
184 mask = masks[(page*4)/8]
191 def countAvailSubpages(self, page, masks):
192 mask = self.getMaskForPage(page, masks)
202 page = self.current_page
207 mask = self.getMaskForPage(page)
208 self.numPressed(page)
212 page = self.current_page
218 mask = self.getMaskForPage(page)
219 self.numPressed(page)
221 def nextSubPage(self):
222 self.numPressed(self.current_page)
224 def prevSubPage(self):
225 num = self.current_page
226 mask = self.getMaskForPage(num)
227 cur_bit = 1 << self.current_subpage
234 if tmp == cur_bit: # no other subpage avail
236 if mask & tmp: # next subpage found
238 while tmp > 1: # convert bit to subpage
241 self.current_subpage = subpage
242 self.showRassPage(num, subpage)
245 def numPressed(self, num):
246 mask = self.getMaskForPage(num)
247 if self.current_page == num:
249 cur_bit = 1 << self.current_subpage
257 if tmp == 8 and cur_bit < 16:
263 if tmp == cur_bit: # no other subpage avail
265 if mask & tmp: # next subpage found
267 while tmp > 1: # convert bit to subpage
270 self.current_subpage = subpage
271 self.showRassPage(num, subpage)