5f74b75c8164503e98385e5494057816d7fb8b85
[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 # html: 
16         def produceHTML(self):
17                 return self.getText()
18
19 # GUI:
20         GUI_WIDGET = eLabel
21
22         def getSize(self):
23                 s = self.instance.calculateSize()
24                 return (s.width(), s.height())
25
26 class LabelConditional(Label, ConditionalWidget):
27         def __init__(self, text = "", withTimer = True):
28                 ConditionalWidget.__init__(self, withTimer = withTimer)
29                 Label.__init__(self, text = text)
30                 
31 class BlinkingLabel(Label, BlinkingWidget):
32         def __init__(self, text = ""):
33                 Label.__init__(text = text)
34                 BlinkingWidget.__init__()
35
36 class BlinkingLabelConditional(BlinkingWidgetConditional, LabelConditional):
37         def __init__(self, text = ""):
38                 LabelConditional.__init__(self, text = text)
39                 BlinkingWidgetConditional.__init__(self)
40
41 class MultiColorLabel(Label):
42         def __init__(self, text=""):
43                 Label.__init__(self,text)
44                 self.foreColors = []
45                 self.backColors = []
46
47         def applySkin(self, desktop, screen):
48                 if self.skinAttributes is not None:
49                         attribs = [ ]
50                         for (attrib, value) in self.skinAttributes:
51                                 if attrib == "foregroundColors":
52                                         colors = value.split(',')
53                                         attribs.append(("foregroundColor",colors[0] ))
54                                         for color in colors:
55                                                 self.foreColors.append(parseColor(color))
56                                 elif attrib == "backgroundColors":
57                                         colors = value.split(',')
58                                         attribs.append(("backgroundColor",colors[0] ))
59                                         for color in colors:
60                                                 self.backColors.append(parseColor(color))
61                                 else:
62                                         attribs.append((attrib,value))
63                         self.skinAttributes = attribs
64                 return GUIComponent.applySkin(self, desktop, screen)
65         
66         def setForegroundColorNum(self, x):
67                 if self.instance:
68                         if len(self.foreColors) > x:
69                                 self.instance.setForegroundColor(self.foreColors[x])
70                         else:
71                                 print "setForegroundColorNum(%d) failed! defined colors:" %(x), self.foreColors
72
73         def setBackgroundColorNum(self, x):
74                 if self.instance:
75                         if len(self.backColors) > x:
76                                 self.instance.setBackgroundColor(self.backColors[x])
77                         else:
78                                 print "setBackgroundColorNum(%d) failed! defined colors:" %(x), self.backColors
79