Skip to content

Axis Table

AxisTableMixin

Mixins class for the Axes tab of the settings section.

Source code in trace/mixins/axis_table.py
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class AxisTableMixin:
    """Mixins class for the Axes tab of the settings section."""

    def axis_table_init(self) -> None:
        """Initializer for the Axis Table Model and Table View."""
        self.axis_table_model = ArchiverAxisModel(self.ui.main_plot, self)
        self.ui.time_axis_tbl.setModel(self.axis_table_model)

        label_col = self.axis_table_model.getColumnIndex("Y-Axis Label")
        self.ui.time_axis_tbl.hideColumn(label_col)

        hdr = self.ui.time_axis_tbl.horizontalHeader()
        hdr.setSectionResizeMode(QHeaderView.Stretch)
        del_col = self.axis_table_model.getColumnIndex("")
        hdr.setSectionResizeMode(del_col, QHeaderView.ResizeToContents)

        plot_viewbox = self.ui.main_plot.plotItem.vb
        plot_viewbox.sigXRangeChanged.connect(self.set_axis_datetimes)
        plot_viewbox.sigRangeChangedManually.connect(lambda *_: self.set_axis_datetimes())

        self.ui.main_start_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((qdt, None)))
        self.ui.main_end_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((None, qdt)))

        self.ui.add_axis_row_btn.clicked.connect(self.addAxis)

    def axis_delegates_init(self) -> None:
        """Initialize and set the ItemDelegates for the axis table."""
        orientation_col = self.axis_table_model.getColumnIndex("Y-Axis Orientation")
        orientation_map = {"Left": "left", "Right": "right"}
        orientation_del = ComboBoxDelegate(self.ui.time_axis_tbl, orientation_map)
        self.ui.time_axis_tbl.setItemDelegateForColumn(orientation_col, orientation_del)

        min_range_col = self.axis_table_model.getColumnIndex("Min Y Range")
        min_range_del = ScientificNotationDelegate(self.ui.time_axis_tbl)
        self.ui.time_axis_tbl.setItemDelegateForColumn(min_range_col, min_range_del)

        max_range_col = self.axis_table_model.getColumnIndex("Max Y Range")
        max_range_del = ScientificNotationDelegate(self.ui.time_axis_tbl)
        self.ui.time_axis_tbl.setItemDelegateForColumn(max_range_col, max_range_del)

        delete_col = self.axis_table_model.getColumnIndex("")
        delete_row_del = DeleteRowDelegate(self.ui.time_axis_tbl)
        self.ui.time_axis_tbl.setItemDelegateForColumn(delete_col, delete_row_del)

    @Slot(object)
    def set_time_axis_range(self, raw_range: Tuple[QDateTime, QDateTime] = (None, None)) -> None:
        """PyQT Slot to set the plot's X-Axis range. This slot should be
        triggered on QDateTimeEdit value change.

        Parameters
        ----------
        raw_range : Tuple[QDateTime], optional
            Takes in a tuple of 2 values, where one is a QDateTime and
            the other is None. The positioning changes either the plot's
            min or max range value. By default (None, None)
        """
        # Disable Autoscroll if enabled
        self.ui.cursor_scale_btn.click()

        proc_range = [None, None]
        for ind, val in enumerate(raw_range):
            # Values that are QDateTime are converted to a float timestamp
            if isinstance(val, QDateTime):
                proc_range[ind] = val.toSecsSinceEpoch()
            # Values that are None use the existing range value
            elif not val:
                proc_range[ind] = self.ui.main_plot.getXAxis().range[ind]
        proc_range.sort()

        logger.debug(f"Setting plot's X-Axis range to {proc_range}")
        self.ui.main_plot.plotItem.vb.blockSignals(True)
        self.ui.main_plot.plotItem.setXRange(*proc_range, padding=0)
        self.ui.main_plot.plotItem.vb.blockSignals(False)

    @Slot(object, object)
    def set_axis_datetimes(self, _: ViewBox = None, time_range: Tuple[float, float] = None) -> None:
        """Slot used to update the QDateTimeEdits on the Axis tab. This
        slot is called when the plot's X-Axis range changes values.

        Parameters
        ----------
        _ : ViewBox, optional
            The ViewBox on which the range is changing. This is unused
        time_range : Tuple[float, float], optional
            The new range values for the QDateTimeEdits, by default None
        """
        if not time_range:
            time_range = self.ui.main_plot.getXAxis().range
        if min(time_range) <= 0:
            return

        time_range = [datetime.fromtimestamp(f) for f in time_range]

        edits = (self.ui.main_start_datetime, self.ui.main_end_datetime)
        for ind, qdt in enumerate(edits):
            if qdt.hasFocus():
                continue
            qdt.blockSignals(True)
            qdt.setDateTime(QDateTime(time_range[ind]))
            qdt.blockSignals(False)

    @Slot()
    def addAxis(self) -> None:
        """Slot for button to add a new row to the axis table."""
        self.axis_table_model.append()

addAxis()

Slot for button to add a new row to the axis table.

Source code in trace/mixins/axis_table.py
114
115
116
117
@Slot()
def addAxis(self) -> None:
    """Slot for button to add a new row to the axis table."""
    self.axis_table_model.append()

axis_delegates_init()

Initialize and set the ItemDelegates for the axis table.

Source code in trace/mixins/axis_table.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def axis_delegates_init(self) -> None:
    """Initialize and set the ItemDelegates for the axis table."""
    orientation_col = self.axis_table_model.getColumnIndex("Y-Axis Orientation")
    orientation_map = {"Left": "left", "Right": "right"}
    orientation_del = ComboBoxDelegate(self.ui.time_axis_tbl, orientation_map)
    self.ui.time_axis_tbl.setItemDelegateForColumn(orientation_col, orientation_del)

    min_range_col = self.axis_table_model.getColumnIndex("Min Y Range")
    min_range_del = ScientificNotationDelegate(self.ui.time_axis_tbl)
    self.ui.time_axis_tbl.setItemDelegateForColumn(min_range_col, min_range_del)

    max_range_col = self.axis_table_model.getColumnIndex("Max Y Range")
    max_range_del = ScientificNotationDelegate(self.ui.time_axis_tbl)
    self.ui.time_axis_tbl.setItemDelegateForColumn(max_range_col, max_range_del)

    delete_col = self.axis_table_model.getColumnIndex("")
    delete_row_del = DeleteRowDelegate(self.ui.time_axis_tbl)
    self.ui.time_axis_tbl.setItemDelegateForColumn(delete_col, delete_row_del)

axis_table_init()

Initializer for the Axis Table Model and Table View.

Source code in trace/mixins/axis_table.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def axis_table_init(self) -> None:
    """Initializer for the Axis Table Model and Table View."""
    self.axis_table_model = ArchiverAxisModel(self.ui.main_plot, self)
    self.ui.time_axis_tbl.setModel(self.axis_table_model)

    label_col = self.axis_table_model.getColumnIndex("Y-Axis Label")
    self.ui.time_axis_tbl.hideColumn(label_col)

    hdr = self.ui.time_axis_tbl.horizontalHeader()
    hdr.setSectionResizeMode(QHeaderView.Stretch)
    del_col = self.axis_table_model.getColumnIndex("")
    hdr.setSectionResizeMode(del_col, QHeaderView.ResizeToContents)

    plot_viewbox = self.ui.main_plot.plotItem.vb
    plot_viewbox.sigXRangeChanged.connect(self.set_axis_datetimes)
    plot_viewbox.sigRangeChangedManually.connect(lambda *_: self.set_axis_datetimes())

    self.ui.main_start_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((qdt, None)))
    self.ui.main_end_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((None, qdt)))

    self.ui.add_axis_row_btn.clicked.connect(self.addAxis)

set_axis_datetimes(_=None, time_range=None)

Slot used to update the QDateTimeEdits on the Axis tab. This slot is called when the plot's X-Axis range changes values.

Parameters

_ : ViewBox, optional The ViewBox on which the range is changing. This is unused time_range : Tuple[float, float], optional The new range values for the QDateTimeEdits, by default None

Source code in trace/mixins/axis_table.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
@Slot(object, object)
def set_axis_datetimes(self, _: ViewBox = None, time_range: Tuple[float, float] = None) -> None:
    """Slot used to update the QDateTimeEdits on the Axis tab. This
    slot is called when the plot's X-Axis range changes values.

    Parameters
    ----------
    _ : ViewBox, optional
        The ViewBox on which the range is changing. This is unused
    time_range : Tuple[float, float], optional
        The new range values for the QDateTimeEdits, by default None
    """
    if not time_range:
        time_range = self.ui.main_plot.getXAxis().range
    if min(time_range) <= 0:
        return

    time_range = [datetime.fromtimestamp(f) for f in time_range]

    edits = (self.ui.main_start_datetime, self.ui.main_end_datetime)
    for ind, qdt in enumerate(edits):
        if qdt.hasFocus():
            continue
        qdt.blockSignals(True)
        qdt.setDateTime(QDateTime(time_range[ind]))
        qdt.blockSignals(False)

set_time_axis_range(raw_range=(None, None))

PyQT Slot to set the plot's X-Axis range. This slot should be triggered on QDateTimeEdit value change.

Parameters

raw_range : Tuple[QDateTime], optional Takes in a tuple of 2 values, where one is a QDateTime and the other is None. The positioning changes either the plot's min or max range value. By default (None, None)

Source code in trace/mixins/axis_table.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@Slot(object)
def set_time_axis_range(self, raw_range: Tuple[QDateTime, QDateTime] = (None, None)) -> None:
    """PyQT Slot to set the plot's X-Axis range. This slot should be
    triggered on QDateTimeEdit value change.

    Parameters
    ----------
    raw_range : Tuple[QDateTime], optional
        Takes in a tuple of 2 values, where one is a QDateTime and
        the other is None. The positioning changes either the plot's
        min or max range value. By default (None, None)
    """
    # Disable Autoscroll if enabled
    self.ui.cursor_scale_btn.click()

    proc_range = [None, None]
    for ind, val in enumerate(raw_range):
        # Values that are QDateTime are converted to a float timestamp
        if isinstance(val, QDateTime):
            proc_range[ind] = val.toSecsSinceEpoch()
        # Values that are None use the existing range value
        elif not val:
            proc_range[ind] = self.ui.main_plot.getXAxis().range[ind]
    proc_range.sort()

    logger.debug(f"Setting plot's X-Axis range to {proc_range}")
    self.ui.main_plot.plotItem.vb.blockSignals(True)
    self.ui.main_plot.plotItem.setXRange(*proc_range, padding=0)
    self.ui.main_plot.plotItem.vb.blockSignals(False)