0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

refactor: add option to select scan and hide arg bundle buttons

This commit is contained in:
2024-08-28 21:32:46 +02:00
parent 664bbce01d
commit 7dadab1f14
2 changed files with 75 additions and 2 deletions

View File

@ -126,12 +126,43 @@ class ScanControl(BECWidget, QWidget):
selected_scan_name = self.comboBox_scan_selection.currentText() selected_scan_name = self.comboBox_scan_selection.currentText()
self.scan_selected.emit(selected_scan_name) self.scan_selected.emit(selected_scan_name)
@Property(str)
def current_scan(self):
"""Returns the scan name for the currently selected scan."""
return self.comboBox_scan_selection.currentText()
@current_scan.setter
def current_scan(self, scan_name: str):
"""Sets the current scan to the given scan name.
Args:
scan_name(str): Name of the scan to set as current.
"""
if scan_name not in self.available_scans:
return
self.comboBox_scan_selection.setCurrentText(scan_name)
@Slot(str)
def set_current_scan(self, scan_name: str):
"""Slot for setting the current scan to the given scan name.
Args:
scan_name(str): Name of the scan to set as current.
"""
self.current_scan = scan_name
@Property(bool) @Property(bool)
def hide_scan_control_buttons(self): def hide_scan_control_buttons(self):
"""Property to hide the scan control buttons."""
return not self.button_run_scan.isVisible() return not self.button_run_scan.isVisible()
@hide_scan_control_buttons.setter @hide_scan_control_buttons.setter
def hide_scan_control_buttons(self, hide: bool): def hide_scan_control_buttons(self, hide: bool):
"""Setter for the hide_scan_control_buttons property.
Args:
hide(bool): Hide or show the scan control buttons.
"""
self.show_scan_control_buttons(not hide) self.show_scan_control_buttons(not hide)
@Slot(bool) @Slot(bool)
@ -145,10 +176,16 @@ class ScanControl(BECWidget, QWidget):
@Property(bool) @Property(bool)
def hide_scan_selection_combobox(self): def hide_scan_selection_combobox(self):
"""Property to hide the scan selection combobox."""
return not self.comboBox_scan_selection.isVisible() return not self.comboBox_scan_selection.isVisible()
@hide_scan_selection_combobox.setter @hide_scan_selection_combobox.setter
def hide_scan_selection_combobox(self, hide: bool): def hide_scan_selection_combobox(self, hide: bool):
"""Setter for the hide_scan_selection_combobox property.
Args:
hide(bool): Hide or show the scan selection combobox.
"""
self.show_scan_selection_combobox(not hide) self.show_scan_selection_combobox(not hide)
@Slot(bool) @Slot(bool)
@ -176,8 +213,7 @@ class ScanControl(BECWidget, QWidget):
show_bundle_buttons = bool(self.arg_group["arg_inputs"]) show_bundle_buttons = bool(self.arg_group["arg_inputs"])
self.button_add_bundle.setVisible(show_bundle_buttons) self._show_bundle_buttons(show_bundle_buttons)
self.button_remove_bundle.setVisible(show_bundle_buttons)
if show_bundle_buttons: if show_bundle_buttons:
self.add_arg_group(self.arg_group) self.add_arg_group(self.arg_group)
@ -187,6 +223,29 @@ class ScanControl(BECWidget, QWidget):
self.update() self.update()
self.adjustSize() self.adjustSize()
def _show_bundle_buttons(self, show: bool):
"""Shows or hides the bundle buttons based on the show argument.
Args:
show(bool): Show or hide the bundle buttons.
"""
self.button_add_bundle.setVisible(show)
self.button_remove_bundle.setVisible(show)
@Property(bool)
def hide_bundle_buttons(self):
"""Property to hide the bundle buttons."""
return not self.button_add_bundle.isVisible()
@hide_bundle_buttons.setter
def hide_bundle_buttons(self, hide: bool):
"""Setter for the hide_bundle_buttons property.
Args:
hide(bool): Hide or show the bundle buttons.
"""
self._show_bundle_buttons(not hide)
def add_kwargs_boxes(self, groups: list): def add_kwargs_boxes(self, groups: list):
""" """
Adds the given gui_groups to the scan control layout. Adds the given gui_groups to the scan control layout.
@ -212,10 +271,12 @@ class ScanControl(BECWidget, QWidget):
@Slot() @Slot()
def add_arg_bundle(self): def add_arg_bundle(self):
"""Adds a new argument bundle to the scan control layout."""
self.arg_box.add_widget_bundle() self.arg_box.add_widget_bundle()
@Slot() @Slot()
def remove_arg_bundle(self): def remove_arg_bundle(self):
"""Removes the last argument bundle from the scan control layout."""
self.arg_box.remove_widget_bundle() self.arg_box.remove_widget_bundle()
def reset_layout(self): def reset_layout(self):
@ -235,6 +296,7 @@ class ScanControl(BECWidget, QWidget):
@Slot() @Slot()
def run_scan(self): def run_scan(self):
"""Starts the selected scan with the given parameters."""
self.scan_started.emit() self.scan_started.emit()
args = [] args = []
kwargs = {} kwargs = {}
@ -248,6 +310,7 @@ class ScanControl(BECWidget, QWidget):
scan_function(*args, **kwargs) scan_function(*args, **kwargs)
def cleanup(self): def cleanup(self):
"""Cleanup the scan control widget."""
self.button_stop_scan.cleanup() self.button_stop_scan.cleanup()
if self.arg_box: if self.arg_box:
for widget in self.arg_box.widgets: for widget in self.arg_box.widgets:

View File

@ -233,6 +233,16 @@ def test_populate_scans(scan_control, mocked_client):
assert sorted(items) == sorted(expected_scans) assert sorted(items) == sorted(expected_scans)
def test_current_scan(scan_control, mocked_client):
current_scan = scan_control.current_scan
wrong_scan = "error_scan"
scan_control.current_scan = wrong_scan
assert scan_control.current_scan == current_scan
new_scan = "grid_scan" if current_scan == "line_scan" else "line_scan"
scan_control.current_scan = new_scan
assert scan_control.current_scan == new_scan
@pytest.mark.parametrize("scan_name", ["line_scan", "grid_scan"]) @pytest.mark.parametrize("scan_name", ["line_scan", "grid_scan"])
def test_on_scan_selected(scan_control, scan_name): def test_on_scan_selected(scan_control, scan_name):
expected_scan_info = available_scans_message.resource[scan_name] expected_scan_info = available_scans_message.resource[scan_name]