fix automatic scan
[enigma2.git] / lib / python / Components / ScrollLabel.py
1 import skin
2 from HTMLComponent import *
3 from GUIComponent import *
4 from enigma import eLabel, eWidget, eSlider, fontRenderClass, ePoint, eSize
5
6 class ScrollLabel(HTMLComponent, GUIComponent):
7         def __init__(self, text=""):
8                 self.message = text
9                 self.instance = None
10                 self.long_text = None
11                 self.scrollbar = None
12                 self.pages = None
13                 self.total = None
14
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                 self.scrollbar.move(ePoint(s.width()-20,0))
20                 self.scrollbar.resize(eSize(20,s.height()))
21                 self.scrollbar.setOrientation(eSlider.orVertical);
22                 self.scrollbar.setRange(0,100)
23                 lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
24                 lines = (int)(s.height() / lineheight)
25                 self.pageHeight = (int)(lines * lineheight)
26                 self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
27                 self.long_text.move(ePoint(0,0))
28                 self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
29                 self.setText(self.message)
30
31         def setText(self, text):
32                 self.message = text
33                 if self.long_text is not None:
34                         self.long_text.move(ePoint(0,0))
35                         self.long_text.setText(self.message)
36                         text_height=self.long_text.calculateSize().height()
37                         total=self.pageHeight
38                         pages=1
39                         while total < text_height:
40                                 total=total+self.pageHeight
41                                 pages=pages+1
42                         if pages > 1:
43                                 self.scrollbar.show()
44                                 self.total = total
45                                 self.pages = pages
46                                 self.updateScrollbar()
47                         else:
48                                 self.scrollbar.hide()
49                                 self.total = None
50                                 self.pages = None
51
52         def updateScrollbar(self):
53                 start = -self.long_text.position().y() * 100 / self.total
54                 vis = self.pageHeight * 100 / self.total;
55                 self.scrollbar.setStartEnd(start, start+vis)
56
57         def getText(self):
58                 return self.message
59
60         def GUIcreate(self, parent):
61                 self.instance = eWidget(parent)
62                 self.scrollbar = eSlider(self.instance)
63                 self.long_text = eLabel(self.instance)
64
65         def GUIdelete(self):
66                 self.long_text = None
67                 self.scrollbar = None
68                 self.instance = None
69
70         def pageUp(self):
71                 if self.total is not None:
72                         curPos = self.long_text.position()
73                         if curPos.y() < 0:
74                                 self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
75                                 self.updateScrollbar()
76
77         def pageDown(self):
78                 if self.total is not None:
79                         curPos = self.long_text.position()
80                         if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
81                                 self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
82                                 self.updateScrollbar()
83
84         def produceHTML(self):
85                 return self.getText()