From 8842eb617ace86e0a5d32f54f87ba38523c36754 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 20 Nov 2025 15:33:41 +0100 Subject: [PATCH] fix(widgets): removed isVisible from all SafeProperties --- bec_widgets/utils/compact_popup.py | 4 ++- .../positioner_box/positioner_box.py | 4 ++- .../positioner_box_2d/positioner_box_2d.py | 8 +++-- .../control/scan_control/scan_control.py | 31 ++++++++++++------- .../widgets/dap/lmfit_dialog/lmfit_dialog.py | 12 +++++-- .../editors/scan_metadata/scan_metadata.py | 4 ++- bec_widgets/widgets/plots/plot_base.py | 25 +++++++++++---- .../scan_progressbar/scan_progressbar.py | 12 +++++-- .../widgets/services/bec_queue/bec_queue.py | 4 ++- 9 files changed, 74 insertions(+), 30 deletions(-) diff --git a/bec_widgets/utils/compact_popup.py b/bec_widgets/utils/compact_popup.py index 8d4daef2..af8b48a2 100644 --- a/bec_widgets/utils/compact_popup.py +++ b/bec_widgets/utils/compact_popup.py @@ -144,6 +144,7 @@ class CompactPopupWidget(QWidget): self.container.setVisible(True) layout(self.container) self.layout = self.container.layout() + self._compact_view = False self.compact_show_popup.clicked.connect(self.show_popup) @@ -210,7 +211,7 @@ class CompactPopupWidget(QWidget): @Property(bool) def compact_view(self): - return self.compact_label.isVisible() + return self._compact_view @compact_view.setter def compact_view(self, set_compact: bool): @@ -220,6 +221,7 @@ class CompactPopupWidget(QWidget): the full view is displayed. This is handled by toggling visibility of the container widget or the compact view widget. """ + self._compact_view = set_compact if set_compact: self.compact_view_widget.setVisible(True) self.container.setVisible(False) diff --git a/bec_widgets/widgets/control/device_control/positioner_box/positioner_box/positioner_box.py b/bec_widgets/widgets/control/device_control/positioner_box/positioner_box/positioner_box.py index a573623e..28d77999 100644 --- a/bec_widgets/widgets/control/device_control/positioner_box/positioner_box/positioner_box.py +++ b/bec_widgets/widgets/control/device_control/positioner_box/positioner_box/positioner_box.py @@ -49,6 +49,7 @@ class PositionerBox(PositionerBoxBase): self._device = "" self._limits = None + self._hide_device_selection = False if self.current_path == "": self.current_path = os.path.dirname(__file__) @@ -114,11 +115,12 @@ class PositionerBox(PositionerBoxBase): @SafeProperty(bool) def hide_device_selection(self): """Hide the device selection""" - return not self.ui.tool_button.isVisible() + return self._hide_device_selection @hide_device_selection.setter def hide_device_selection(self, value: bool): """Set the device selection visibility""" + self._hide_device_selection = value self.ui.tool_button.setVisible(not value) @SafeSlot(bool) diff --git a/bec_widgets/widgets/control/device_control/positioner_box/positioner_box_2d/positioner_box_2d.py b/bec_widgets/widgets/control/device_control/positioner_box/positioner_box_2d/positioner_box_2d.py index 298a2f07..689c0514 100644 --- a/bec_widgets/widgets/control/device_control/positioner_box/positioner_box_2d/positioner_box_2d.py +++ b/bec_widgets/widgets/control/device_control/positioner_box/positioner_box_2d/positioner_box_2d.py @@ -73,6 +73,8 @@ class PositionerBox2D(PositionerBoxBase): self._limits_hor = None self._limits_ver = None self._dialog = None + self._hide_device_selection = False + self._hide_device_boxes = False self._enable_controls_hor = True self._enable_controls_ver = True if self.current_path == "": @@ -225,22 +227,24 @@ class PositionerBox2D(PositionerBoxBase): @SafeProperty(bool) def hide_device_selection(self): """Hide the device selection""" - return not self.ui.tool_button_hor.isVisible() + return self._hide_device_selection @hide_device_selection.setter def hide_device_selection(self, value: bool): """Set the device selection visibility""" + self._hide_device_selection = value self.ui.tool_button_hor.setVisible(not value) self.ui.tool_button_ver.setVisible(not value) @SafeProperty(bool) def hide_device_boxes(self): """Hide the device selection""" - return not self.ui.device_box_hor.isVisible() + return self._hide_device_boxes @hide_device_boxes.setter def hide_device_boxes(self, value: bool): """Set the device selection visibility""" + self._hide_device_boxes = value self.ui.device_box_hor.setVisible(not value) self.ui.device_box_ver.setVisible(not value) diff --git a/bec_widgets/widgets/control/scan_control/scan_control.py b/bec_widgets/widgets/control/scan_control/scan_control.py index 6bbef6e0..f1ef4b2b 100644 --- a/bec_widgets/widgets/control/scan_control/scan_control.py +++ b/bec_widgets/widgets/control/scan_control/scan_control.py @@ -91,6 +91,11 @@ class ScanControl(BECWidget, QWidget): self._scan_metadata: dict | None = None self._metadata_form = ScanMetadata(parent=self) + self._hide_arg_box = False + self._hide_kwarg_boxes = False + self._hide_scan_control_buttons = False + self._hide_metadata = False + self._hide_scan_selection_combobox = False # Create and set main layout self._init_UI() @@ -262,9 +267,7 @@ class ScanControl(BECWidget, QWidget): @SafeProperty(bool) def hide_arg_box(self): """Property to hide the argument box.""" - if self.arg_box is None: - return True - return not self.arg_box.isVisible() + return self._hide_arg_box @hide_arg_box.setter def hide_arg_box(self, hide: bool): @@ -273,18 +276,14 @@ class ScanControl(BECWidget, QWidget): Args: hide(bool): Hide or show the argument box. """ + self._hide_arg_box = hide if self.arg_box is not None: self.arg_box.setVisible(not hide) @SafeProperty(bool) def hide_kwarg_boxes(self): """Property to hide the keyword argument boxes.""" - if len(self.kwarg_boxes) == 0: - return True - - for box in self.kwarg_boxes: - if box is not None: - return not box.isVisible() + return self._hide_kwarg_boxes @hide_kwarg_boxes.setter def hide_kwarg_boxes(self, hide: bool): @@ -293,6 +292,7 @@ class ScanControl(BECWidget, QWidget): Args: hide(bool): Hide or show the keyword argument boxes. """ + self._hide_kwarg_boxes = hide if len(self.kwarg_boxes) > 0: for box in self.kwarg_boxes: box.setVisible(not hide) @@ -300,7 +300,7 @@ class ScanControl(BECWidget, QWidget): @SafeProperty(bool) def hide_scan_control_buttons(self): """Property to hide the scan control buttons.""" - return not self.button_run_scan.isVisible() + return self._hide_scan_control_buttons @hide_scan_control_buttons.setter def hide_scan_control_buttons(self, hide: bool): @@ -309,12 +309,13 @@ class ScanControl(BECWidget, QWidget): Args: hide(bool): Hide or show the scan control buttons. """ + self._hide_scan_control_buttons = hide self.show_scan_control_buttons(not hide) @SafeProperty(bool) def hide_metadata(self): """Property to hide the metadata form.""" - return not self._metadata_form.isVisible() + return self._hide_metadata @hide_metadata.setter def hide_metadata(self, hide: bool): @@ -323,6 +324,7 @@ class ScanControl(BECWidget, QWidget): Args: hide(bool): Hide or show the metadata form. """ + self._hide_metadata = hide self._metadata_form.setVisible(not hide) @SafeProperty(bool) @@ -342,12 +344,13 @@ class ScanControl(BECWidget, QWidget): @SafeSlot(bool) def show_scan_control_buttons(self, show: bool): """Shows or hides the scan control buttons.""" + self._hide_scan_control_buttons = not show self.scan_control_group.setVisible(show) @SafeProperty(bool) def hide_scan_selection_combobox(self): """Property to hide the scan selection combobox.""" - return not self.comboBox_scan_selection.isVisible() + return self._hide_scan_selection_combobox @hide_scan_selection_combobox.setter def hide_scan_selection_combobox(self, hide: bool): @@ -356,11 +359,13 @@ class ScanControl(BECWidget, QWidget): Args: hide(bool): Hide or show the scan selection combobox. """ + self._hide_scan_selection_combobox = hide self.show_scan_selection_combobox(not hide) @SafeSlot(bool) def show_scan_selection_combobox(self, show: bool): """Shows or hides the scan selection combobox.""" + self._hide_scan_selection_combobox = not show self.scan_selection_group.setVisible(show) @SafeSlot(str) @@ -415,6 +420,7 @@ class ScanControl(BECWidget, QWidget): box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.layout.insertWidget(position + len(self.kwarg_boxes), box) self.kwarg_boxes.append(box) + box.setVisible(not self._hide_kwarg_boxes) def add_arg_group(self, group: dict): """ @@ -427,6 +433,7 @@ class ScanControl(BECWidget, QWidget): self.arg_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.arg_box.hide_add_remove_buttons = self._hide_add_remove_buttons self.layout.insertWidget(self.ARG_BOX_POSITION, self.arg_box) + self.arg_box.setVisible(not self._hide_arg_box) @SafeSlot(str) def emit_device_selected(self, dev_names): diff --git a/bec_widgets/widgets/dap/lmfit_dialog/lmfit_dialog.py b/bec_widgets/widgets/dap/lmfit_dialog/lmfit_dialog.py index 05a5623c..68870b60 100644 --- a/bec_widgets/widgets/dap/lmfit_dialog/lmfit_dialog.py +++ b/bec_widgets/widgets/dap/lmfit_dialog/lmfit_dialog.py @@ -65,6 +65,9 @@ class LMFitDialog(BECWidget, QWidget): self._move_buttons = [] self._accent_colors = get_accent_colors() self.action_buttons = {} + self._hide_curve_selection = False + self._hide_summary = False + self._hide_parameters = False @property def enable_actions(self) -> bool: @@ -108,7 +111,7 @@ class LMFitDialog(BECWidget, QWidget): @SafeProperty(bool) def hide_curve_selection(self): """SafeProperty for showing the curve selection.""" - return not self.ui.group_curve_selection.isVisible() + return self._hide_curve_selection @hide_curve_selection.setter def hide_curve_selection(self, show: bool): @@ -117,12 +120,13 @@ class LMFitDialog(BECWidget, QWidget): Args: show (bool): Whether to show the curve selection. """ + self._hide_curve_selection = show self.ui.group_curve_selection.setVisible(not show) @SafeProperty(bool) def hide_summary(self) -> bool: """SafeProperty for showing the summary.""" - return not self.ui.group_summary.isVisible() + return self._hide_summary @hide_summary.setter def hide_summary(self, show: bool): @@ -131,12 +135,13 @@ class LMFitDialog(BECWidget, QWidget): Args: show (bool): Whether to show the summary. """ + self._hide_summary = show self.ui.group_summary.setVisible(not show) @SafeProperty(bool) def hide_parameters(self) -> bool: """SafeProperty for showing the parameters.""" - return not self.ui.group_parameters.isVisible() + return self._hide_parameters @hide_parameters.setter def hide_parameters(self, show: bool): @@ -145,6 +150,7 @@ class LMFitDialog(BECWidget, QWidget): Args: show (bool): Whether to show the parameters. """ + self._hide_parameters = show self.ui.group_parameters.setVisible(not show) @property diff --git a/bec_widgets/widgets/editors/scan_metadata/scan_metadata.py b/bec_widgets/widgets/editors/scan_metadata/scan_metadata.py index bd75081d..5df774f0 100644 --- a/bec_widgets/widgets/editors/scan_metadata/scan_metadata.py +++ b/bec_widgets/widgets/editors/scan_metadata/scan_metadata.py @@ -49,6 +49,7 @@ class ScanMetadata(PydanticModelForm): self._scan_name = scan_name or "" self._md_schema = get_metadata_schema_for_scan(self._scan_name) self._additional_metadata.data_changed.connect(self.validate_form) + self._hide_optional_metadata = False super().__init__(parent=parent, data_model=self._md_schema, client=client, **kwargs) @@ -63,7 +64,7 @@ class ScanMetadata(PydanticModelForm): @SafeProperty(bool) def hide_optional_metadata(self): # type: ignore """Property to hide the optional metadata table.""" - return not self._additional_md_box.isVisible() + return self._hide_optional_metadata @hide_optional_metadata.setter def hide_optional_metadata(self, hide: bool): @@ -72,6 +73,7 @@ class ScanMetadata(PydanticModelForm): Args: hide(bool): Hide or show the optional metadata table. """ + self._hide_optional_metadata = hide self._additional_md_box.setVisible(not hide) def get_form_data(self): diff --git a/bec_widgets/widgets/plots/plot_base.py b/bec_widgets/widgets/plots/plot_base.py index 823ac6de..908a16dd 100644 --- a/bec_widgets/widgets/plots/plot_base.py +++ b/bec_widgets/widgets/plots/plot_base.py @@ -173,6 +173,12 @@ class PlotBase(BECWidget, QWidget): self.tick_item = BECTickItem(parent=self, plot_item=self.plot_item) self.arrow_item = BECArrowItem(parent=self, plot_item=self.plot_item) + # Visibility States + self._toolbar_visible = True + self._enable_fps_monitor = False + self._outer_axes_visible = self.plot_item.getAxis("top").isVisible() + self._inner_axes_visible = self.plot_item.getAxis("bottom").isVisible() + self.toolbar = ModularToolBar(parent=self, orientation="horizontal") self._init_toolbar() @@ -338,7 +344,7 @@ class PlotBase(BECWidget, QWidget): """ Show Toolbar. """ - return self.toolbar.isVisible() + return self._toolbar_visible @enable_toolbar.setter def enable_toolbar(self, value: bool): @@ -348,6 +354,7 @@ class PlotBase(BECWidget, QWidget): Args: value(bool): The value to set. """ + self._toolbar_visible = value self.toolbar.setVisible(value) @SafeProperty(bool, doc="Enable the FPS monitor.") @@ -355,7 +362,7 @@ class PlotBase(BECWidget, QWidget): """ Enable the FPS monitor. """ - return self.fps_label.isVisible() + return self._enable_fps_monitor @enable_fps_monitor.setter def enable_fps_monitor(self, value: bool): @@ -365,9 +372,11 @@ class PlotBase(BECWidget, QWidget): Args: value(bool): The value to set. """ - if value and self.fps_monitor is None: + if value == self._enable_fps_monitor: + return + if value: self.hook_fps_monitor() - elif not value and self.fps_monitor is not None: + else: self.unhook_fps_monitor() ################################################################################ @@ -840,7 +849,7 @@ class PlotBase(BECWidget, QWidget): """ Show the outer axes of the plot widget. """ - return self.plot_item.getAxis("top").isVisible() + return self._outer_axes_visible @outer_axes.setter def outer_axes(self, value: bool): @@ -853,6 +862,7 @@ class PlotBase(BECWidget, QWidget): self.plot_item.showAxis("top", value) self.plot_item.showAxis("right", value) + self._outer_axes_visible = value self.property_changed.emit("outer_axes", value) @SafeProperty(bool, doc="Show inner axes of the plot widget.") @@ -860,7 +870,7 @@ class PlotBase(BECWidget, QWidget): """ Show inner axes of the plot widget. """ - return self.plot_item.getAxis("bottom").isVisible() + return self._inner_axes_visible @inner_axes.setter def inner_axes(self, value: bool): @@ -873,6 +883,7 @@ class PlotBase(BECWidget, QWidget): self.plot_item.showAxis("bottom", value) self.plot_item.showAxis("left", value) + self._inner_axes_visible = value self._apply_x_label() self._apply_y_label() self.property_changed.emit("inner_axes", value) @@ -1047,6 +1058,7 @@ class PlotBase(BECWidget, QWidget): self.fps_monitor.sigFpsUpdate.connect(self.update_fps_label) self.update_fps_label(0) + self._enable_fps_monitor = True def unhook_fps_monitor(self, delete_label=True): """Unhook the FPS monitor from the plot.""" @@ -1058,6 +1070,7 @@ class PlotBase(BECWidget, QWidget): if self.fps_label is not None: # Hide Label self.fps_label.hide() + self._enable_fps_monitor = False ################################################################################ # Crosshair diff --git a/bec_widgets/widgets/progress/scan_progressbar/scan_progressbar.py b/bec_widgets/widgets/progress/scan_progressbar/scan_progressbar.py index 2ebce2c8..2fada11d 100644 --- a/bec_widgets/widgets/progress/scan_progressbar/scan_progressbar.py +++ b/bec_widgets/widgets/progress/scan_progressbar/scan_progressbar.py @@ -146,6 +146,9 @@ class ScanProgressBar(BECWidget, QWidget): self.layout.addWidget(self.ui) self.setLayout(self.layout) self.progressbar = self.ui.progressbar + self._show_elapsed_time = self.ui.elapsed_time_label.isVisible() + self._show_remaining_time = self.ui.remaining_time_label.isVisible() + self._show_source_label = self.ui.source_label.isVisible() self.connect_to_queue() self._progress_source = None @@ -222,30 +225,33 @@ class ScanProgressBar(BECWidget, QWidget): @SafeProperty(bool) def show_elapsed_time(self): - return self.ui.elapsed_time_label.isVisible() + return self._show_elapsed_time @show_elapsed_time.setter def show_elapsed_time(self, value): + self._show_elapsed_time = value self.ui.elapsed_time_label.setVisible(value) if hasattr(self.ui, "dash"): self.ui.dash.setVisible(value) @SafeProperty(bool) def show_remaining_time(self): - return self.ui.remaining_time_label.isVisible() + return self._show_remaining_time @show_remaining_time.setter def show_remaining_time(self, value): + self._show_remaining_time = value self.ui.remaining_time_label.setVisible(value) if hasattr(self.ui, "dash"): self.ui.dash.setVisible(value) @SafeProperty(bool) def show_source_label(self): - return self.ui.source_label.isVisible() + return self._show_source_label @show_source_label.setter def show_source_label(self, value): + self._show_source_label = value self.ui.source_label.setVisible(value) def update_labels(self): diff --git a/bec_widgets/widgets/services/bec_queue/bec_queue.py b/bec_widgets/widgets/services/bec_queue/bec_queue.py index b2dff0d7..6ad4c93f 100644 --- a/bec_widgets/widgets/services/bec_queue/bec_queue.py +++ b/bec_widgets/widgets/services/bec_queue/bec_queue.py @@ -52,6 +52,7 @@ class BECQueue(BECWidget, CompactPopupWidget): ) self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) + self._toolbar_hidden = False # Set up the toolbar self.set_toolbar() @@ -105,7 +106,7 @@ class BECQueue(BECWidget, CompactPopupWidget): @Property(bool) def hide_toolbar(self): """Property to hide the BEC Queue toolbar.""" - return not self.toolbar.isVisible() + return self._toolbar_hidden @hide_toolbar.setter def hide_toolbar(self, hide: bool): @@ -124,6 +125,7 @@ class BECQueue(BECWidget, CompactPopupWidget): Args: hide(bool): Whether to hide the toolbar. """ + self._toolbar_hidden = hide self.toolbar.setVisible(not hide) def refresh_queue(self):