Ejemplo n.º 1
0
    def initUI(self):
        self.setWindowIcon(QtGui.QIcon())
        self.setWindowTitle('Arena Controller')

        #Create important actions
        exitAction = QtGui.QAction('Exit',self)
        exitAction.triggered.connect(self.close)

        camAction = QtGui.QAction('Camera',self)
        camAction.triggered.connect(self.connectToCamera)

        ardAction = QtGui.QAction('Arduino',self)
        ardAction.triggered.connect(self.connectToArduino)

        self.playAction = QtGui.QAction('Play/Pause',self)
        self.playAction.setCheckable(True)
        self.playAction.setChecked(True)
        self.playAction.triggered.connect(self.playpause)

        self.nextViewAction = QtGui.QAction('DispMode:Raw',self)
        self.nextViewAction.triggered.connect(self.nextDispMode)

        self.startExpAction = QtGui.QAction('Start',self)
        self.startExpAction.setCheckable(True)
        self.startExpAction.setChecked(False)
        self.startExpAction.triggered.connect(self.startExperiment)

        #Create the menu bar
        menubar = self.menuBar()
        fileMenu= menubar.addMenu('&File')
        fileMenu.addAction(exitAction)
        fileMenu.addAction(camAction)

        #Create a toolbar
        self.toolbar = self.addToolBar('Main')
        self.toolbar.addAction(camAction)
        self.toolbar.addAction(ardAction)
        self.toolbar.addSeparator()
        #note that widgets can also be added to the toolbar (like a text box)
        self.toolbar.addAction(self.playAction)
        self.toolbar.addAction(self.nextViewAction)
        self.toolbar.addAction(self.startExpAction)
        self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea and QtCore.Qt.TopToolBarArea)

 
        #Initialize the settings panel (borrowed Broxton's code)
        self.settingsManager = SettingsPanelManager(self)

        #add arena management panel
        from ArenaManagementPanel import ArenaManagementPanel
        self.arenaPanel = ArenaManagementPanel(self,self)
        self.settingsManager.add(SettingsPanel(name = "Arenas", message = "",
                                               widget = self.arenaPanel))
        #self.connect(self.arenaPanel,
        #             QtCore.SIGNAL('postprocessChanged()'),
        #             self.imageDispWidget.updateDisplay)
        #             self.displaySettings.updateFromParent)
                
        #create the central panel
        self.ftDisp = FishTrackingDisplay() #this label will be used to display video
        self.ftDisp.setAlignment(QtCore.Qt.AlignLeft)  
        self.setCentralWidget(self.ftDisp)

        self.setGeometry(0, 0, 1700, 900)

        #Init to the status bar
        self.statusBar().showMessage('No camera connected. Click on camera connect.')
        self.show()
Ejemplo n.º 2
0
class ArenaControllerMainWindow(QtGui.QMainWindow):

    def __init__(self):
        super(ArenaControllerMainWindow, self).__init__()

        #devices
        self.cam = None
        self.ard = None
        #self.labjack = u6.U6()
        #do I need to do anything to configure a couple registers?

        #parameters and state
        self.bDispRawImage = True
        self.currCvFrame = None
        self.currDispFrame = None
        self.initUI()
        self.projWin = ArenaControllerProjectorWindow(self)
        self.updateTimer = self.startTimer(1)

    def initUI(self):
        self.setWindowIcon(QtGui.QIcon())
        self.setWindowTitle('Arena Controller')

        #Create important actions
        exitAction = QtGui.QAction('Exit',self)
        exitAction.triggered.connect(self.close)

        camAction = QtGui.QAction('Camera',self)
        camAction.triggered.connect(self.connectToCamera)

        ardAction = QtGui.QAction('Arduino',self)
        ardAction.triggered.connect(self.connectToArduino)

        self.playAction = QtGui.QAction('Play/Pause',self)
        self.playAction.setCheckable(True)
        self.playAction.setChecked(True)
        self.playAction.triggered.connect(self.playpause)

        self.nextViewAction = QtGui.QAction('DispMode:Raw',self)
        self.nextViewAction.triggered.connect(self.nextDispMode)

        self.startExpAction = QtGui.QAction('Start',self)
        self.startExpAction.setCheckable(True)
        self.startExpAction.setChecked(False)
        self.startExpAction.triggered.connect(self.startExperiment)

        #Create the menu bar
        menubar = self.menuBar()
        fileMenu= menubar.addMenu('&File')
        fileMenu.addAction(exitAction)
        fileMenu.addAction(camAction)

        #Create a toolbar
        self.toolbar = self.addToolBar('Main')
        self.toolbar.addAction(camAction)
        self.toolbar.addAction(ardAction)
        self.toolbar.addSeparator()
        #note that widgets can also be added to the toolbar (like a text box)
        self.toolbar.addAction(self.playAction)
        self.toolbar.addAction(self.nextViewAction)
        self.toolbar.addAction(self.startExpAction)
        self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea and QtCore.Qt.TopToolBarArea)

 
        #Initialize the settings panel (borrowed Broxton's code)
        self.settingsManager = SettingsPanelManager(self)

        #add arena management panel
        from ArenaManagementPanel import ArenaManagementPanel
        self.arenaPanel = ArenaManagementPanel(self,self)
        self.settingsManager.add(SettingsPanel(name = "Arenas", message = "",
                                               widget = self.arenaPanel))
        #self.connect(self.arenaPanel,
        #             QtCore.SIGNAL('postprocessChanged()'),
        #             self.imageDispWidget.updateDisplay)
        #             self.displaySettings.updateFromParent)
                
        #create the central panel
        self.ftDisp = FishTrackingDisplay() #this label will be used to display video
        self.ftDisp.setAlignment(QtCore.Qt.AlignLeft)  
        self.setCentralWidget(self.ftDisp)

        self.setGeometry(0, 0, 1700, 900)

        #Init to the status bar
        self.statusBar().showMessage('No camera connected. Click on camera connect.')
        self.show()

    def closeEvent(self, event):
        if self.projWin: 
            self.projWin.close()

    def connectToCamera(self):
        cameraId, ok = QtGui.QInputDialog.getInt(self, 'Camera Info', 'Enter a Camera ID (try 0,1,-1, or 2):', value=0)
        if ok:
            self.cam = CameraDevice(cameraId=cameraId, parent=self)
            self.cam.newFrame.connect(self.onNewFrame)
            self.cam.paused = False
            self.statusBar().showMessage('Camera connected.')

    def connectToArduino(self):
        portName, ok = QtGui.QInputDialog.getText(self, 'Arduino Port', 'Enter the arduino port:',
                                  text=aac.SerialArduinoController.static_getDefaultPortName())
        portName = str(portName)
        self.statusBar().showMessage('Restart the arduino to complete the connection.')
        if self.ard == None:
            self.ard = aac.SerialArduinoController(portName=portName) 
        else:
            self.ard.connect(portName=portName)

        if self.ard.isConnected():
            self.statusBar().showMessage('Arduino connected.')
        else:
            self.statusBar().showMessage('Arduino failed to connect. Restart arduino and try again.')

    def playpause(self):
        if not self.cam==None:
            self.cam.paused = not self.cam.paused
            if self.cam.paused:
                self.playAction.setText('Play')
            else:
                self.playAction.setText('Pause')

    def nextDispMode(self):
        self.bDispRawImage = not self.bDispRawImage
        if self.bDispRawImage:
            self.nextViewAction.setText('DispMode:Raw')
        else:
            self.nextViewAction.setText('DispMode:CurrArena')

    def onNewFrame(self, frame):
        self.frameTime = time.time()
        self.currCvFrame = cv.CloneImage(frame)
        self.arenaPanel.onNewFrame(self.currCvFrame, self.frameTime)
        self.updateMainDisplay()

    def updateMainDisplay(self):
        #start with either the raw image or the current arena image
        if self.bDispRawImage:
            dispImg = OpenCVQImage(self.currCvFrame)
        else:
            cvImg = self.arenaPanel.getCurrentArenaView()
            if cvImg:
                dispImg = OpenCVQImage(cvImg)
            else:
                dispImg = OpenCVQImage(self.currCvFrame)
        #let each arena draw overlays
        painter = QtGui.QPainter()
        painter.begin(dispImg)
        self.arenaPanel.drawDisplayOverlays(painter)
        painter.end()
        #draw the overlaid image
        pixmap = QtGui.QPixmap.fromImage(dispImg)
        self.ftDisp.setPixmap(pixmap)

    def updateProjectorDisplay(self):
        self.projWin.updateProjectorDisplay()

    def drawProjectorDisplay(self, painter):
        self.arenaPanel.drawProjectorDisplay(painter)

    def startExperiment(self):
        if self.startExpAction.isChecked():
            self.startExpAction.setText('Stop')
            self.arenaPanel.startArenas()
        else:
            self.startExpAction.setText('Start ')
            self.arenaPanel.stopArenas()

    def timerEvent(self, event):
        self.arenaPanel.updateState()