fix(bec_widgets): adapt to bec_qthemes 1.0; themes can be only applied on living Qt objects

This commit is contained in:
2025-08-19 10:50:56 +02:00
parent d25314e6ee
commit b0cd619d7d
44 changed files with 164 additions and 277 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

+7
View File
@@ -8,6 +8,7 @@ from bec_lib import messages
from bec_lib.messages import _StoredDataInfo
from bec_qthemes import apply_theme
from pytestqt.exceptions import TimeoutError as QtBotTimeoutError
from qtpy.QtCore import QEvent, QEventLoop
from qtpy.QtWidgets import QApplication, QMessageBox
from bec_widgets.cli.rpc.rpc_register import RPCRegister
@@ -24,9 +25,15 @@ def pytest_runtest_makereport(item, call):
item.stash["failed"] = rep.failed
def process_all_deferred_deletes(qapp):
qapp.sendPostedEvents(None, QEvent.DeferredDelete)
qapp.processEvents(QEventLoop.AllEvents)
@pytest.fixture(autouse=True)
def qapplication(qtbot, request, testable_qtimer_class): # pylint: disable=unused-argument
qapp = QApplication.instance()
process_all_deferred_deletes(qapp)
apply_theme("light")
qapp.processEvents()
-4
View File
@@ -17,10 +17,6 @@ def abort_button(qtbot, mocked_client):
def test_abort_button(abort_button):
assert abort_button.button.text() == "Abort"
assert (
abort_button.button.styleSheet()
== "background-color: #666666; color: white; font-weight: bold; font-size: 12px;"
)
abort_button.button.click()
assert abort_button.queue.request_scan_abortion.called
abort_button.close()
+13
View File
@@ -144,6 +144,19 @@ class ExamplePlotWidget(BECWidget, QWidget):
self.glw.addItem(self.pi)
self.pi.plot([1, 2, 3, 4, 5], pen="r")
def cleanup_pyqtgraph(self, item: pg.PlotItem | None = None):
"""Cleanup pyqtgraph items."""
if item is None:
item = self.pi
item.vb.menu.close()
item.vb.menu.deleteLater()
item.ctrlMenu.close()
item.ctrlMenu.deleteLater()
def cleanup(self):
self.cleanup_pyqtgraph()
super().cleanup()
def test_apply_theme(qtbot, mocked_client):
widget = create_widget(qtbot, ExamplePlotWidget, client=mocked_client)
-12
View File
@@ -42,18 +42,6 @@ def test_set_radius(basic_rounded_frame):
assert basic_rounded_frame.radius == 20
def test_apply_theme_light(plot_rounded_frame):
plot_rounded_frame.apply_theme("light")
assert plot_rounded_frame.background_color == "#e9ecef"
def test_apply_theme_dark(plot_rounded_frame):
plot_rounded_frame.apply_theme("dark")
assert plot_rounded_frame.background_color == "#141414"
def test_apply_plot_widget_style(plot_rounded_frame):
# Verify that a PlotWidget can have its style applied
plot_rounded_frame.apply_plot_widget_style(border="1px solid red")