diff --git a/trace/widgets/axis_settings.py b/trace/widgets/axis_settings.py index 036b417b..e5ef641d 100644 --- a/trace/widgets/axis_settings.py +++ b/trace/widgets/axis_settings.py @@ -31,13 +31,13 @@ def __init__(self, parent: QWidget, plot: PyDMArchiverTimePlot, axis: BasePlotAx log_checkbox = QCheckBox(self) log_checkbox.setChecked(self.axis.log_mode) - log_checkbox.checkStateChanged.connect(self.set_axis_log_mode) + log_checkbox.stateChanged.connect(self.set_axis_log_mode) log_mode_row = SettingsRowItem(self, "Log Mode", log_checkbox) main_layout.addLayout(log_mode_row) self.grid_checkbox = QCheckBox(self) self.grid_checkbox.setChecked(bool(self.axis.grid)) - self.grid_checkbox.checkStateChanged.connect(self.show_grid) + self.grid_checkbox.stateChanged.connect(self.show_grid) y_grid_row = SettingsRowItem(self, "Y Axis Gridline", self.grid_checkbox) main_layout.addLayout(y_grid_row) @@ -68,12 +68,16 @@ def set_axis_orientation(self, orientation: str): self.axis.show() @Slot(int) - def set_axis_log_mode(self, checked: int): - self.axis.log_mode = bool(checked) + @Slot(Qt.CheckState) + def set_axis_log_mode(self, state: int | Qt.CheckState): + checked = Qt.CheckState(state) == Qt.Checked + self.axis.log_mode = checked @Slot(int) - def show_grid(self, visible: int): - if not visible: + @Slot(Qt.CheckState) + def show_grid(self, state: int | Qt.CheckState): + checked = Qt.CheckState(state) == Qt.Checked + if not checked: self.axis.setGrid(False) else: try: diff --git a/trace/widgets/control_panel.py b/trace/widgets/control_panel.py index 77f7c14b..e9cdbcc7 100644 --- a/trace/widgets/control_panel.py +++ b/trace/widgets/control_panel.py @@ -2,7 +2,7 @@ import qtawesome as qta from qtpy import QtGui, QtCore, QtWidgets -from qtpy.QtCore import QTimer +from qtpy.QtCore import Qt, Slot, QTimer from services.theme_manager import Theme, IconColors, ThemeManager from pydm.widgets.baseplot import BasePlotAxisItem @@ -368,7 +368,7 @@ def __init__(self, plot_axis_item: BasePlotAxisItem, control_panel=None, theme_m layout.addLayout(self.bottom_settings_layout) self.auto_range_checkbox = QtWidgets.QCheckBox("Auto") self.auto_range_checkbox.setCheckState(QtCore.Qt.Checked if self.source.auto_range else QtCore.Qt.Unchecked) - self.auto_range_checkbox.checkStateChanged.connect(self.set_auto_range) + self.auto_range_checkbox.stateChanged.connect(self.set_auto_range) self.source.linkedView().sigRangeChangedManually.connect(self.disable_auto_range) self.bottom_settings_layout.addWidget(self.auto_range_checkbox) self.bottom_settings_layout.addWidget(QtWidgets.QLabel("min, max")) @@ -387,7 +387,7 @@ def __init__(self, plot_axis_item: BasePlotAxisItem, control_panel=None, theme_m self.active_toggle = ToggleSwitch("Active") self.active_toggle.setCheckState(QtCore.Qt.Checked if self.source.isVisible() else QtCore.Qt.Unchecked) - self.active_toggle.checkStateChanged.connect(self.set_active) + self.active_toggle.stateChanged.connect(self.set_active) self.header_layout.addWidget(self.active_toggle) self.placeholder = QtWidgets.QWidget(self) @@ -543,16 +543,19 @@ def toggle_expand(self): self.layout().itemAt(index).widget().show() self._expanded = not self._expanded - def set_active(self, state: QtCore.Qt.CheckState): - if state == QtCore.Qt.Unchecked: - self.source.hide() - else: - self.source.show() + @Slot(int) + @Slot(Qt.CheckState) + def set_active(self, state: int | Qt.CheckState): + checked = Qt.CheckState(state) == Qt.Checked + self.source.setVisible(checked) for i in range(1, self.layout().count()): self.layout().itemAt(i).widget().active_toggle.setCheckState(state) - def set_auto_range(self, state: QtCore.Qt.CheckState): - self.source.auto_range = state == QtCore.Qt.Checked + @Slot(int) + @Slot(Qt.CheckState) + def set_auto_range(self, state: int | Qt.CheckState): + checked = Qt.CheckState(state) == Qt.Checked + self.source.auto_range = checked def disable_auto_range(self): self.auto_range_checkbox.setCheckState(QtCore.Qt.Unchecked) @@ -753,7 +756,7 @@ def __init__( self.active_toggle = ToggleSwitch("Active", color=self.source.color_string) self.active_toggle.setCheckState(QtCore.Qt.Checked if self.source.isVisible() else QtCore.Qt.Unchecked) - self.active_toggle.checkStateChanged.connect(self.set_active) + self.active_toggle.stateChanged.connect(self.set_active) self.layout().addWidget(self.active_toggle) second_layout = QtWidgets.QVBoxLayout() @@ -878,11 +881,11 @@ def axis_item(self): parent = parent.parent() return parent - def set_active(self, state: QtCore.Qt.CheckState): - if state == QtCore.Qt.Unchecked: - self.source.hide() - else: - self.source.show() + @Slot(int) + @Slot(Qt.CheckState) + def set_active(self, state: int | Qt.CheckState): + checked = Qt.CheckState(state) == Qt.Checked + self.source.setVisible(checked) def update_live_icon(self, connected: bool) -> None: self.live_connection_status.setVisible(not connected) diff --git a/trace/widgets/curve_settings.py b/trace/widgets/curve_settings.py index c6bbd10b..6cb846d3 100644 --- a/trace/widgets/curve_settings.py +++ b/trace/widgets/curve_settings.py @@ -75,10 +75,10 @@ def __init__(self, parent: QWidget, plot: PyDMArchiverTimePlot, curve: TimePlotC width_row = SettingsRowItem(self, " Width", width_combo) main_layout.addLayout(width_row) - extention_option = QCheckBox(self) - extention_option.checkStateChanged.connect(lambda check: self.set_extension_option(bool(check))) - extention_option_row = SettingsRowItem(self, "Line Extention", extention_option) - main_layout.addLayout(extention_option_row) + extension_option = QCheckBox(self) + extension_option.stateChanged.connect(self.set_extension_option) + extension_option_row = SettingsRowItem(self, " Line Extension", extension_option) + main_layout.addLayout(extension_option_row) symbol_title_label = SettingsTitle(self, "Symbol") main_layout.addWidget(symbol_title_label) @@ -156,6 +156,16 @@ def set_curve_style(self, style: int) -> None: def set_curve_width(self, width: int) -> None: self.curve.lineWidth = width + @Slot(int) + @Slot(Qt.CheckState) + def set_extension_option(self, state: int | Qt.CheckState) -> None: + """Set the line extension based on the checkbox state.""" + enable = Qt.CheckState(state) == Qt.Checked + + self.curve.show_extension_line = enable + self.curve.getViewBox().addItem(self.curve._extension_line) + self.curve.redrawCurve() + @Slot(object) def set_symbol_shape(self, shape: str) -> None: self.curve.symbol = shape @@ -163,10 +173,3 @@ def set_symbol_shape(self, shape: str) -> None: @Slot(object) def set_symbol_size(self, size: int) -> None: self.curve.symbolSize = size - - @Slot(object) - def set_extension_option(self, enable: bool) -> None: - """Set the line extension based on the checkbox state.""" - self.curve.show_extension_line = enable - self.curve.getViewBox().addItem(self.curve._extension_line) - self.curve.redrawCurve() diff --git a/trace/widgets/plot_settings.py b/trace/widgets/plot_settings.py index 0d4b86b4..9aa56def 100644 --- a/trace/widgets/plot_settings.py +++ b/trace/widgets/plot_settings.py @@ -46,7 +46,7 @@ def __init__(self, parent: QWidget, plot: PyDMArchiverTimePlot): main_layout.addLayout(plot_title_row) self.legend_checkbox = QCheckBox(self) - self.legend_checkbox.checkStateChanged.connect(lambda check: self.plot.setShowLegend(bool(check))) + self.legend_checkbox.stateChanged.connect(self.set_show_legend) self.legend_checkbox.setChecked(True) # legend on by default legend_row = SettingsRowItem(self, "Show Legend", self.legend_checkbox) main_layout.addLayout(legend_row) @@ -81,7 +81,7 @@ def __init__(self, parent: QWidget, plot: PyDMArchiverTimePlot): main_layout.addLayout(end_dt_row) self.crosshair_checkbox = QCheckBox(self) - self.crosshair_checkbox.checkStateChanged.connect(lambda check: self.plot.enableCrosshair(check, 100, 100)) + self.crosshair_checkbox.stateChanged.connect(self.set_crosshair) crosshair_row = SettingsRowItem(self, "Show Crosshair", self.crosshair_checkbox) main_layout.addLayout(crosshair_row) @@ -101,12 +101,12 @@ def __init__(self, parent: QWidget, plot: PyDMArchiverTimePlot): main_layout.addLayout(axis_tick_font_size_row) self.x_grid_checkbox = QCheckBox(self) - self.x_grid_checkbox.checkStateChanged.connect(self.show_x_grid) + self.x_grid_checkbox.stateChanged.connect(self.show_x_grid) x_grid_row = SettingsRowItem(self, " X Axis Gridline", self.x_grid_checkbox) main_layout.addLayout(x_grid_row) self.y_grid_checkbox = QCheckBox(self) - self.y_grid_checkbox.checkStateChanged.connect(self.show_y_grid) + self.y_grid_checkbox.stateChanged.connect(self.show_y_grid) y_grid_row = SettingsRowItem(self, " All Y Axis Gridlines", self.y_grid_checkbox) main_layout.addLayout(y_grid_row) @@ -145,6 +145,12 @@ def show(self): self.move(global_pos) super().show() + @Slot(int) + @Slot(Qt.CheckState) + def set_show_legend(self, state: int | Qt.CheckState) -> None: + checked = Qt.CheckState(state) == Qt.Checked + self.plot.setShowLegend(checked) + @Slot(int) def set_axis_tick_font_size(self, size: int) -> None: font = QFont() @@ -185,6 +191,12 @@ def set_time_axis_range(self, raw_range: tuple[QDateTime, QDateTime] = (None, No self.plot.plotItem.setXRange(*proc_range, padding=0) self.plot.plotItem.vb.blockSignals(False) + @Slot(int) + @Slot(Qt.CheckState) + def set_crosshair(self, state: int | Qt.CheckState) -> None: + checked = Qt.CheckState(state) == Qt.Checked + self.plot.enableCrosshair(checked, 100, 100) + @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 @@ -213,14 +225,17 @@ def set_axis_datetimes(self, _: ViewBox = None, time_range: tuple[float, float] qdt.blockSignals(False) @Slot(int) - def show_x_grid(self, visible: int): + @Slot(Qt.CheckState) + def show_x_grid(self, state: int | Qt.CheckState) -> None: """Slot to show or hide the X-Axis gridlines.""" + visible = Qt.CheckState(state) == Qt.Checked opacity = self.gridline_opacity - self.set_plot_gridlines(bool(visible), opacity) + self.set_plot_gridlines(visible, opacity) @Slot(int) - def show_y_grid(self, visible: int): - visible = bool(visible) + @Slot(Qt.CheckState) + def show_y_grid(self, state: int | Qt.CheckState) -> None: + visible = Qt.CheckState(state) == Qt.Checked self.set_all_y_axis_gridlines.emit(visible) @Slot(int)