1efce8fabee0b1ef08642e72df83ff7f9b6689d8
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Label.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from VariableText import VariableText
4 from skin import parseColor
5 from ConditionalWidget import ConditionalWidget, BlinkingWidget, BlinkingWidgetConditional
6
7 from enigma import eLabel
8
9 class Label(VariableText, HTMLComponent, GUIComponent):
10         def __init__(self, text=""):
11                 GUIComponent.__init__(self)
12                 VariableText.__init__(self)
13                 self.setText(text)
14
15 # fake Source methods:
16         def connectDownstream(self, downstream):
17                 pass
18
19         def checkSuspend(self):
20                 pass
21
22         def disconnectDownstream(self, downstream):
23                 pass
24
25 # html:
26         def produceHTML(self):
27                 return self.getText()
28
29 # GUI:
30         GUI_WIDGET = eLabel
31
32         def getSize(self):
33                 s = self.instance.calculateSize()
34                 return (s.width(), s.height())
35
36 class LabelConditional(Label, ConditionalWidget):
37         def __init__(self, text = "", withTimer = True):
38                 ConditionalWidget.__init__(self, withTimer = withTimer)
39                 Label.__init__(self, text = text)
40
41 class BlinkingLabel(Label, BlinkingWidget):
42         def __init__(self, text = ""):
43                 Label.__init__(text = text)
44                 BlinkingWidget.__init__()
45
46 class BlinkingLabelConditional(BlinkingWidgetConditional, LabelConditional):
47         def __init__(self, text = ""):
48                 LabelConditional.__init__(self, text = text)
49                 BlinkingWidgetConditional.__init__(self)
50
51 class MultiColorLabel(Label):
52         def __init__(self, text=""):
53                 Label.__init__(self,text)
54                 self.foreColors = []
55                 self.backColors = []
56
57         def applySkin(self, desktop, screen):
58                 if self.skinAttributes is not None:
59                         foregroundColor = None
60                         backgroundColor = None
61                         attribs = [ ]
62                         for (attrib, value) in self.skinAttributes:
63                                 if attrib == "foregroundColors":
64                                         colors = value.split(',')
65                                         for color in colors:
66                                                 self.foreColors.append(parseColor(color))
67                                         if not foregroundColor:
68                                                 foregroundColor = colors[0]
69                                 elif attrib == "backgroundColors":
70                                         colors = value.split(',')
71                                         for color in colors:
72                                                 self.backColors.append(parseColor(color))
73                                         if not backgroundColor:
74                                                 backgroundColor = colors[0]
75                                 elif attrib == "backgroundColor":
76                                         backgroundColor = value
77                                 elif attrib == "foregroundColor":
78                                         foregroundColor = value
79                                 else:
80                                         attribs.append((attrib,value))
81                         if foregroundColor:
82                                 attribs.append(("foregroundColor",foregroundColor))
83                         if backgroundColor:
84                                 attribs.append(("backgroundColor",backgroundColor))
85                         self.skinAttributes = attribs
86                 return GUIComponent.applySkin(self, desktop, screen)
87
88         def setForegroundColorNum(self, x):
89                 if self.instance:
90                         if len(self.foreColors) > x:
91                                 self.instance.setForegroundColor(self.foreColors[x])
92                         else:
93                                 print "setForegroundColorNum(%d) failed! defined colors:" %(x), self.foreColors
94
95         def setBackgroundColorNum(self, x):
96                 if self.instance:
97                         if len(self.backColors) > x:
98                                 self.instance.setBackgroundColor(self.backColors[x])
99                         else:
100                                 print "setBackgroundColorNum(%d) failed! defined colors:" %(x), self.backColors
101