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):
17 skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes)
18 s = self.long_text.size()
19 self.instance.move(self.long_text.position())
20 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
21 lines = (int)(s.height() / lineheight)
22 self.pageHeight = (int)(lines * lineheight)
23 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
24 self.scrollbar.move(ePoint(s.width()-20,0))
25 self.scrollbar.resize(eSize(20,self.pageHeight+(int)(lineheight/6)))
26 self.scrollbar.setOrientation(eSlider.orVertical);
27 self.scrollbar.setRange(0,100)
28 self.scrollbar.setBorderWidth(1)
29 self.long_text.move(ePoint(0,0))
30 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
31 self.setText(self.message)
33 def setText(self, text):
35 if self.long_text is not None:
36 self.long_text.move(ePoint(0,0))
37 self.long_text.setText(self.message)
38 text_height=self.long_text.calculateSize().height()
41 while total < text_height:
42 total=total+self.pageHeight
48 self.updateScrollbar()
54 def appendText(self, text):
55 old_text = self.getText()
56 if len(str(old_text)) >0:
60 if self.long_text is not None:
61 self.long_text.setText(self.message)
62 text_height=self.long_text.calculateSize().height()
65 while total < text_height:
66 total=total+self.pageHeight
72 self.updateScrollbar()
78 def updateScrollbar(self):
79 start = -self.long_text.position().y() * 100 / self.total
80 vis = self.pageHeight * 100 / self.total;
81 self.scrollbar.setStartEnd(start, start+vis)
86 def GUIcreate(self, parent):
87 self.instance = eWidget(parent)
88 self.scrollbar = eSlider(self.instance)
89 self.long_text = eLabel(self.instance)
97 if self.total is not None:
98 curPos = self.long_text.position()
100 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
101 self.updateScrollbar()
104 if self.total is not None:
105 curPos = self.long_text.position()
106 if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
107 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
108 self.updateScrollbar()
112 while i < self.pages:
115 self.updateScrollbar()
117 def produceHTML(self):
118 return self.getText()