2 from HTMLComponent import HTMLComponent
3 from GUIComponent import GUIComponent
4 from enigma import eLabel, eWidget, eSlider, fontRenderClass, ePoint, eSize
6 class ScrollLabel(HTMLComponent, GUIComponent):
7 def __init__(self, text=""):
8 GUIComponent.__init__(self)
16 def applySkin(self, desktop):
18 if self.skinAttributes is not None:
19 skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes)
21 scrollbar_attribs = [ ]
22 for (attrib, value) in self.skinAttributes:
23 if attrib.find("borderColor") != -1 or attrib.find("borderWidth") != -1:
24 scrollbar_attribs.append((attrib,value))
25 if attrib.find("transparent") != -1 or attrib.find("backgroundColor") != -1:
26 widget_attribs.append((attrib,value))
27 skin.applyAllAttributes(self.instance, desktop, widget_attribs)
28 skin.applyAllAttributes(self.scrollbar, desktop, scrollbar_attribs+widget_attribs)
30 s = self.long_text.size()
31 self.instance.move(self.long_text.position())
32 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
33 lines = (int)(s.height() / lineheight)
34 self.pageHeight = (int)(lines * lineheight)
35 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
36 self.scrollbar.move(ePoint(s.width()-20,0))
37 self.scrollbar.resize(eSize(20,self.pageHeight+(int)(lineheight/6)))
38 self.scrollbar.setOrientation(eSlider.orVertical);
39 self.scrollbar.setRange(0,100)
40 self.scrollbar.setBorderWidth(1)
41 self.long_text.move(ePoint(0,0))
42 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
43 self.setText(self.message)
46 def setText(self, text):
48 if self.long_text is not None and self.pageHeight:
49 self.long_text.move(ePoint(0,0))
50 self.long_text.setText(self.message)
51 text_height=self.long_text.calculateSize().height()
54 while total < text_height:
55 total=total+self.pageHeight
61 self.updateScrollbar()
67 def appendText(self, text):
68 old_text = self.getText()
69 if len(str(old_text)) >0:
73 if self.long_text is not None:
74 self.long_text.setText(self.message)
75 text_height=self.long_text.calculateSize().height()
78 while total < text_height:
79 total=total+self.pageHeight
85 self.updateScrollbar()
91 def updateScrollbar(self):
92 start = -self.long_text.position().y() * 100 / self.total
93 vis = self.pageHeight * 100 / self.total;
94 self.scrollbar.setStartEnd(start, start+vis)
99 def GUIcreate(self, parent):
100 self.instance = eWidget(parent)
101 self.scrollbar = eSlider(self.instance)
102 self.long_text = eLabel(self.instance)
105 self.long_text = None
106 self.scrollbar = None
110 if self.total is not None:
111 curPos = self.long_text.position()
113 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
114 self.updateScrollbar()
117 if self.total is not None:
118 curPos = self.long_text.position()
119 if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
120 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
121 self.updateScrollbar()
125 while i < self.pages:
128 self.updateScrollbar()
130 def produceHTML(self):
131 return self.getText()