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, parent):
18 if self.skinAttributes is not None:
19 skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes, parent.scale)
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, parent.scale)
28 skin.applyAllAttributes(self.scrollbar, desktop, scrollbar_attribs+widget_attribs, parent.scale)
30 s = self.long_text.size()
31 self.instance.move(self.long_text.position())
32 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
34 lineheight = 30 # assume a random lineheight if nothing is visible
35 lines = (int)(s.height() / lineheight)
36 self.pageHeight = (int)(lines * lineheight)
37 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
38 self.scrollbar.move(ePoint(s.width()-20,0))
39 self.scrollbar.resize(eSize(20,self.pageHeight+(int)(lineheight/6)))
40 self.scrollbar.setOrientation(eSlider.orVertical);
41 self.scrollbar.setRange(0,100)
42 self.scrollbar.setBorderWidth(1)
43 self.long_text.move(ePoint(0,0))
44 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
45 self.setText(self.message)
48 def setText(self, text):
50 if self.long_text is not None and self.pageHeight:
51 self.long_text.move(ePoint(0,0))
52 self.long_text.setText(self.message)
53 text_height=self.long_text.calculateSize().height()
56 while total < text_height:
57 total=total+self.pageHeight
63 self.updateScrollbar()
69 def appendText(self, text):
70 old_text = self.getText()
71 if len(str(old_text)) >0:
75 if self.long_text is not None:
76 self.long_text.setText(self.message)
77 text_height=self.long_text.calculateSize().height()
80 while total < text_height:
81 total=total+self.pageHeight
87 self.updateScrollbar()
93 def updateScrollbar(self):
94 start = -self.long_text.position().y() * 100 / self.total
95 vis = self.pageHeight * 100 / self.total;
96 self.scrollbar.setStartEnd(start, start+vis)
101 def GUIcreate(self, parent):
102 self.instance = eWidget(parent)
103 self.scrollbar = eSlider(self.instance)
104 self.long_text = eLabel(self.instance)
107 self.long_text = None
108 self.scrollbar = None
112 if self.total is not None:
113 curPos = self.long_text.position()
115 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
116 self.updateScrollbar()
119 if self.total is not None:
120 curPos = self.long_text.position()
121 if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
122 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
123 self.updateScrollbar()
127 while i < self.pages:
130 self.updateScrollbar()
132 def produceHTML(self):
133 return self.getText()