add ScrollLabel component
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sat, 12 Nov 2005 18:07:15 +0000 (18:07 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sat, 12 Nov 2005 18:07:15 +0000 (18:07 +0000)
lib/python/Components/Makefile.am
lib/python/Components/ScrollLabel.py [new file with mode: 0644]
lib/python/Components/__init__.py

index bd5ad96ab7333921aa2769dc558f26f322b65df6..15073741f7680e80dba0fa076485e6e8e1a25cca 100644 (file)
@@ -9,4 +9,4 @@ install_PYTHON = \
        GUIComponent.py MenuList.py TextInput.py __init__.py MovieList.py                               \
        InputDevice.py ServicePosition.py SetupDevices.py Harddisk.py                                           \
        AVSwitch.py Network.py RFmod.py DiskInfo.py NimManager.py Lcd.py                                \
        GUIComponent.py MenuList.py TextInput.py __init__.py MovieList.py                               \
        InputDevice.py ServicePosition.py SetupDevices.py Harddisk.py                                           \
        AVSwitch.py Network.py RFmod.py DiskInfo.py NimManager.py Lcd.py                                \
-       EpgList.py
+       EpgList.py ScrollLabel.py
diff --git a/lib/python/Components/ScrollLabel.py b/lib/python/Components/ScrollLabel.py
new file mode 100644 (file)
index 0000000..4a5caf6
--- /dev/null
@@ -0,0 +1,85 @@
+import skin
+from HTMLComponent import *
+from GUIComponent import *
+from enigma import eLabel, eWidget, eSlider, fontRenderClass, ePoint, eSize
+
+class ScrollLabel(HTMLComponent, GUIComponent):
+       def __init__(self, text=""):
+               self.message = text
+               self.instance = None
+               self.long_text = None
+               self.scrollbar = None
+               self.pages = None
+               self.total = None
+
+       def applySkin(self, desktop):
+               skin.applyAllAttributes(self.long_text, desktop, self.skinAttributes)
+               s = self.long_text.size()
+               self.instance.move(self.long_text.position())
+               self.scrollbar.move(ePoint(s.width()-20,0))
+               self.scrollbar.resize(eSize(20,s.height()))
+               self.scrollbar.setOrientation(eSlider.orVertical);
+               self.scrollbar.setRange(0,100)
+               lineheight=fontRenderClass.getInstance().getLineHeight( self.long_text.getFont() )
+               lines = (int)(s.height() / lineheight)
+               self.pageHeight = (int)(lines * lineheight)
+               self.instance.resize(eSize(s.width(), self.pageHeight+(int)(lineheight/6)))
+               self.long_text.move(ePoint(0,0))
+               self.long_text.resize(eSize(s.width()-30, self.pageHeight*16))
+               self.setText(self.message)
+
+       def setText(self, text):
+               self.message = text
+               if self.long_text is not None:
+                       self.long_text.move(ePoint(0,0))
+                       self.long_text.setText(self.message)
+                       text_height=self.long_text.calculateSize().height()
+                       total=self.pageHeight
+                       pages=1
+                       while total < text_height:
+                               total=total+self.pageHeight
+                               pages=pages+1
+                       if pages > 1:
+                               self.scrollbar.show()
+                               self.total = total
+                               self.pages = pages
+                               self.updateScrollbar()
+                       else:
+                               self.scrollbar.hide()
+                               self.total = None
+                               self.pages = None
+
+       def updateScrollbar(self):
+               start = -self.long_text.position().y() * 100 / self.total
+               vis = self.pageHeight * 100 / self.total;
+               self.scrollbar.setStartEnd(start, start+vis)
+
+       def getText(self):
+               return self.message
+
+       def GUIcreate(self, parent):
+               self.instance = eWidget(parent)
+               self.scrollbar = eSlider(self.instance)
+               self.long_text = eLabel(self.instance)
+
+       def GUIdelete(self):
+               self.long_text = None
+               self.scrollbar = None
+               self.instance = None
+
+       def pageUp(self):
+               if self.total is not None:
+                       curPos = self.long_text.position()
+                       if curPos.y() < 0:
+                               self.long_text.move( ePoint( curPos.x(), curPos.y() + self.pageHeight ) )
+                               self.updateScrollbar()
+
+       def pageDown(self):
+               if self.total is not None:
+                       curPos = self.long_text.position()
+                       if self.total-self.pageHeight >= abs( curPos.y() - self.pageHeight ):
+                               self.long_text.move( ePoint( curPos.x(), curPos.y() - self.pageHeight ) )
+                               self.updateScrollbar()
+
+       def produceHTML(self):
+               return self.getText()
index f501b907606bdad17008db54f70997194d5686f5..ebc7f49fbf0b9f5da51e4e1f9c0caf34a9bd5a15 100644 (file)
@@ -6,4 +6,4 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo",
        "components", "config", "TimerList", "TimeInput", "MovieList", 
        "InputDevice",  "ServicePosition", "IPAddress", "VariableIP", "IPGateway",
        "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry",
        "components", "config", "TimerList", "TimeInput", "MovieList", 
        "InputDevice",  "ServicePosition", "IPAddress", "VariableIP", "IPGateway",
        "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry",
-       "Lcd", "EpgList"]
+       "Lcd", "EpgList" "ScrollLabel"]