Esempio n. 1
0
 def setUpDataDisplayWidget(self):
     self.dataDisplayWidget = DataDisplay()
     # self.dataDisplayWidget.setMinimumSize(800,380)
     # self.dataDisplayLayout = QVBoxLayout()
     # self.dataDisplayWidget.setLayout(self.dataDisplayLayout)
     self.stackedLayout.addWidget(self.dataDisplayWidget)
     return
Esempio n. 2
0
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.parent = parent
        self.setMouseTracking(True)

        self.nav = Navigation()
        self.navInterface = NavigationInterface(self.nav)
        self.dataDisplay = DataDisplay()

        # self.navigateSignal.connect(self.navigateEvent)
        SIGNALS.navigateSignal.connect(self.navigateEvent)
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(640, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.driftalert = QtGui.QCheckBox(self.centralwidget)
        self.driftalert.setGeometry(QtCore.QRect(320, 330, 71, 18))
        self.driftalert.setObjectName(_fromUtf8("driftalert"))
        self.trapalert = QtGui.QCheckBox(self.centralwidget)
        self.trapalert.setGeometry(QtCore.QRect(320, 350, 91, 18))
        self.trapalert.setObjectName(_fromUtf8("trapalert"))
        self.emailinput = QtGui.QLineEdit(self.centralwidget)
        self.emailinput.setGeometry(QtCore.QRect(320, 370, 131, 20))
        self.emailinput.setObjectName(_fromUtf8("emailinput"))
        self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(460, 330, 160, 91))
        self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
        self.buttons = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.buttons.setObjectName(_fromUtf8("buttons"))
        self.startdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.startdisplay.setObjectName(_fromUtf8("startdisplay"))
        self.buttons.addWidget(self.startdisplay)
        self.savedisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.savedisplay.setObjectName(_fromUtf8("savedisplay"))
        self.buttons.addWidget(self.savedisplay)
        self.stopdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.stopdisplay.setObjectName(_fromUtf8("stopdisplay"))
        self.buttons.addWidget(self.stopdisplay)
        self.displaywindow = DataDisplay(self.centralwidget)
        self.displaywindow.setGeometry(QtCore.QRect(40, 20, 551, 301))
        self.displaywindow.setObjectName(_fromUtf8("displaywindow"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 18))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.driftalert.setText(_translate("MainWindow", "Drift Alert", None))
        self.trapalert.setText(_translate("MainWindow", "Trapping Alert", None))
        self.startdisplay.setText(_translate("MainWindow", "Start Display", None))
        self.savedisplay.setText(_translate("MainWindow", "Save Display", None))
        self.stopdisplay.setText(_translate("MainWindow", "Stop Display", None))
Esempio n. 4
0
 def __init__(self, parent=None):
     super(GLWidget, self).__init__(parent)
     self.parent = parent
     self.setMouseTracking(True)
     
     self.nav = Navigation()
     self.navInterface = NavigationInterface(self.nav)
     self.dataDisplay = DataDisplay()
     
     # self.navigateSignal.connect(self.navigateEvent)
     SIGNALS.navigateSignal.connect(self.navigateEvent)
Esempio n. 5
0
class GLWidget(QtOpenGL.QGLWidget):
    # initial window size
    w, h = 1024, 768

    isInitialized = False

    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.parent = parent
        self.setMouseTracking(True)

        self.nav = Navigation()
        self.navInterface = NavigationInterface(self.nav)
        self.dataDisplay = DataDisplay()

        # self.navigateSignal.connect(self.navigateEvent)
        SIGNALS.navigateSignal.connect(self.navigateEvent)

    def minimumSizeHint(self):
        return QtCore.QSize(50, 50)

    def sizeHint(self):
        return QtCore.QSize(self.w, self.h)

    # get position coordinates
    def coord(self, pos):
        return (pos.x(), pos.y())

    # get normalized coordinates
    def norm(self, pair):
        return (pair[0] / float(self.w), pair[1] / float(self.h))

    def ncoord(self, pos):
        return self.norm(self.coord(pos))

    def initializeGL(self):
        self.dataDisplay.initialize()
        self.isInitialized = True

    def paintGL(self):
        tx, ty = self.nav.get_translation()
        sx, sy = self.nav.get_scale()
        self.dataDisplay.transform(tx, ty, sx, sy)
        self.dataDisplay.paint()

    # handle window resizing
    def resizeGL(self, w, h):
        self.w, self.h = w, h
        self.dataDisplay.resize(w, h)

    def focusInEvent(self):
        pass

    def focusOutEvent(self):
        self.keyReleaseEvent(None)

    def navigateEvent(self):
        self.updateGL()

    def mousePressEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mousePress(x, y, event.button())

    def mouseReleaseEvent(self, event):
        self.navInterface.mouseRelease()

    def mouseMoveEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mouseMove(x, y)
        self.parent.statusbar.showMessage("%g, %g" %
                                          self.getMousePosition(x, y))
        if self.navInterface.mouseButton:
            SIGNALS.navigateSignal.emit()

    def getMousePosition(self, x, y):
        """
        convert mouse coordinates => data coordinates
        """
        tx, ty = self.nav.get_translation(False)
        sx, sy = self.nav.get_scale()
        # x = .5 * (1. - 1./sx) - tx + x/sx# + self.nav.offsetx
        # y = .5 * (1. - 1./sy) - ty + y/sy
        x, y = self.nav.get_data_coordinates(x, y)

        # inverse data normalization
        xmin, xmax, ymin, ymax = self.dataDisplay.get_bounds()
        x = xmin + x * (xmax - xmin)
        y = ymin + y * (ymax - ymin)
        y = -y
        return x, y

    def wheelEvent(self, event):
        self.navInterface.mouseWheel(event.delta())
        SIGNALS.navigateSignal.emit()

    def keyPressEvent(self, e):
        key = ""
        if e.key() == QtCore.Qt.Key_Control:
            key = KEY_CTRL
        if e.key() == QtCore.Qt.Key_Shift:
            key = KEY_SHIFT
        if e.key() == QtCore.Qt.Key_Alt:
            key = KEY_ALT
        if e.key() == QtCore.Qt.Key_Up:
            key = KEY_UP
        if e.key() == QtCore.Qt.Key_Down:
            key = KEY_DOWN
        if e.key() == QtCore.Qt.Key_Left:
            key = KEY_LEFT
        if e.key() == QtCore.Qt.Key_Right:
            key = KEY_RIGHT
        self.navInterface.keyPress(key)
        SIGNALS.navigateSignal.emit()

    def keyReleaseEvent(self, e):
        self.navInterface.keyRelease()

    # PUBLIC METHODS
    def slide(self, x, max):
        # slide, and update only if the transform is not null
        if (self.nav.slide(x, max)):
            self.updateGL()

    def reset(self):
        self.nav.reset()
        SIGNALS.navigateSignal.emit()

    def load_data(self, data, databounds=None, options=None):
        self.dataDisplay.load(data, databounds, options=options)
        # reload if already initialized
        if self.isInitialized:
            self.dataDisplay.bind_data_buffer()
            self.updateGL()

    def capture(self):
        glReadBuffer(GL_FRONT)
        image = self.grabFrameBuffer()
        return image
Esempio n. 6
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(640, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 641, 461))
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab_3 = QtGui.QWidget()
        self.tab_3.setObjectName(_fromUtf8("tab_3"))
        self.driftpercent = QtGui.QLineEdit(self.tab_3)
        self.driftpercent.setGeometry(QtCore.QRect(170, 340, 41, 20))
        self.driftpercent.setObjectName(_fromUtf8("driftpercent"))
        self.label_3 = QtGui.QLabel(self.tab_3)
        self.label_3.setGeometry(QtCore.QRect(70, 360, 91, 20))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.trappercent = QtGui.QLineEdit(self.tab_3)
        self.trappercent.setGeometry(QtCore.QRect(170, 360, 41, 20))
        self.trappercent.setObjectName(_fromUtf8("trappercent"))
        self.verticalLayoutWidget = QtGui.QWidget(self.tab_3)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(440, 320, 160, 91))
        self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
        self.buttons = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.buttons.setObjectName(_fromUtf8("buttons"))
        self.startdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.startdisplay.setObjectName(_fromUtf8("startdisplay"))
        self.buttons.addWidget(self.startdisplay)
        self.savedisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.savedisplay.setObjectName(_fromUtf8("savedisplay"))
        self.buttons.addWidget(self.savedisplay)
        self.stopdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.stopdisplay.setObjectName(_fromUtf8("stopdisplay"))
        self.buttons.addWidget(self.stopdisplay)
        self.trapalert = QtGui.QCheckBox(self.tab_3)
        self.trapalert.setGeometry(QtCore.QRect(300, 340, 91, 18))
        self.trapalert.setObjectName(_fromUtf8("trapalert"))
        self.displaywindow = DataDisplay(self.tab_3)
        self.displaywindow.setGeometry(QtCore.QRect(20, 10, 551, 301))
        self.displaywindow.setObjectName(_fromUtf8("displaywindow"))
        self.label = QtGui.QLabel(self.tab_3)
        self.label.setGeometry(QtCore.QRect(230, 360, 61, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.emailinput = QtGui.QLineEdit(self.tab_3)
        self.emailinput.setGeometry(QtCore.QRect(300, 360, 131, 20))
        self.emailinput.setObjectName(_fromUtf8("emailinput"))
        self.label_2 = QtGui.QLabel(self.tab_3)
        self.label_2.setGeometry(QtCore.QRect(70, 340, 91, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.driftalert = QtGui.QCheckBox(self.tab_3)
        self.driftalert.setGeometry(QtCore.QRect(300, 320, 71, 18))
        self.driftalert.setObjectName(_fromUtf8("driftalert"))
        self.frequencyinput = QtGui.QLineEdit(self.tab_3)
        self.frequencyinput.setGeometry(QtCore.QRect(120, 380, 91, 20))
        self.frequencyinput.setObjectName(_fromUtf8("frequencyinput"))
        self.label_6 = QtGui.QLabel(self.tab_3)
        self.label_6.setGeometry(QtCore.QRect(10, 380, 111, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.errortext = QtGui.QLineEdit(self.tab_3)
        self.errortext.setGeometry(QtCore.QRect(100, 320, 181, 20))
        self.errortext.setObjectName(_fromUtf8("errortext"))
        self.label_8 = QtGui.QLabel(self.tab_3)
        self.label_8.setGeometry(QtCore.QRect(40, 320, 61, 16))
        self.label_8.setObjectName(_fromUtf8("label_8"))
        self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
        self.tab_4 = QtGui.QWidget()
        self.tab_4.setObjectName(_fromUtf8("tab_4"))
        self.sweepwindow = DataDisplay(self.tab_4)
        self.sweepwindow.setGeometry(QtCore.QRect(30, 10, 551, 301))
        self.sweepwindow.setObjectName(_fromUtf8("sweepwindow"))
        self.startsweepbutton = QtGui.QPushButton(self.tab_4)
        self.startsweepbutton.setGeometry(QtCore.QRect(490, 320, 111, 23))
        self.startsweepbutton.setObjectName(_fromUtf8("startsweepbutton"))
        self.stopsweepbutton = QtGui.QPushButton(self.tab_4)
        self.stopsweepbutton.setGeometry(QtCore.QRect(490, 350, 111, 23))
        self.stopsweepbutton.setObjectName(_fromUtf8("stopsweepbutton"))
        self.savesweepbutton = QtGui.QPushButton(self.tab_4)
        self.savesweepbutton.setGeometry(QtCore.QRect(490, 380, 111, 23))
        self.savesweepbutton.setObjectName(_fromUtf8("savesweepbutton"))
        self.starttemp = QtGui.QLineEdit(self.tab_4)
        self.starttemp.setGeometry(QtCore.QRect(420, 320, 51, 20))
        self.starttemp.setObjectName(_fromUtf8("starttemp"))
        self.stoptemp = QtGui.QLineEdit(self.tab_4)
        self.stoptemp.setGeometry(QtCore.QRect(420, 340, 51, 20))
        self.stoptemp.setObjectName(_fromUtf8("stoptemp"))
        self.label_4 = QtGui.QLabel(self.tab_4)
        self.label_4.setGeometry(QtCore.QRect(260, 320, 151, 20))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.tab_4)
        self.label_5.setGeometry(QtCore.QRect(260, 340, 151, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.sweepfreqinput = QtGui.QLineEdit(self.tab_4)
        self.sweepfreqinput.setGeometry(QtCore.QRect(380, 360, 91, 20))
        self.sweepfreqinput.setObjectName(_fromUtf8("sweepfreqinput"))
        self.label_7 = QtGui.QLabel(self.tab_4)
        self.label_7.setGeometry(QtCore.QRect(260, 360, 111, 16))
        self.label_7.setObjectName(_fromUtf8("label_7"))
        self.sweepmoduloinput = QtGui.QLineEdit(self.tab_4)
        self.sweepmoduloinput.setGeometry(QtCore.QRect(320, 380, 21, 20))
        self.sweepmoduloinput.setObjectName(_fromUtf8("sweepmoduloinput"))
        self.label_9 = QtGui.QLabel(self.tab_4)
        self.label_9.setGeometry(QtCore.QRect(190, 380, 131, 20))
        self.label_9.setObjectName(_fromUtf8("label_9"))
        self.label_10 = QtGui.QLabel(self.tab_4)
        self.label_10.setGeometry(QtCore.QRect(340, 380, 81, 21))
        self.label_10.setObjectName(_fromUtf8("label_10"))
        self.tabWidget.addTab(self.tab_4, _fromUtf8(""))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 18))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(1)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Esempio n. 7
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(640, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 641, 461))
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab_3 = QtGui.QWidget()
        self.tab_3.setObjectName(_fromUtf8("tab_3"))
        self.driftpercent = QtGui.QLineEdit(self.tab_3)
        self.driftpercent.setGeometry(QtCore.QRect(170, 340, 41, 20))
        self.driftpercent.setObjectName(_fromUtf8("driftpercent"))
        self.label_3 = QtGui.QLabel(self.tab_3)
        self.label_3.setGeometry(QtCore.QRect(70, 360, 91, 20))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.trappercent = QtGui.QLineEdit(self.tab_3)
        self.trappercent.setGeometry(QtCore.QRect(170, 360, 41, 20))
        self.trappercent.setObjectName(_fromUtf8("trappercent"))
        self.verticalLayoutWidget = QtGui.QWidget(self.tab_3)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(440, 320, 160, 91))
        self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
        self.buttons = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.buttons.setObjectName(_fromUtf8("buttons"))
        self.startdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.startdisplay.setObjectName(_fromUtf8("startdisplay"))
        self.buttons.addWidget(self.startdisplay)
        self.savedisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.savedisplay.setObjectName(_fromUtf8("savedisplay"))
        self.buttons.addWidget(self.savedisplay)
        self.stopdisplay = QtGui.QPushButton(self.verticalLayoutWidget)
        self.stopdisplay.setObjectName(_fromUtf8("stopdisplay"))
        self.buttons.addWidget(self.stopdisplay)
        self.trapalert = QtGui.QCheckBox(self.tab_3)
        self.trapalert.setGeometry(QtCore.QRect(300, 340, 91, 18))
        self.trapalert.setObjectName(_fromUtf8("trapalert"))
        self.displaywindow = DataDisplay(self.tab_3)
        self.displaywindow.setGeometry(QtCore.QRect(20, 10, 551, 301))
        self.displaywindow.setObjectName(_fromUtf8("displaywindow"))
        self.label = QtGui.QLabel(self.tab_3)
        self.label.setGeometry(QtCore.QRect(230, 360, 61, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.emailinput = QtGui.QLineEdit(self.tab_3)
        self.emailinput.setGeometry(QtCore.QRect(300, 360, 131, 20))
        self.emailinput.setObjectName(_fromUtf8("emailinput"))
        self.label_2 = QtGui.QLabel(self.tab_3)
        self.label_2.setGeometry(QtCore.QRect(70, 340, 91, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.driftalert = QtGui.QCheckBox(self.tab_3)
        self.driftalert.setGeometry(QtCore.QRect(300, 320, 71, 18))
        self.driftalert.setObjectName(_fromUtf8("driftalert"))
        self.frequencyinput = QtGui.QLineEdit(self.tab_3)
        self.frequencyinput.setGeometry(QtCore.QRect(120, 380, 91, 20))
        self.frequencyinput.setObjectName(_fromUtf8("frequencyinput"))
        self.label_6 = QtGui.QLabel(self.tab_3)
        self.label_6.setGeometry(QtCore.QRect(10, 380, 111, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.errortext = QtGui.QLineEdit(self.tab_3)
        self.errortext.setGeometry(QtCore.QRect(100, 320, 181, 20))
        self.errortext.setObjectName(_fromUtf8("errortext"))
        self.label_8 = QtGui.QLabel(self.tab_3)
        self.label_8.setGeometry(QtCore.QRect(40, 320, 61, 16))
        self.label_8.setObjectName(_fromUtf8("label_8"))
        self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
        self.tab_4 = QtGui.QWidget()
        self.tab_4.setObjectName(_fromUtf8("tab_4"))
        self.sweepwindow = DataDisplay(self.tab_4)
        self.sweepwindow.setGeometry(QtCore.QRect(30, 10, 551, 301))
        self.sweepwindow.setObjectName(_fromUtf8("sweepwindow"))
        self.startsweepbutton = QtGui.QPushButton(self.tab_4)
        self.startsweepbutton.setGeometry(QtCore.QRect(490, 320, 111, 23))
        self.startsweepbutton.setObjectName(_fromUtf8("startsweepbutton"))
        self.stopsweepbutton = QtGui.QPushButton(self.tab_4)
        self.stopsweepbutton.setGeometry(QtCore.QRect(490, 350, 111, 23))
        self.stopsweepbutton.setObjectName(_fromUtf8("stopsweepbutton"))
        self.savesweepbutton = QtGui.QPushButton(self.tab_4)
        self.savesweepbutton.setGeometry(QtCore.QRect(490, 380, 111, 23))
        self.savesweepbutton.setObjectName(_fromUtf8("savesweepbutton"))
        self.starttemp = QtGui.QLineEdit(self.tab_4)
        self.starttemp.setGeometry(QtCore.QRect(420, 320, 51, 20))
        self.starttemp.setObjectName(_fromUtf8("starttemp"))
        self.stoptemp = QtGui.QLineEdit(self.tab_4)
        self.stoptemp.setGeometry(QtCore.QRect(420, 340, 51, 20))
        self.stoptemp.setObjectName(_fromUtf8("stoptemp"))
        self.label_4 = QtGui.QLabel(self.tab_4)
        self.label_4.setGeometry(QtCore.QRect(260, 320, 151, 20))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.tab_4)
        self.label_5.setGeometry(QtCore.QRect(260, 340, 151, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.sweepfreqinput = QtGui.QLineEdit(self.tab_4)
        self.sweepfreqinput.setGeometry(QtCore.QRect(380, 360, 91, 20))
        self.sweepfreqinput.setObjectName(_fromUtf8("sweepfreqinput"))
        self.label_7 = QtGui.QLabel(self.tab_4)
        self.label_7.setGeometry(QtCore.QRect(260, 360, 111, 16))
        self.label_7.setObjectName(_fromUtf8("label_7"))
        self.sweepmoduloinput = QtGui.QLineEdit(self.tab_4)
        self.sweepmoduloinput.setGeometry(QtCore.QRect(320, 380, 21, 20))
        self.sweepmoduloinput.setObjectName(_fromUtf8("sweepmoduloinput"))
        self.label_9 = QtGui.QLabel(self.tab_4)
        self.label_9.setGeometry(QtCore.QRect(190, 380, 131, 20))
        self.label_9.setObjectName(_fromUtf8("label_9"))
        self.label_10 = QtGui.QLabel(self.tab_4)
        self.label_10.setGeometry(QtCore.QRect(340, 380, 81, 21))
        self.label_10.setObjectName(_fromUtf8("label_10"))
        self.tabWidget.addTab(self.tab_4, _fromUtf8(""))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 18))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(1)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.label_3.setText(_translate("MainWindow", "Trap Threshold(%)", None))
        self.startdisplay.setText(_translate("MainWindow", "Start Display", None))
        self.savedisplay.setText(_translate("MainWindow", "Save Display", None))
        self.stopdisplay.setText(_translate("MainWindow", "Stop Display", None))
        self.trapalert.setText(_translate("MainWindow", "Trapping Alert", None))
        self.label.setText(_translate("MainWindow", "Enter email:", None))
        self.label_2.setText(_translate("MainWindow", "Drift Threshold(%)", None))
        self.driftalert.setText(_translate("MainWindow", "Drift Alert", None))
        self.label_6.setText(_translate("MainWindow", "Sample Frequency(Hz)", None))
        self.label_8.setText(_translate("MainWindow", "Error Status", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "Tab 1", None))
        self.startsweepbutton.setText(_translate("MainWindow", "Start Sweep", None))
        self.stopsweepbutton.setText(_translate("MainWindow", "Stop Sweep", None))
        self.savesweepbutton.setText(_translate("MainWindow", "Save Graph", None))
        self.label_4.setText(_translate("MainWindow", "Starting Temperature(Celcius)", None))
        self.label_5.setText(_translate("MainWindow", "Stopping Temperature(Celcius)", None))
        self.label_7.setText(_translate("MainWindow", "Sample Frequency(Hz)", None))
        self.label_9.setText(_translate("MainWindow", "Increment by 0.1°C every ", None))
        self.label_10.setText(_translate("MainWindow", "*0.5 seconds", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "Tab 2", None))
Esempio n. 8
0
class MainWindow(QMainWindow):

    #Signals which go to control. They have to be declared here due to limitations of the PyQt5
    #https://stackoverflow.com/questions/2970312/pyqt4-qtcore-pyqtsignal-object-has-no-attribute-connect
    #well explained in the link above
    toggleLaserSignal = pyqtSignal()
    moveRightStartSignal = pyqtSignal()
    moveRightStopSignal = pyqtSignal()
    moveLeftStartSignal = pyqtSignal()
    moveLeftStopSignal = pyqtSignal()
    measureDistanceSignal = pyqtSignal()
    setAngleToZeroSignal = pyqtSignal()
    calculateWidthSignal = pyqtSignal()
    sendSpeedSignal = pyqtSignal(int)
    connectBluetoothSignal = pyqtSignal()
    getMapSignal = pyqtSignal()

    def __init__(self, parent=None):
        QMainWindow.__init__(self)
        #self.setStyleSheet("background-color: black;")
        #self.setStyleSheet(".QPushButton { background-color: black}")
        self.setAutoFillBackground(True)

        #Set the properties of the window
        self.setMinimumSize(800, 480)
        self.setWindowTitle("Dingo is amazing")

        #initialise widgets and threads
        self.displayWidgets()
        self.setUpThreads()
        self.defineSignals()

        self.updateDisplays()  #delete later
        self.updateLaserColour()

        self.show()

    def __del__(self):
        #Destructor. Initialise closing the thread, wait for it to finish, continue
        self.controlThread.quit()
        self.controlThread.wait()
        self.commsThread.quit()
        self.controlThread.wait()

    def setUpThreads(self):
        #Set up threads. Initialise objects and move them to threads
        self.controlThread = QThread()
        self.commsThread = QThread()

        self.controlThreadObject = Control()
        self.commsThreadObject = Comms()

        self.controlThreadObject.moveToThread(self.controlThread)
        self.commsThreadObject.moveToThread(self.commsThread)

        self.controlThread.start()
        self.commsThread.start()

        return

    def displayWidgets(self):

        self.setUpCentralWidget()
        self.setUpMenuWidget()
        self.setUpStackedLayoutWidget()
        self.setUpControlGridWidget()
        self.setUpSettingsWidget()
        self.setUpImagesWidget()
        self.setUpDataDisplayWidget()
        self.setUpMapsControlWidget()
        self.addMenuButtons()
        self.addButtonsToControlGrid()
        self.addDisplaysToControlGrid()
        self.initialiseVariablesToZero()
        self.addMotorSpeedControls()
        self.addWarningDisplay()
        self.initialiseSpeedVariable()
        #self.addSliderToControlGrid()

        return

    def setUpMenuWidget(self):
        menuWidget = QWidget()
        menuWidget.setMinimumSize(800, 20)
        self.menuLayout = QHBoxLayout()
        menuWidget.setLayout(self.menuLayout)
        self.mainLayout.addWidget(menuWidget)
        return

    def setUpStackedLayoutWidget(self):
        stackedWidget = QWidget()
        stackedWidget.setMinimumSize(800, 380)
        self.stackedLayout = QStackedLayout()
        stackedWidget.setLayout(self.stackedLayout)
        self.mainLayout.addWidget(stackedWidget)

        return

    def setUpCentralWidget(self):
        mainWidget = QWidget()
        self.mainLayout = QVBoxLayout()
        mainWidget.setLayout(self.mainLayout)
        self.setCentralWidget(mainWidget)
        return

    def setUpControlGridWidget(self):
        self.controlWidget = QWidget()
        self.controlWidget.setMinimumSize(800, 380)
        self.controlLayout = QGridLayout()
        self.controlWidget.setLayout(self.controlLayout)
        self.stackedLayout.addWidget(self.controlWidget)
        return

    def setUpImagesWidget(self):
        self.imagesWidget = MapsDisplay()
        # self.imagesWidget.setMinimumSize(800,380)
        # self.imagesLayout = QHBoxLayout()
        # self.imagesWidget.setLayout(self.imagesLayout)
        self.stackedLayout.addWidget(self.imagesWidget)

    def setUpDataDisplayWidget(self):
        self.dataDisplayWidget = DataDisplay()
        # self.dataDisplayWidget.setMinimumSize(800,380)
        # self.dataDisplayLayout = QVBoxLayout()
        # self.dataDisplayWidget.setLayout(self.dataDisplayLayout)
        self.stackedLayout.addWidget(self.dataDisplayWidget)
        return

    def setUpMapsControlWidget(self):
        self.mapsControlWidget = MapsControl()
        self.stackedLayout.addWidget(self.mapsControlWidget)

    def setUpSettingsWidget(self):
        self.settingsWidget = SettingsWidget()
        self.stackedLayout.addWidget(self.settingsWidget)

    def addMenuButtons(self):
        buttonControl = QPushButton("Control Panel")
        buttonControl.setFixedHeight(40)
        buttonControl.clicked.connect(
            self.switchStackedLayoutWidget(self.controlWidget))
        self.menuLayout.addWidget(buttonControl)

        buttonDisplay = QPushButton("Display data")
        buttonDisplay.setFixedHeight(40)
        buttonDisplay.clicked.connect(
            self.switchStackedLayoutWidget(self.dataDisplayWidget))
        self.menuLayout.addWidget(buttonDisplay)

        buttonMaps = QPushButton("Maps control")
        buttonMaps.setFixedHeight(40)
        buttonMaps.clicked.connect(
            self.switchStackedLayoutWidget(self.mapsControlWidget))
        self.menuLayout.addWidget(buttonMaps)

        buttonImages = QPushButton("Maps")
        buttonImages.setFixedHeight(40)
        buttonImages.clicked.connect(
            self.switchStackedLayoutWidget(self.imagesWidget))
        self.menuLayout.addWidget(buttonImages)

        buttonSettings = QPushButton("Settings")
        buttonSettings.setFixedHeight(40)
        buttonSettings.clicked.connect(
            self.switchStackedLayoutWidget(self.settingsWidget))
        self.menuLayout.addWidget(buttonSettings)

        return

    def switchStackedLayoutWidget(self, widget):
        #this is an interesting concept. I couldn't pass a widget directly to the setCurrentWidget
        #I had to use something called function factory
        #https://stackoverflow.com/questions/6784084/how-to-pass-arguments-to-functions-by-the-click-of-button-in-pyqt
        #More information on stack
        def functionFactory():
            self.stackedLayout.setCurrentWidget(widget)

        return functionFactory

    def initialiseVariablesToZero(self):
        self.lastDistance = 0
        self.lastAngle = 0
        self.formerDistance = 0
        self.formerAngle = 0
        self.lastWidth = 0
        self.lastWidthDistance = 0
        self.laserOn = False
        return

    def initialiseSpeedVariable(self):
        self.speed = 5
        return

    def updateDisplays(self):
        self.boxDistanceLast.setText("Last distance: " +
                                     str(self.lastDistance) + "mm")
        self.boxAngleLast.setText("Last angle: " + str(self.lastAngle))
        self.boxDistanceFormer.setText("Former distance: " +
                                       str(self.formerDistance) + "mm")
        self.boxAngleFormer.setText("Former angle: " + str(self.formerAngle))
        self.boxWidth.setText("Last width: " + str(self.lastWidth) + "mm")
        self.boxSpeed.setText("Motor speed: " + str(self.speed))
        self.boxWidthDistance.setText("Shortest distance: " +
                                      str(self.lastWidthDistance) + "mm")

        if self.lastDistance != 0 and self.lastDistance < 1000:
            self.boxWarning.setText(
                "WARNING. Distance under 1m. It can be inaccurate")
            self.boxWarning.setStyleSheet("background-color: red")
        elif self.lastDistance != 0 and self.lastDistance > 1000:
            self.boxWarning.setText("Measurement OK")
            self.boxWarning.setStyleSheet("background-color: green")
        return

    def addDisplaysToControlGrid(self):
        self.boxDistanceLast = QLineEdit()
        self.boxDistanceLast.setFixedHeight(40)
        self.boxDistanceLast.setReadOnly(True)
        self.controlLayout.addWidget(self.boxDistanceLast, 2, 0)

        self.boxAngleLast = QLineEdit()
        self.boxAngleLast.setFixedHeight(40)
        self.boxAngleLast.setReadOnly(True)
        self.controlLayout.addWidget(self.boxAngleLast, 2, 1)

        self.boxDistanceFormer = QLineEdit()
        self.boxDistanceFormer.setFixedHeight(40)
        self.boxDistanceFormer.setReadOnly(True)
        self.controlLayout.addWidget(self.boxDistanceFormer, 3, 0)

        self.boxAngleFormer = QLineEdit()
        self.boxAngleFormer.setFixedHeight(40)
        self.boxAngleFormer.setReadOnly(True)
        self.controlLayout.addWidget(self.boxAngleFormer, 3, 1)

        self.boxWidth = QLineEdit()
        self.boxWidth.setFixedHeight(40)
        self.boxWidth.setReadOnly(True)
        self.controlLayout.addWidget(self.boxWidth, 2, 2)

        self.boxSpeed = QLineEdit()
        self.boxSpeed.setFixedHeight(40)
        self.boxSpeed.setReadOnly(True)
        self.controlLayout.addWidget(self.boxSpeed, 5, 1)

        self.boxWidthDistance = QLineEdit()
        self.boxWidthDistance.setFixedHeight(40)
        self.boxWidthDistance.setReadOnly(True)
        self.controlLayout.addWidget(self.boxWidthDistance, 3, 2)

        return

    def addSliderToControlGrid(self):
        self.slider = QSlider()
        self.slider.setRange(1, 10)
        self.slider.setTickPosition(1)
        self.slider.setTickInterval(10)
        self.slider.setSingleStep(1)
        self.slider.setOrientation(1)
        self.controlLayout.addWidget(self.slider, 5, 0, 1, 2)
        return

    def addButtonsToControlGrid(self):
        self.buttonToggleLaser = QPushButton("Toggle laser: OFF")
        #buttonToggleLaser.setStyleSheet("background-color: white")
        self.buttonToggleLaser.setFixedHeight(50)
        self.buttonToggleLaser.setStyleSheet("background-color: green")
        self.buttonToggleLaser.clicked.connect(self.buttonToggleLaserClicked)
        self.controlLayout.addWidget(self.buttonToggleLaser, 0, 0)

        self.buttonBluetoothConnect = QPushButton("Bluetooth Connect")
        self.buttonBluetoothConnect.setFixedHeight(50)
        self.buttonBluetoothConnect.clicked.connect(
            self.buttonBluetoothConnectClicked)
        self.controlLayout.addWidget(self.buttonBluetoothConnect, 0, 2)

        #Boxes for displaying last measured distance and angle. Blocked, will be updated by later functions

        #Push Buttons For moving right, left and taking measurement

        buttonLeft = QPushButton("<<<")
        buttonLeft.pressed.connect(self.buttonMoveLeftPressed)
        buttonLeft.released.connect(self.buttonMoveLeftReleased)
        buttonLeft.setFixedHeight(60)
        self.controlLayout.addWidget(buttonLeft, 6, 0)

        buttonMeasure = QPushButton("Measure")
        buttonMeasure.clicked.connect(self.buttonMeasureClicked)
        buttonMeasure.setFixedHeight(60)
        self.controlLayout.addWidget(buttonMeasure, 6, 1)

        buttonRight = QPushButton(">>>")
        buttonRight.pressed.connect(self.buttonMoveRightPressed)
        buttonRight.released.connect(self.buttonMoveRightReleased)
        buttonRight.setFixedHeight(60)
        self.controlLayout.addWidget(buttonRight, 6, 2)

        #Buttons for setting angle to relative 0 and displaying distance p2p

        buttonSetRelativeZero = QPushButton("Set angle 0")
        buttonSetRelativeZero.setFixedHeight(40)
        buttonSetRelativeZero.clicked.connect(
            self.buttonSetRelativeAngleToZeroClicked)
        self.controlLayout.addWidget(buttonSetRelativeZero, 8, 0)

        buttonWidth = QPushButton("Calculate width")
        buttonWidth.setFixedHeight(40)
        buttonWidth.clicked.connect(self.buttonGetWidthPressed)
        self.controlLayout.addWidget(buttonWidth, 8, 2)

        # Moved to maps control tab
        buttonScan = QPushButton("Map the room")
        buttonScan.setFixedHeight(40)
        buttonScan.clicked.connect(self.buttonScanRoomClicked)
        # self.controlLayout.addWidget(buttonScan,8,2)

        return

    def addButtonUpdate(self):
        buttonUpdate = QPushButton("UPdate")
        buttonUpdate.setFixedHeight(40)
        buttonUpdate.clicked.connect(self.updateFirmware)
        self.controlLayout.addWidget(buttonUpdate, 3, 2)

    def addMotorSpeedControls(self):
        buttonDecreaseSpeed = QPushButton("---")
        buttonDecreaseSpeed.setFixedHeight(40)
        buttonDecreaseSpeed.clicked.connect(self.buttonDecreaseSpeedClicked)
        self.controlLayout.addWidget(buttonDecreaseSpeed, 5, 0)

        buttonIncreaseSpeed = QPushButton("+++")
        buttonIncreaseSpeed.setFixedHeight(40)
        buttonIncreaseSpeed.clicked.connect(self.buttonIncreaseSpeedClicked)
        self.controlLayout.addWidget(buttonIncreaseSpeed, 5, 2)

        return

    def defineSignals(self):
        #gui -> control
        self.toggleLaserSignal.connect(self.controlThreadObject.toggleLaser)
        self.moveRightStartSignal.connect(
            self.controlThreadObject.moveRightStart)
        self.moveRightStopSignal.connect(
            self.controlThreadObject.moveRightStop)
        self.moveLeftStartSignal.connect(
            self.controlThreadObject.moveLeftStart)
        self.moveLeftStopSignal.connect(self.controlThreadObject.moveLeftStop)
        self.measureDistanceSignal.connect(
            self.controlThreadObject.measureDistance)
        self.setAngleToZeroSignal.connect(
            self.controlThreadObject.setAngleToZero)
        self.calculateWidthSignal.connect(
            self.controlThreadObject.calculateWidth)
        self.sendSpeedSignal.connect(
            self.controlThreadObject.receiveSpeedValue)

        #maps control -> gui
        self.mapsControlWidget.getMapSignal.connect(
            self.controlThreadObject.getMap)
        self.mapsControlWidget.turnOffLaserSignal.connect(self.turnOffLaser)

        #maps -> maps control
        self.imagesWidget.mapAddedSignal.connect(
            self.mapsControlWidget.indicatorFinishMeasurment)

        #control -> gui
        self.controlThreadObject.sendMapSignal.connect(self.receiveMap)
        self.controlThreadObject.sendPointSignal.connect(self.receivePoint)

        #gui -> comms
        self.connectBluetoothSignal.connect(self.commsThreadObject.main)

        #comms -> gui

        self.commsThreadObject.calculateWidthSignal.connect(
            self.buttonGetWidthPressed)
        self.commsThreadObject.toggleLaserSignal.connect(
            self.buttonToggleLaserClicked)
        self.commsThreadObject.getMapSignal.connect(
            self.controlThreadObject.getMap)
        self.commsThreadObject.measureSignal.connect(self.buttonMeasureClicked)
        self.commsThreadObject.setAngleZeroSignal.connect(
            self.buttonSetRelativeAngleToZeroClicked)
        self.commsThreadObject.bluetoothReadySignal.connect(
            self.bluetoothConnected)

        return

    def turnOffLaser(self):
        self.laserOn = False
        self.updateLaserColour()
        return

    def bluetoothConnected(self):
        self.buttonBluetoothConnect.setText("Bluetooth ready")
        return

    def buttonToggleLaserClicked(self):
        self.laserOn = not self.laserOn
        self.toggleLaserSignal.emit()
        self.updateLaserColour()

        return

    def updateLaserColour(self):
        if self.laserOn is True:
            self.buttonToggleLaser.setStyleSheet("background-color: red")
            self.buttonToggleLaser.setText("Toggle laser: ON")
        elif self.laserOn is not True:
            self.buttonToggleLaser.setStyleSheet("background-color: green")
            self.buttonToggleLaser.setText("Toggle laser: OFF")

    def buttonMeasureClicked(self):
        #A slot which handles Measure button click
        self.measureDistanceSignal.emit()
        # point = Point()
        # point.value = 6
        # point.angle = 56
        # point.error = 43
        # self.dataDisplayWidget.addPointToDisplay(point)
        return

    def buttonSetRelativeAngleToZeroClicked(self):
        #Slot which set  relative angle to zero degrees. Useful for calibration
        self.setAngleToZeroSignal.emit()
        return

    def buttonMoveRightPressed(self):
        #Slot
        self.moveRightStartSignal.emit()
        return

    def buttonMoveRightReleased(self):
        #Slot
        self.moveRightStopSignal.emit()
        return

    def buttonMoveLeftPressed(self):
        #Slot
        self.moveLeftStartSignal.emit()
        return

    def buttonMoveLeftReleased(self):
        #Slot
        self.moveLeftStopSignal.emit()
        return

    def buttonIncreaseSpeedClicked(self):
        if self.speed >= 10:
            return
        else:
            self.speed += 1
            self.sendSpeedSignal.emit(self.speed)
            self.updateDisplays()
        return

    def buttonDecreaseSpeedClicked(self):
        if self.speed <= 1:
            return
        else:
            self.speed -= 1
            self.sendSpeedSignal.emit(self.speed)
            self.updateDisplays()
        return

    def buttonGetWidthPressed(self):
        #Slot. Uses two last measurements and returns distance between these points
        self.calculateWidthSignal.emit()
        # point = Point()
        # point.value = 6324
        # point.objectType = "width"
        # point.angle = 99999
        # point.error = 43
        # self.dataDisplayWidget.addMeasurementToDisplay(point)
        return

    def buttonBluetoothConnectClicked(self):
        #Slot
        self.connectBluetoothSignal.emit()
        return

    def displayPikaPika(self):
        pika = QLabel(self)
        pix = QtGui.QPixmap("pika.png")
        pix = pix.scaled(800, 380)
        pika.setPixmap(pix)
        self.imagesLayout.addWidget(pika)

        pika.show()

        return

    def buttonScanRoomClicked(self):
        self.getMapSignal.emit()

        return

    def sendMarkNixon(self):
        img = QImage("nix.png")
        mp = Map()
        mp.mapImage = img
        self.imagesWidget.addNewMapPair(mp)
        return

    def receivePoint(self, point):
        point.value = round(point.value, 2)
        point.angle = round(point.angle, 2)
        point.error = round(point.error, 2)

        if point.objectType == "point":
            self.updateLastDistance(point)
            self.dataDisplayWidget.addMeasurementToDisplay(point)
        elif point.objectType == "width":
            self.commsThreadObject.response = "msg:" + str(
                point.value) + "," + str(point.angle)
            self.updateWidht(point)
            self.dataDisplayWidget.addMeasurementToDisplay(point)
        return

    def receiveMap(self, imageMap):
        self.imagesWidget.addNewMapPair(imageMap)

        return

    def updateLastDistance(self, point):
        #Move last to former
        self.formerDistance = self.lastDistance
        self.formerAngle = self.lastAngle

        self.lastDistance = point.value
        self.lastAngle = point.angle

        self.updateDisplays()

        return

    def updateWidht(self, point):
        self.lastWidth = point.value
        self.lastWidthDistance = point.angle
        self.updateDisplays()
        return

    def updateFirmware(self):
        pid = os.getpid()
        os.system("sudo python3 updater.py")
        os.kill(pid, signal.SIGKILL)

        return

    def addWarningDisplay(self):
        self.boxWarning = QTextEdit(
            "Measurements under 1m are likely to be inaccurate")
        self.boxWarning.setStyleSheet("background-color: white")
        self.boxWarning.setAlignment(Qt.AlignCenter)
        self.boxWarning.setReadOnly(True)
        self.boxWarning.setFixedHeight(50)
        self.controlLayout.addWidget(self.boxWarning, 0, 1)
import utilitaires as ut
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
                           
pygame.init()
screen = pygame.display.set_mode((860, 600), DOUBLEBUF and RESIZABLE)
pygame.display.set_caption("Test")
f = pygame.font.SysFont(pygame.font.get_default_font(), 20)
clock = pygame.time.Clock()
nb_e = 3
nb_s = 1

pop = Population(10, nb_e, nb_s)
pop.generer()

status = DataDisplay((0,0), padding = 20)
status.add("FPS", lambda : clock.get_fps())
status.add("Current generation", lambda : pop.generationCount)
status.add("Number of species", lambda : len(pop.especes))
status.add("Best fitness", pop.getBestFitness)
status.add("Best shared fitness", pop.getBestSharedFitness)
status.add("Average fitness", lambda : pop.averageFitness)

evol = False

while True:
    clock.tick()
    screen.fill((255,255,255))

    for event in pygame.event.get():
        if event.type == QUIT:
Esempio n. 10
0
class GLWidget(QtOpenGL.QGLWidget):
    # initial window size
    w, h = 1024, 768
    
    isInitialized = False
    
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.parent = parent
        self.setMouseTracking(True)
        
        self.nav = Navigation()
        self.navInterface = NavigationInterface(self.nav)
        self.dataDisplay = DataDisplay()
        
        # self.navigateSignal.connect(self.navigateEvent)
        SIGNALS.navigateSignal.connect(self.navigateEvent)

    def minimumSizeHint(self):
        return QtCore.QSize(50, 50)

    def sizeHint(self):
        return QtCore.QSize(self.w, self.h)
    
    # get position coordinates
    def coord(self, pos):
        return (pos.x(), pos.y())
    
    # get normalized coordinates
    def norm(self, pair):
        return (pair[0]/float(self.w), pair[1]/float(self.h))
    
    def ncoord(self, pos):
        return self.norm(self.coord(pos))
        
    def initializeGL(self):
        self.dataDisplay.initialize()
        self.isInitialized = True
        
    def paintGL(self):
        tx, ty = self.nav.get_translation()
        sx, sy = self.nav.get_scale()
        self.dataDisplay.transform(tx, ty, sx, sy)
        self.dataDisplay.paint()
    
    # handle window resizing
    def resizeGL(self, w, h):
        self.w, self.h = w, h
        self.dataDisplay.resize(w, h)
        
    def focusInEvent(self):
        pass
        
    def focusOutEvent(self):
        self.keyReleaseEvent(None)
        
    def navigateEvent(self):
        self.updateGL()
        
    def mousePressEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mousePress(x, y, event.button())
            
    def mouseReleaseEvent(self, event):
        self.navInterface.mouseRelease()

    def mouseMoveEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mouseMove(x, y)
        self.parent.statusbar.showMessage("%g, %g" % self.getMousePosition(x, y))
        if self.navInterface.mouseButton:
            SIGNALS.navigateSignal.emit()

    def getMousePosition(self, x, y):
        """
        convert mouse coordinates => data coordinates
        """
        tx, ty = self.nav.get_translation(False)
        sx, sy = self.nav.get_scale()
        # x = .5 * (1. - 1./sx) - tx + x/sx# + self.nav.offsetx
        # y = .5 * (1. - 1./sy) - ty + y/sy
        x, y = self.nav.get_data_coordinates(x, y)
        
        # inverse data normalization
        xmin, xmax, ymin, ymax = self.dataDisplay.get_bounds()
        x = xmin + x * (xmax - xmin)
        y = ymin + y * (ymax - ymin)
        y = -y
        return x, y
   
    def wheelEvent(self, event):
        self.navInterface.mouseWheel(event.delta())
        SIGNALS.navigateSignal.emit()
 
    def keyPressEvent(self, e):
        key = ""
        if e.key() == QtCore.Qt.Key_Control:
            key = KEY_CTRL
        if e.key() == QtCore.Qt.Key_Shift:
            key = KEY_SHIFT
        if e.key() == QtCore.Qt.Key_Alt:
            key = KEY_ALT
        if e.key() == QtCore.Qt.Key_Up:
            key = KEY_UP
        if e.key() == QtCore.Qt.Key_Down:
            key = KEY_DOWN
        if e.key() == QtCore.Qt.Key_Left:
            key = KEY_LEFT
        if e.key() == QtCore.Qt.Key_Right:
            key = KEY_RIGHT
        self.navInterface.keyPress(key)
        SIGNALS.navigateSignal.emit()
        
    def keyReleaseEvent(self, e):
        self.navInterface.keyRelease()

        
        
    # PUBLIC METHODS
    def slide(self, x, max):
        # slide, and update only if the transform is not null
        if (self.nav.slide(x, max)):
            self.updateGL()
        
    def reset(self):
        self.nav.reset()
        SIGNALS.navigateSignal.emit()
    
    def load_data(self, data, databounds=None, options=None):
        self.dataDisplay.load(data, databounds, options=options)
        # reload if already initialized
        if self.isInitialized:
            self.dataDisplay.bind_data_buffer()
            self.updateGL()
    
    def capture(self):
        glReadBuffer(GL_FRONT)
        image = self.grabFrameBuffer()
        return image