1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-04 16:02:51 +01:00

fix(device-manager-display-widget): fix error message popup on cancelling upload

This commit is contained in:
2026-01-16 17:48:18 +01:00
committed by Christian Appel
parent 58e57169e8
commit 53fe1ac63d
3 changed files with 33 additions and 33 deletions

View File

@@ -231,8 +231,9 @@ class DeviceManagerDisplayWidget(DockAreaWidget):
# Build dock layout using shared helpers
self._build_docks()
logger.info("Connecting application about to quit signal to device manager view...")
QApplication.instance().aboutToQuit.connect(self._about_to_quit_handler)
# TODO Implement once issue #1012 is solved
# logger.info("Connecting application about to quit signal to device manager view...")
# QApplication.instance().aboutToQuit.connect(self._about_to_quit_handler)
##############################
### Custom set busy widget ###
@@ -248,16 +249,17 @@ class DeviceManagerDisplayWidget(DockAreaWidget):
### Application quit handler ###
################################
@SafeSlot()
def _about_to_quit_handler(self):
"""Handle application about to quit event. If config upload is active, cancel it."""
logger.info("Application is quitting, checking for active config upload...")
if self._config_upload_active:
logger.info("Application is quitting, cancelling active config upload...")
self._config_helper.send_config_request(
action="cancel", config=None, wait_for_response=True, timeout_s=10
)
logger.info("Config upload cancelled.")
# TODO Implement once issue #1012 is solved
# @SafeSlot()
# def _about_to_quit_handler(self):
# """Handle application about to quit event. If config upload is active, cancel it."""
# logger.info("Application is quitting, checking for active config upload...")
# if self._config_upload_active:
# logger.info("Application is quitting, cancelling active config upload...")
# self._config_helper.send_config_request(
# action="cancel", config=None, wait_for_response=True, timeout_s=10
# )
# logger.info("Config upload cancelled.")
def _set_busy_wrapper(self, enabled: bool):
"""Thin wrapper around set_busy to flip the state variable."""
@@ -669,7 +671,6 @@ class DeviceManagerDisplayWidget(DockAreaWidget):
def _handle_cancel_config_upload_failed(self, exception: Exception):
"""Handle failure to cancel the config upload."""
QMessageBox.critical(self, "Error Cancelling Upload", f"{str(exception)}")
self._set_busy_wrapper(enabled=False)
validation_results = self.device_table_view.get_validation_results()

View File

@@ -47,7 +47,7 @@ def test_becwidget_start_busy_shows_overlay(qtbot, widget_busy):
def test_becwidget_set_busy_toggle_and_text(qtbot, widget_idle):
overlay = getattr(widget_idle, "_busy_overlay", None)
assert overlay is None, "Overlay should be lazily created when idle"
assert overlay is not None
widget_idle.set_busy(True)
overlay = getattr(widget_idle, "_busy_overlay")
@@ -120,7 +120,6 @@ def test_becwidget_overlay_frame_geometry_and_style(qtbot, widget_busy):
ss = frame.styleSheet()
assert "dashed" in ss
assert "border" in ss
assert "rgba(128, 128, 128, 110)" in ss
def test_becwidget_busy_cycle_start_on_off_on(qtbot, widget_busy):

View File

@@ -20,10 +20,13 @@ def progress_bar(qtbot, mocked_client):
def test_progress_bar_initialization(progress_bar):
"""Test the initial state of the DeviceInitializationProgressBar."""
assert progress_bar.failed_devices == []
assert progress_bar._user_value == 0
assert progress_bar._user_maximum == 1
assert progress_bar.progress_bar._user_value == 0
assert progress_bar.progress_bar._user_maximum == 100
assert progress_bar.toolTip() == "No device initialization failures."
assert progress_bar.progress_label.text() == "Initializing devices..."
assert progress_bar.group_box.title() == "Config Update Progress"
def test_update_device_initialization_progress(progress_bar, qtbot):
"""Test updating the progress bar with different device initialization messages."""
@@ -34,22 +37,19 @@ def test_update_device_initialization_progress(progress_bar, qtbot):
)
progress_bar._update_device_initialization_progress(msg.model_dump(), {})
assert progress_bar._user_value == 1
assert progress_bar._user_maximum == 3
assert (
f"Device initialization for '{msg.device}' is in progress..."
in progress_bar.center_label.text()
)
assert progress_bar.progress_bar._user_value == 1
assert progress_bar.progress_bar._user_maximum == 3
assert progress_bar.progress_label.text() == f"{msg.device} initialization in progress..."
assert "1 / 3 - 33 %" == progress_bar.progress_bar.center_label.text()
# II. Update with message of finished DeviceInitializationProgressMessage, finished=True, success=True
msg.finished = True
msg.success = True
progress_bar._update_device_initialization_progress(msg.model_dump(), {})
assert progress_bar._user_value == 1
assert progress_bar._user_maximum == 3
assert (
f"Device initialization for '{msg.device}' succeeded!" in progress_bar.center_label.text()
)
assert progress_bar.progress_bar._user_value == 1
assert progress_bar.progress_bar._user_maximum == 3
assert progress_bar.progress_label.text() == f"{msg.device} initialization succeeded!"
assert "1 / 3 - 33 %" == progress_bar.progress_bar.center_label.text()
# III. Update with message of finished DeviceInitializationProgressMessage, finished=True, success=False
msg.finished = True
@@ -58,11 +58,11 @@ def test_update_device_initialization_progress(progress_bar, qtbot):
msg.index = 2
with qtbot.waitSignal(progress_bar.failed_devices_changed) as signal_blocker:
progress_bar._update_device_initialization_progress(msg.model_dump(), {})
assert progress_bar._user_value == 2
assert progress_bar._user_maximum == 3
assert (
f"Device initialization for '{msg.device}' failed!" in progress_bar.center_label.text()
)
assert progress_bar.progress_label.text() == f"{msg.device} initialization failed!"
assert "2 / 3 - 66 %" == progress_bar.progress_bar.center_label.text()
assert progress_bar.progress_bar._user_value == 2
assert progress_bar.progress_bar._user_maximum == 3
assert signal_blocker.args == [[msg.device]]
assert progress_bar.toolTip() == f"Failed devices: {msg.device}"