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=""):
15 def applySkin(self, desktop):
16 skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes)
17 s = self.long_text.size()
18 self.instance.move(self.long_text.position())
19 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
20 lines = (int)(s.height() / lineheight)
21 self.pageHeight = (int)(lines * lineheight)
22 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
23 self.scrollbar.move(ePoint(s.width()-20,0))
24 self.scrollbar.resize(eSize(20,self.pageHeight+(int)(lineheight/6)))
25 self.scrollbar.setOrientation(eSlider.orVertical);
26 self.scrollbar.setRange(0,100)
27 self.scrollbar.setBorderWidth(1)
28 self.long_text.move(ePoint(0,0))
29 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
30 self.setText(self.message)
32 def setText(self, text):
34 if self.long_text is not None:
35 self.long_text.move(ePoint(0,0))
36 self.long_text.setText(self.message)
37 text_height=self.long_text.calculateSize().height()
40 while total < text_height:
41 total=total+self.pageHeight
47 self.updateScrollbar()
53 def appendText(self, text):
54 old_text = self.getText()
55 if len(str(old_text)) >0:
59 if self.long_text is not None:
60 self.long_text.setText(self.message)
61 text_height=self.long_text.calculateSize().height()
64 while total < text_height:
65 total=total+self.pageHeight
71 self.updateScrollbar()
77 def updateScrollbar(self):
78 start = -self.long_text.position().y() * 100 / self.total
79 vis = self.pageHeight * 100 / self.total;
80 self.scrollbar.setStartEnd(start, start+vis)
85 def GUIcreate(self, parent):
86 self.instance = eWidget(parent)
87 self.scrollbar = eSlider(self.instance)
88 self.long_text = eLabel(self.instance)
96 if self.total is not None:
97 curPos = self.long_text.position()
99 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
100 self.updateScrollbar()
103 if self.total is not None:
104 curPos = self.long_text.position()
105 if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
106 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
107 self.updateScrollbar()
111 while i < self.pages:
114 self.updateScrollbar()
116 def produceHTML(self):
117 return self.getText()