コード例 #1
0
 def create_window(label=''):
     window = QMainWindow()
     view = IMUChartView(window)
     window.setCentralWidget(view)
     window.setWindowTitle(label)
     window.resize(640, 480)
     return [window, view]
コード例 #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 graph_type == GraphType.BEACON:
            self.graph = BeaconsView(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)
コード例 #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
コード例 #4
0
ファイル: MainWindow.py プロジェクト: mfkiwl/OpenIMU
 def create_chart_view(self, test_data=False):
     chart_view = IMUChartView(self)
     if test_data is True:
         chart_view.add_test_data()
     return chart_view
コード例 #5
0
ファイル: RecordsetWindow.py プロジェクト: kfriesth/OpenIMU
    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