import sys
from PySide import QtGui, QtCore, QtOpenGL

import random
import math

class SignalItem(QtGui.QGraphicsItem):
    def __init__(self, nr):
        super(SignalItem, self).__init__()
        self.setFlags(QtGui.QGraphicsItem.ItemUsesExtendedStyleOption)
        
        self.nr = nr
        self.fr = random.randint(3, 50)
        self.bg = QtGui.QColor(random.randint(200,255),random.randint(200,255),random.randint(200,255))
    
    def boundingRect(self):
        return QtCore.QRectF(0, self.nr*50, 10000, 50)
    
    def paint(self, painter, option, widget):
        painter.fillRect(option.exposedRect, self.bg)
        self.prevY = math.sin((int(option.exposedRect.left()) - 1)/float(self.fr))*10 + 25 + self.nr*50
        for x in range(int(option.exposedRect.left()), int(option.exposedRect.right())):
            y = math.sin(x/float(self.fr))*10 + 25 + self.nr*50 
            painter.drawLine(x-1, self.prevY, x, y)
            self.prevY = y


class Dummy(QtCore.QObject):
    def __init__(self):
        super(Dummy, self).__init__()
        self.scene = QtGui.QGraphicsScene()

        for i in range(40):
            item = SignalItem(i)
            self.scene.addItem(item)

        self.view = QtGui.QGraphicsView(self.scene)
        self.view.show()

        self.startTimer(25)
        self.x = 0
        self.lastTimerEvent = None

    def timerEvent(self,event):
        self.x += 1
        self.view.horizontalScrollBar().setValue(self.x)
        currentTime = QtCore.QTime.currentTime()
        if self.lastTimerEvent:
            print self.lastTimerEvent.msecsTo(currentTime)
        self.lastTimerEvent = currentTime


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    d = Dummy()
    sys.exit(app.exec_())
