mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-11-10 03:24:06 +01:00
refactor(busy_loader): share BusyStateWidget and build CustomBusyWidget on it
This commit is contained in:
5 files changed
+119
-119
No files matched your search
@@ -4,6 +4,7 @@ from qtpy.QtWidgets import QLabel, QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets import BECWidget
|
||||
from bec_widgets.tests.client_mocks import mocked_client
|
||||
from bec_widgets.utils.busy_loader import BusyStateWidget
|
||||
from bec_widgets.widgets.utility.spinner.spinner import SpinnerWidget
|
||||
|
||||
|
||||
@@ -139,3 +140,29 @@ def test_becwidget_busy_cycle_start_on_off_on(qtbot, widget_busy):
|
||||
|
||||
# Geometry follows parent after re-show
|
||||
qtbot.waitUntil(lambda: overlay.geometry() == widget_busy.rect())
|
||||
|
||||
|
||||
def test_becwidget_default_busy_state_widget(widget_idle):
|
||||
assert isinstance(widget_idle._busy_state_widget, BusyStateWidget)
|
||||
assert widget_idle._busy_state_widget.label.text() == "Loading..."
|
||||
|
||||
|
||||
def test_busy_state_widget_without_text_hides_label(qtbot):
|
||||
widget = BusyStateWidget(text=None, spinner_size=32)
|
||||
qtbot.addWidget(widget)
|
||||
assert widget.label.isHidden()
|
||||
assert widget.spinner.width() == 32
|
||||
assert widget.spinner.height() == 32
|
||||
|
||||
|
||||
def test_busy_state_widget_spinner_runs_only_while_visible(qtbot):
|
||||
widget = BusyStateWidget()
|
||||
qtbot.addWidget(widget)
|
||||
assert widget.spinner._started is False
|
||||
|
||||
widget.show()
|
||||
qtbot.waitExposed(widget)
|
||||
assert widget.spinner._started is True
|
||||
|
||||
widget.hide()
|
||||
assert widget.spinner._started is False
|
||||
@@ -31,7 +31,7 @@ from bec_widgets.applications.views.device_manager_view.device_manager_view impo
|
||||
DeviceManagerWidget,
|
||||
)
|
||||
from bec_widgets.tests.client_mocks import mocked_client
|
||||
from bec_widgets.utils.colors import get_accent_colors
|
||||
from bec_widgets.utils.busy_loader import BusyStateWidget
|
||||
from bec_widgets.widgets.control.device_manager.components import (
|
||||
DeviceTable,
|
||||
DMConfigView,
|
||||
@@ -644,17 +644,21 @@ class TestDeviceManagerView:
|
||||
def test_custom_busy_widget(self, custom_busy: CustomBusyWidget, qtbot):
|
||||
"""Test the CustomBusyWidget functionality."""
|
||||
|
||||
# Check layout
|
||||
# Check layout: shared busy state spinner, no message, progress card and cancel button
|
||||
assert isinstance(custom_busy, BusyStateWidget)
|
||||
assert custom_busy.progress is not None
|
||||
assert custom_busy.spinner is not None
|
||||
assert custom_busy.spinner._started is False
|
||||
assert custom_busy.label.isHidden()
|
||||
layout = custom_busy.content_layout
|
||||
assert layout.indexOf(custom_busy.spinner) < layout.indexOf(custom_busy.progress)
|
||||
assert layout.indexOf(custom_busy.progress) < layout.indexOf(custom_busy.cancel_button)
|
||||
|
||||
# Check background
|
||||
color = get_accent_colors()
|
||||
bg = color._colors["BG"]
|
||||
sheet = custom_busy.styleSheet()
|
||||
assert bg.name() in sheet
|
||||
assert "border-radius: 12px" in sheet
|
||||
# The card background is scoped to the progress card and follows the theme palette
|
||||
sheet = custom_busy.progress.styleSheet()
|
||||
assert "#busyProgressCard" in sheet
|
||||
assert "palette(window)" in sheet
|
||||
assert custom_busy.styleSheet() == ""
|
||||
|
||||
# Show event should start spinner
|
||||
custom_busy.showEvent(None)
|
||||
|
||||
Reference in new issue
Block a user