def setLeftSidedBox(self): # Left sided box for controls self.leftBox = QFormLayout() self.recordButton = QPushButton("Record") self.recordButton.setEnabled(False) self.recordButton.clicked.connect(self.startRecord) self.stopButton = QPushButton("Stop") self.stopButton.setEnabled(False) self.stopButton.clicked.connect(self.stopRecord) self.recordButtons = QGridLayout() self.recordButtons.addWidget( self.recordButton, 0, 0) self.recordButtons.addWidget( self.stopButton, 0, 1) self.leftBox.addRow(QLabel("Recording controls")) self.leftBox.addRow(self.recordButtons) self.route = QLineEdit() self.route.setReadOnly(True) self.examine = QPushButton("Examine") self.examine.clicked.connect(self.getFilename) folderButtons = QGridLayout() folderButtons.addWidget(self.route, 0, 0) folderButtons.addWidget(self.examine, 0, 1) self.leftBox.addRow(QLabel("Save folder")) self.leftBox.addRow(folderButtons) # Sensors status self.leftBox.addRow(QLabel("Sensor status")) self.headsetState = HeadStatusWidget(self.setPlotGraphBySensor) self.leftBox.addRow(self.headsetState) self.headsetState.updateHeadsetStatus(None)
def setLeftSidedBox(self): # Left sided box for controls self.leftBox = QFormLayout() self.recordButton = QPushButton("Grabar") self.recordButton.setEnabled(False) self.recordButton.clicked.connect(self.startRecord) self.stopButton = QPushButton("Detener") self.stopButton.setEnabled(False) self.stopButton.clicked.connect(self.stopRecord) self.recordButtons = QGridLayout() self.recordButtons.addWidget( self.recordButton, 0, 0) self.recordButtons.addWidget( self.stopButton, 0, 1) self.leftBox.addRow(QLabel("Controles de grabacion")) self.leftBox.addRow(self.recordButtons) self.route = QLineEdit() self.route.setReadOnly(True) self.examine = QPushButton("Examinar") self.examine.clicked.connect(self.getFilename) folderButtons = QGridLayout() folderButtons.addWidget(self.route, 0, 0) folderButtons.addWidget(self.examine, 0, 1) self.leftBox.addRow(QLabel("Carpeta de guardado")) self.leftBox.addRow(folderButtons) # Sensors status self.leftBox.addRow(QLabel("Estado de los sensores")) self.headsetState = HeadStatusWidget(self.setPlotGraphBySensor) self.leftBox.addRow(self.headsetState) self.headsetState.updateHeadsetStatus(None)
def setLeftSidedBox(self): # Left sided box for controls self.leftBox = QFormLayout() # Folder selection buttons self.route = QLineEdit() self.route.setReadOnly(True) self.examine = QPushButton("Examinar") self.examine.clicked.connect(self.getFilename) folderButtons = QGridLayout() folderButtons.addWidget(self.route, 0, 0) folderButtons.addWidget(self.examine, 0, 1) self.leftBox.addRow(QLabel("Archivo escogido")) self.leftBox.addRow(folderButtons) # Action selection buttons self.startBtn = QPushButton("Iniciar") self.startBtn.setEnabled(False) self.startBtn.clicked.connect(self.startReading) self.stopBtn = QPushButton("Pausar") self.stopBtn.setEnabled(False) self.stopBtn.clicked.connect(self.stopReading) self.restartBtn = QPushButton("Reiniciar") self.restartBtn.setEnabled(False) self.restartBtn.clicked.connect(self.restartReading) actionsButtons = QGridLayout() actionsButtons.addWidget(self.startBtn, 0, 0) actionsButtons.addWidget(self.stopBtn, 0, 1) actionsButtons.addWidget(self.restartBtn, 0, 2) self.leftBox.addRow(QLabel("Control")) self.leftBox.addRow(actionsButtons) # Sensors status self.leftBox.addRow(QLabel("Estado de los sensores")) self.headsetState = HeadStatusWidget(self.setPlotGraphBySensor) self.leftBox.addRow(self.headsetState) self.headsetState.updateHeadsetStatus(None)
class FromFile: def __init__(self, parent=None): self.parser = PacketParser() self.timer = pg.QtCore.QTimer() self.electrodePairing = {\ "AF3": {'pair': "AF4", 'order': 1}, "AF4": {'pair': "AF3", 'order': 0}, "F3": {'pair': "F4", 'order': 1}, "F4": {'pair': "F3", 'order': 0}, "F7": {'pair': "F8", 'order': 1}, "F8": {'pair': "F7", 'order': 0}, "FC5": {'pair': "FC6", 'order': 1}, "FC6": {'pair': "FC5", 'order': 0}, "T7": {'pair': "T8", 'order': 1}, "T8": {'pair': "T7", 'order': 0}, "P7": {'pair': "P8", 'order': 1}, "P8": {'pair': "P7", 'order': 0}, "O1": {'pair': "O2", 'order': 1}, "O2": {'pair': "O1", 'order': 0}, } def setFromFileTab(self): self.setLeftSidedBox() self.setCenterBox() # Main grid layout self.gridLayout = QGridLayout() self.gridLayout.addLayout( self.leftBox, 0, 0) self.gridLayout.addLayout( self.centerBox, 0, 1) self.gridLayout.setColumnStretch(0, 1) self.gridLayout.setColumnStretch(1, 3) return self.gridLayout def setLeftSidedBox(self): # Left sided box for controls self.leftBox = QFormLayout() # Folder selection buttons self.route = QLineEdit() self.route.setReadOnly(True) self.examine = QPushButton("Examinar") self.examine.clicked.connect(self.getFilename) folderButtons = QGridLayout() folderButtons.addWidget(self.route, 0, 0) folderButtons.addWidget(self.examine, 0, 1) self.leftBox.addRow(QLabel("Archivo escogido")) self.leftBox.addRow(folderButtons) # Action selection buttons self.startBtn = QPushButton("Iniciar") self.startBtn.setEnabled(False) self.startBtn.clicked.connect(self.startReading) self.stopBtn = QPushButton("Pausar") self.stopBtn.setEnabled(False) self.stopBtn.clicked.connect(self.stopReading) self.restartBtn = QPushButton("Reiniciar") self.restartBtn.setEnabled(False) self.restartBtn.clicked.connect(self.restartReading) actionsButtons = QGridLayout() actionsButtons.addWidget(self.startBtn, 0, 0) actionsButtons.addWidget(self.stopBtn, 0, 1) actionsButtons.addWidget(self.restartBtn, 0, 2) self.leftBox.addRow(QLabel("Control")) self.leftBox.addRow(actionsButtons) # Sensors status self.leftBox.addRow(QLabel("Estado de los sensores")) self.headsetState = HeadStatusWidget(self.setPlotGraphBySensor) self.leftBox.addRow(self.headsetState) self.headsetState.updateHeadsetStatus(None) def setPlotGraphBySensor(self, sensor): self.plots.setVisible(False) self.heatmap.setVisible(False) self.altPlots.setVisible(True) if self.electrodePairing[sensor]["order"]: self.altPlots.restartSensors( [ sensor, self.electrodePairing[sensor]["pair"]] ) else: self.altPlots.restartSensors([ self.electrodePairing[sensor]["pair"], sensor ]) self.toggleGraph.setVisible(False) self.returnToGraphs.setVisible(True) def setCenterBox(self): # Center sided box for signals self.centerBox = QFormLayout() self.centerBox.addRow(QLabel("Estado de las senales")) self.activeGraph = True self.toggleGraph = QPushButton("Mapa de calor") self.toggleGraph.setEnabled( False ) self.toggleGraph.clicked.connect( self.toggleGraphics ) self.centerBox.addRow( self.toggleGraph ) self.returnToGraphs = QPushButton("Regresar") self.returnToGraphs.setVisible(False) self.returnToGraphs.clicked.connect(self.returnToGraphics) self.centerBox.addRow(self.returnToGraphs) self.plots = PlottingWidget() self.centerBox.addRow( self.plots ) self.heatmap = HeatMapWidget() self.centerBox.addRow(self.heatmap) self.toggleGraphics() self.altPlots = PlottingWidget([]) self.centerBox.addRow(self.altPlots) self.altPlots.setVisible(False) def toggleGraphics(self): if not self.activeGraph: self.plots.setVisible(False) self.heatmap.setVisible(True) self.toggleGraph.setText("Graficas") self.activeGraph = True else: self.plots.setVisible(True) self.heatmap.setVisible(False) self.toggleGraph.setText("Mapa de calor") self.activeGraph = False def returnToGraphics(self): self.altPlots.setVisible(False) self.returnToGraphs.setVisible(False) self.plots.setVisible(True) self.toggleGraph.setVisible(True) def startReading(self): self.startBtn.setEnabled(False) self.stopBtn.setEnabled(True) self.toggleGraph.setEnabled(True) self.timer.timeout.connect( self.setupNewPacket ) self.timer.start(10) def stopReading(self): self.timer.stop() self.stopBtn.setEnabled(False) self.startBtn.setEnabled(True) def restartReading(self): self.altPlots.setVisible(False) self.returnToGraphs.setVisible(False) self.startBtn.setEnabled(False) self.stopBtn.setEnabled(False) self.restartBtn.setEnabled(False) self.toggleGraph.setEnabled(False) self.timer.stop() self.fileRoute = "" self.route.setText(self.fileRoute) self.csvfile = None self.file = None self.headers = None self.plots.restartPlotting() self.plots.setVisible(True) self.activeGraph = True self.heatmap.updateHeatMapStatus(None) if self.activeGraph: self.toggleGraphics() self.headsetState.updateHeadsetStatus(None) def setupNewPacket(self): nextPacket = next(self.file) parsed = self.parser.fromCSVToPacket( list(self.headers), nextPacket ) self.plots.updater( parsed ) self.heatmap.updateHeatMapStatus(parsed) self.headsetState.updateHeadsetStatus(parsed) if self.altPlots != None: self.altPlots.updater(parsed) def getFilename(self): filename = QFileDialog.getOpenFileName(self.examine, 'Open file', 'c:\\', "CSV (*.csv)") self.fileRoute = filename[0] self.route.setText( self.fileRoute ) self.csvfile = open(self.fileRoute, 'rb') self.file = csv.reader(self.csvfile, delimiter=',', quotechar='|') self.headers = next(self.file) self.startBtn.setEnabled(True) self.restartBtn.setEnabled(True)
class Record: def __init__(self, parent=None): self.headset = Emotiv() self.electrodePairing = { \ "AF3": {'pair': "AF4", 'order': 1}, "AF4": {'pair': "AF3", 'order': 0}, "F3": {'pair': "F4", 'order': 1}, "F4": {'pair': "F3", 'order': 0}, "F7": {'pair': "F8", 'order': 1}, "F8": {'pair': "F7", 'order': 0}, "FC5": {'pair': "FC6", 'order': 1}, "FC6": {'pair': "FC5", 'order': 0}, "T7": {'pair': "T8", 'order': 1}, "T8": {'pair': "T7", 'order': 0}, "P7": {'pair': "P8", 'order': 1}, "P8": {'pair': "P7", 'order': 0}, "O1": {'pair': "O2", 'order': 1}, "O2": {'pair': "O1", 'order': 0}, } self.timer = pg.QtCore.QTimer() self.recording = False self.parser = PacketParser() self.header_text = "Timestamp,F3 Value,F3 Quality,FC5 Value,FC5 Quality,F7 Value,F7 Quality,T7 Value,T7 Quality,P7 Value,P7 Quality,O1 Value,O1 Quality,O2 Value,O2 Quality,P8 Value,P8 Quality,T8 Value,T8 Quality,F8 Value,F8 Quality,AF4 Value,AF4 Quality,FC6 Value,FC6 Quality,F4 Value,F4 Quality,AF3 Value,AF3 Quality,X Value,Y Value,Z Value" def setPlotGraphBySensor(self, sensor): self.plots.setVisible(False) self.altPlots.setVisible(True) if self.electrodePairing[sensor]["order"]: self.altPlots.restartSensors( [ sensor, self.electrodePairing[sensor]["pair"]] ) else: self.altPlots.restartSensors([ self.electrodePairing[sensor]["pair"], sensor ]) self.returnToGraphs.setVisible(True) def update(self): packet = self.headset.dequeue() if packet != None: self.plots.updater(packet) self.headsetState.updateHeadsetStatus(packet) if self.recording: row = self.parser.fromPacketToCSV( packet ) self.output_file.write(row + "\n") def setRecordTab(self): self.setLeftSidedBox() self.setCenterBox() # Main grid layout self.gridLayout = QGridLayout() self.gridLayout.addLayout( self.leftBox, 0, 0) self.gridLayout.addLayout( self.centerBox, 0, 1) self.gridLayout.setColumnStretch(0, 1) self.gridLayout.setColumnStretch(1, 3) return self.gridLayout def setLeftSidedBox(self): # Left sided box for controls self.leftBox = QFormLayout() self.recordButton = QPushButton("Record") self.recordButton.setEnabled(False) self.recordButton.clicked.connect(self.startRecord) self.stopButton = QPushButton("Stop") self.stopButton.setEnabled(False) self.stopButton.clicked.connect(self.stopRecord) self.recordButtons = QGridLayout() self.recordButtons.addWidget( self.recordButton, 0, 0) self.recordButtons.addWidget( self.stopButton, 0, 1) self.leftBox.addRow(QLabel("Recording controls")) self.leftBox.addRow(self.recordButtons) self.route = QLineEdit() self.route.setReadOnly(True) self.examine = QPushButton("Examine") self.examine.clicked.connect(self.getFilename) folderButtons = QGridLayout() folderButtons.addWidget(self.route, 0, 0) folderButtons.addWidget(self.examine, 0, 1) self.leftBox.addRow(QLabel("Save folder")) self.leftBox.addRow(folderButtons) # Sensors status self.leftBox.addRow(QLabel("Sensor status")) self.headsetState = HeadStatusWidget(self.setPlotGraphBySensor) self.leftBox.addRow(self.headsetState) self.headsetState.updateHeadsetStatus(None) def setCenterBox(self): # Center sided box for signals self.centerBox = QFormLayout() self.centerBox.addRow(QLabel("Signal status")) self.returnToGraphs = QPushButton("Return") self.returnToGraphs.setVisible(False) self.returnToGraphs.clicked.connect(self.returnToGraphics) self.centerBox.addRow(self.returnToGraphs) self.plots = PlottingWidget() self.centerBox.addRow(self.plots) self.altPlots = PlottingWidget([]) self.centerBox.addRow(self.altPlots) self.altPlots.setVisible(False) def returnToGraphics(self): self.altPlots.setVisible(False) self.returnToGraphs.setVisible(False) self.plots.setVisible(True) def getFilename(self): filename = QFileDialog.getExistingDirectory(self.examine, "Open Directory", "/home", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks); self.fileRoute = filename self.route.setText(self.fileRoute) self.recordButton.setEnabled(True) def startRecord(self): self.stopButton.setEnabled(True) self.recordButton.setEnabled(False) self.recording = True self.file_name += datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%H-%M-%S') + ".csv" self.output_file = open(self.file_name, 'w') self.output_file.write(self.header_text + "\n") def stopRecord(self): self.output_file.close()