Example #1
0
 def create_gps_view(label=''):
     window = QMainWindow()
     view = GPSView(window)
     window.setCentralWidget(view)
     window.setWindowTitle(label)
     window.resize(640, 480)
     return [window, view]
Example #2
0
    def __init__(self, graph_type: GraphType, sensor: Sensor, parent=None):
        super().__init__(parent=parent)
        self.UI = Ui_frmGraphWidget()
        self.UI.setupUi(self)

        self.sensor = sensor

        # Create correct graph
        self.graph = None
        if graph_type == GraphType.LINECHART:
            self.graph = IMUChartView(self)

        if graph_type == GraphType.MAP:
            self.graph = GPSView(self)

        if self.graph is None:
            print("GraphWindow: Undefined graph type.")
            return

        self.UI.wdgChart.layout().addWidget(self.graph)

        # Initial UI state
        self.UI.btnClearSelection.setEnabled(False)
        self.mode_buttons_group = QButtonGroup()
        self.mode_buttons_group.addButton(self.UI.btnSelect)
        self.mode_buttons_group.addButton(self.UI.btnMove)

        self.update_zoom_buttons_state()

        # Connect signals
        self.UI.btnClearSelection.clicked.connect(self.clearSelectionRequest)
        self.UI.btnZoomArea.clicked.connect(self.zoomAreaRequest)
        self.UI.btnZoomIn.clicked.connect(self.zoomInRequest)
        self.UI.btnZoomOut.clicked.connect(self.zoomOutRequest)
        self.UI.btnZoomReset.clicked.connect(self.zoomResetRequest)
        self.UI.btnDataInfos.clicked.connect(self.dataInfosRequest)
        self.mode_buttons_group.buttonClicked.connect(
            self.graph_interaction_mode_changed)
        self.graph.selectedAreaChanged.connect(self.graph_selection_changed)
        self.graph.clearedSelectionArea.connect(self.graph_selection_changed)

        # self.UI.btnMove.setChecked(True)
        # self.graph.set_interaction_mode(GraphInteractionMode.MOVE)
        self.UI.btnSelect.setChecked(True)
        self.graph.set_interaction_mode(GraphInteractionMode.SELECT)
Example #3
0
    def sensor_current_changed(self, item):
        sensor = self.sensors[item.data(Qt.UserRole)]
        timeseries = []
        # Color map
        colors = [Qt.red, Qt.green, Qt.yellow, Qt.cyan]

        if item.checkState() == Qt.Checked:
            # Choose the correct display for each sensor
            graph = None
            channels = self.dbMan.get_all_channels(sensor=sensor)
            for channel in channels:
                # Will get all data (converted to floats)
                channel_data = []
                for record in self.recordsets:
                    channel_data += self.dbMan.get_all_sensor_data(
                        recordset=record,
                        convert=True,
                        sensor=sensor,
                        channel=channel)
                timeseries.append(self.create_data_timeseries(channel_data))
                timeseries[-1]['label'] = channel.label

            if sensor.id_sensor_type == SensorType.ACCELEROMETER \
                    or sensor.id_sensor_type == SensorType.GYROMETER \
                    or sensor.id_sensor_type == SensorType.BATTERY \
                    or sensor.id_sensor_type == SensorType.LUX \
                    or sensor.id_sensor_type == SensorType.CURRENT \
                    or sensor.id_sensor_type == SensorType.BAROMETER \
                    or sensor.id_sensor_type == SensorType.MAGNETOMETER \
                    or sensor.id_sensor_type == SensorType.TEMPERATURE \
                    or sensor.id_sensor_type == SensorType.HEARTRATE \
                    or sensor.id_sensor_type == SensorType.ORIENTATION \
                    or sensor.id_sensor_type == SensorType.FSR:

                #graph = IMUChartView(self.UI.displayContents)
                graph = IMUChartView(self.UI.mdiArea)
                # graph.add_test_data()
                # Add series
                for series in timeseries:
                    graph.add_data(series['x'],
                                   series['y'],
                                   color=colors.pop(),
                                   legend_text=series['label'])

                graph.set_title(item.text())

            if sensor.id_sensor_type == SensorType.GPS:
                # graph = GPSView(self.UI.mdiArea)
                """base_widget = QWidget(self.UI.displayContents)
                base_widget.setFixedHeight(400)
                base_widget.setMaximumHeight(400)"""
                base_widget = self.UI.mdiArea
                graph = GPSView(base_widget)

                for data in channel_data:
                    gps = GPSGeodetic()
                    gps.from_bytes(data.data)
                    if gps.latitude != 0 and gps.longitude != 0:
                        graph.addPosition(data.timestamps.start_timestamp,
                                          gps.latitude / 1e7,
                                          gps.longitude / 1e7)
                        graph.setCursorPositionFromTime(
                            data.timestamps.start_timestamp)
                    # print (gps)

            if graph is not None:
                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                self.sensors_graphs[sensor.id_sensor] = graph
                #self.UI.displayContents.layout().insertWidget(0,graph)

                graph.show()
                QApplication.instance().processEvents()

                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

                #self.UI.displayArea.ensureWidgetVisible(graph)
                # self.UI.displayArea.verticalScrollBar().setSliderPosition(self.UI.displayArea.verticalScrollBar().maximum())
                # self.tile_graphs_vertically()
                self.UI.mdiArea.tileSubWindows()

        else:
            # Remove from display
            try:
                if self.sensors_graphs[sensor.id_sensor] is not None:
                    self.UI.mdiArea.removeSubWindow(
                        self.sensors_graphs[sensor.id_sensor].parent())
                    self.sensors_graphs[sensor.id_sensor].hide()
                    self.sensors_graphs[sensor.id_sensor] = None
                    # self.tile_graphs_vertically()
                    self.UI.mdiArea.tileSubWindows()
            except KeyError:
                pass
Example #4
0
class GraphWindow(QWidget):

    aboutToClose = pyqtSignal(QObject)
    requestData = pyqtSignal(Sensor, datetime.datetime, datetime.datetime)
    zoomAreaRequested = pyqtSignal(datetime.datetime, datetime.datetime)
    zoomResetRequested = pyqtSignal()

    def __init__(self, graph_type: GraphType, sensor: Sensor, parent=None):
        super().__init__(parent=parent)
        self.UI = Ui_frmGraphWidget()
        self.UI.setupUi(self)

        self.sensor = sensor

        # Create correct graph
        self.graph = None
        if graph_type == GraphType.LINECHART:
            self.graph = IMUChartView(self)

        if graph_type == GraphType.MAP:
            self.graph = GPSView(self)

        if self.graph is None:
            print("GraphWindow: Undefined graph type.")
            return

        self.UI.wdgChart.layout().addWidget(self.graph)

        # Initial UI state
        self.UI.btnClearSelection.setEnabled(False)
        self.mode_buttons_group = QButtonGroup()
        self.mode_buttons_group.addButton(self.UI.btnSelect)
        self.mode_buttons_group.addButton(self.UI.btnMove)

        self.update_zoom_buttons_state()

        # Connect signals
        self.UI.btnClearSelection.clicked.connect(self.clearSelectionRequest)
        self.UI.btnZoomArea.clicked.connect(self.zoomAreaRequest)
        self.UI.btnZoomIn.clicked.connect(self.zoomInRequest)
        self.UI.btnZoomOut.clicked.connect(self.zoomOutRequest)
        self.UI.btnZoomReset.clicked.connect(self.zoomResetRequest)
        self.UI.btnDataInfos.clicked.connect(self.dataInfosRequest)
        self.mode_buttons_group.buttonClicked.connect(
            self.graph_interaction_mode_changed)
        self.graph.selectedAreaChanged.connect(self.graph_selection_changed)
        self.graph.clearedSelectionArea.connect(self.graph_selection_changed)

        # self.UI.btnMove.setChecked(True)
        # self.graph.set_interaction_mode(GraphInteractionMode.MOVE)
        self.UI.btnSelect.setChecked(True)
        self.graph.set_interaction_mode(GraphInteractionMode.SELECT)

    def event(self, e):
        if e.type() == QEvent.Enter:
            # Over the widget - show toolbar
            # self.UI.frameTools.show()
            pass

        if e.type() == QEvent.Leave:
            # Not over the widget - hide toolbar
            # self.UI.frameTools.hide()
            pass

        if e.type() == QEvent.Close:
            self.aboutToClose.emit(self)

        return super().event(e)

    def setCursorPositionFromTime(self, timestamp, emit_signal=False):
        if self.graph is not None:
            self.graph.setCursorPositionFromTime(timestamp, emit_signal)

    def setSelectionAreaFromTime(self,
                                 start_time,
                                 end_time,
                                 emit_signal=False):
        if self.graph is not None:
            self.graph.setSelectionAreaFromTime(start_time, end_time,
                                                emit_signal)
            self.update_zoom_buttons_state()

    def clearSelectionArea(self):
        if self.graph is not None:
            self.graph.clearSelectionArea(False)
            self.UI.btnClearSelection.setEnabled(False)
            self.update_zoom_buttons_state()

    def update_zoom_buttons_state(self):
        self.UI.btnZoomArea.setEnabled(self.graph.selection_rec is not None)
        self.UI.btnZoomOut.setEnabled(self.graph.is_zoomed)
        self.UI.btnZoomReset.setEnabled(self.graph.is_zoomed)

    @pyqtSlot()
    def clearSelectionRequest(self):
        self.graph.clearSelectionArea(True)
        self.UI.btnClearSelection.setEnabled(False)

    @pyqtSlot()
    def zoomAreaRequest(self):
        if self.graph:
            self.graph.zoom_area()
            self.requestData.emit(self.sensor,
                                  self.graph.get_displayed_start_time(),
                                  self.graph.get_displayed_end_time())
            self.zoomAreaRequested.emit(self.graph.get_displayed_start_time(),
                                        self.graph.get_displayed_end_time())
        self.update_zoom_buttons_state()

    def zoomAreaRequestTime(self,
                            start_time: float,
                            end_time: float,
                            emit_signal=False):
        if self.graph:
            self.graph.setSelectionAreaFromTime(start_time, end_time,
                                                emit_signal)
            self.graph.zoom_area()

    @pyqtSlot()
    def zoomOutRequest(self):
        if self.graph:
            self.graph.zoom_out()
            self.requestData.emit(self.sensor,
                                  self.graph.get_displayed_start_time(),
                                  self.graph.get_displayed_end_time())
            self.zoomAreaRequested.emit(self.graph.get_displayed_start_time(),
                                        self.graph.get_displayed_end_time())
        self.update_zoom_buttons_state()

    @pyqtSlot()
    def zoomInRequest(self):
        if self.graph:
            self.graph.zoom_in()
            self.requestData.emit(self.sensor,
                                  self.graph.get_displayed_start_time(),
                                  self.graph.get_displayed_end_time())
            self.zoomAreaRequested.emit(self.graph.get_displayed_start_time(),
                                        self.graph.get_displayed_end_time())
        self.update_zoom_buttons_state()

    @pyqtSlot()
    def zoomResetRequest(self, emit_signal=True):
        if self.graph:
            self.graph.zoom_reset()
            if emit_signal:
                self.zoomResetRequested.emit()
        self.update_zoom_buttons_state()

    @pyqtSlot()
    def dataInfosRequest(self):
        infos = DataInfosWidget(self.sensor,
                                self.graph.total_samples,
                                parent=self)
        # infos.setStyleSheet(self.styleSheet())
        infos.exec()

    @pyqtSlot()
    def graph_selection_changed(self):
        self.UI.btnClearSelection.setEnabled(
            self.graph.selection_rec is not None)
        self.update_zoom_buttons_state()

    @pyqtSlot(QAbstractButton)
    def graph_interaction_mode_changed(self, button=QAbstractButton):
        if button == self.UI.btnSelect:
            self.graph.set_interaction_mode(GraphInteractionMode.SELECT)
        if button == self.UI.btnMove:
            self.graph.set_interaction_mode(GraphInteractionMode.MOVE)
Example #5
0
    def sensor_current_changed(self, item):
        sensor = self.sensors[item.data(Qt.UserRole)]
        timeseries = []
        # Color map
        colors = [Qt.red, Qt.green, Qt.darkBlue]

        if item.checkState() == Qt.Checked:
            # Choose the correct display for each sensor

            channels = self.dbMan.get_all_channels(sensor=sensor)
            for channel in channels:
                # Will get all data (converted to floats)
                channel_data = []
                for record in self.recordsets:
                    channel_data += self.dbMan.get_all_sensor_data(
                        recordset=record,
                        convert=True,
                        sensor=sensor,
                        channel=channel)

            if sensor.id_sensor_type == SensorType.ACCELEROMETER \
                or sensor.id_sensor_type == SensorType.GYROMETER \
                    or sensor.id_sensor_type == SensorType.BATTERY\
                        or sensor.id_sensor_type == SensorType.LUX:

                timeseries.append(self.create_data_timeseries(channel_data))
                timeseries[-1]['label'] = channel.label

                graph = IMUChartView()
                # graph.add_test_data()
                # Add series
                for series in timeseries:
                    graph.add_data(series['x'],
                                   series['y'],
                                   color=colors.pop(),
                                   legend_text=series['label'])

                graph.set_title(item.text())
                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                graph.show()

                self.sensors_graphs[sensor.id_sensor] = graph
                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

                self.tile_graphs_vertically()

            if sensor.id_sensor_type == SensorType.GPS:
                graph = GPSView(self.UI.mdiArea)

                for data in channel_data:
                    gps = GPSGeodetic()
                    gps.from_bytes(data.data)
                    if gps.latitude != 0 and gps.longitude != 0:
                        graph.addPosition(data.start_timestamp,
                                          gps.latitude / 1e7,
                                          gps.longitude / 1e7)
                        graph.setCursorPositionFromTime(data.start_timestamp)
                    # print (gps)

                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                graph.show()
                self.sensors_graphs[sensor.id_sensor] = graph
                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

        else:
            # Remove from display
            if self.sensors_graphs[sensor.id_sensor] is not None:
                self.UI.mdiArea.removeSubWindow(
                    self.sensors_graphs[sensor.id_sensor].parent())
                self.sensors_graphs[sensor.id_sensor] = None