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 for (attrib, value) in self.skinAttributes:
22 if attrib.find("Color") != -1 or attrib.find("transparent") != -1:
23 attribs.append((attrib,value))
24 skin.applyAllAttributes(self.instance, desktop, attribs)
25 skin.applyAllAttributes(self.scrollbar, desktop, attribs)
27 s = self.long_text.size()
28 self.instance.move(self.long_text.position())
29 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
30 lines = (int)(s.height() / lineheight)
31 self.pageHeight = (int)(lines * lineheight)
32 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
33 self.scrollbar.move(ePoint(s.width()-20,0))
34 self.scrollbar.resize(eSize(20,self.pageHeight+(int)(lineheight/6)))
35 self.scrollbar.setOrientation(eSlider.orVertical);
36 self.scrollbar.setRange(0,100)
37 self.scrollbar.setBorderWidth(1)
38 self.long_text.move(ePoint(0,0))
39 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
40 self.setText(self.message)
43 def setText(self, text):
45 if self.long_text is not None and self.pageHeight:
46 self.long_text.move(ePoint(0,0))
47 self.long_text.setText(self.message)
48 text_height=self.long_text.calculateSize().height()
51 while total < text_height:
52 total=total+self.pageHeight
58 self.updateScrollbar()
64 def appendText(self, text):
65 old_text = self.getText()
66 if len(str(old_text)) >0:
70 if self.long_text is not None:
71 self.long_text.setText(self.message)
72 text_height=self.long_text.calculateSize().height()
75 while total < text_height:
76 total=total+self.pageHeight
82 self.updateScrollbar()
88 def updateScrollbar(self):
89 start = -self.long_text.position().y() * 100 / self.total
90 vis = self.pageHeight * 100 / self.total;
91 self.scrollbar.setStartEnd(start, start+vis)
96 def GUIcreate(self, parent):
97 self.instance = eWidget(parent)
98 self.scrollbar = eSlider(self.instance)
99 self.long_text = eLabel(self.instance)
102 self.long_text = None
103 self.scrollbar = None
107 if self.total is not None:
108 curPos = self.long_text.position()
110 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
111 self.updateScrollbar()
114 if self.total is not None:
115 curPos = self.long_text.position()
116 if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
117 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
118 self.updateScrollbar()
122 while i < self.pages:
125 self.updateScrollbar()
127 def produceHTML(self):
128 return self.getText()