add possibility to use ValueRange as ValueEqual Converter
[enigma2.git] / lib / python / Components / Converter / RdsInfo.py
1 from enigma import iRdsDecoder, iPlayableService
2 from Components.Converter.Converter import Converter
3 from Components.Element import cached
4
5 class RdsInfo(Converter, object):
6         RASS_INTERACTIVE_AVAILABLE = 0
7         RTP_TEXT_CHANGED = 1
8         RADIO_TEXT_CHANGED = 2
9
10         def __init__(self, type):
11                 Converter.__init__(self, type)
12                 self.type = {
13                                 "RadioText": self.RADIO_TEXT_CHANGED,
14                                 "RtpText": self.RTP_TEXT_CHANGED,
15                                 "RasInteractiveAvailable": self.RASS_INTERACTIVE_AVAILABLE
16                         }[type]
17
18                 self.interesting_events = {
19                                 self.RADIO_TEXT_CHANGED: [iPlayableService.evUpdatedRadioText],
20                                 self.RTP_TEXT_CHANGED: [iPlayableService.evUpdatedRtpText],
21                                 self.RASS_INTERACTIVE_AVAILABLE: [iPlayableService.evUpdatedRassInteractivePicMask]
22                         }[self.type]
23
24         @cached
25         def getText(self):
26                 decoder = self.source.decoder
27                 text = ""
28                 if decoder:
29                         if self.type == self.RADIO_TEXT_CHANGED:
30                                 text = decoder.getText(iRdsDecoder.RadioText)
31                         elif self.type == self.RTP_TEXT_CHANGED:
32                                 text = decoder.getText(iRdsDecoder.RtpText)
33                         else:
34                                 print "unknown RdsInfo Converter type", self.type
35                 return text
36
37         text = property(getText)
38
39         @cached
40         def getBoolean(self):
41                 decoder = self.source.decoder
42                 if self.type == self.RASS_INTERACTIVE_AVAILABLE:
43                         mask = decoder and decoder.getRassInteractiveMask()
44                         return (mask and mask[0] & 1 and True) or False
45                 elif self.type == self.RADIO_TEXT_CHANGED:
46                         return (len(decoder.getText(iRdsDecoder.RadioText)) and True) or False
47                 elif self.type == self.RTP_TEXT_CHANGED:
48                         return (len(decoder.getText(iRdsDecoder.RtpText)) and True) or False
49         boolean = property(getBoolean)
50
51         def changed(self, what):
52                 if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
53                         Converter.changed(self, what)