From b58a098ed4afbe62721fd2bf8497f363deecbfa6 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Fri, 21 Mar 2025 15:04:32 +0100 Subject: [PATCH] fix(round_frame): RoundFrame removed from BECWidget inheritance --- bec_widgets/qt_utils/round_frame.py | 19 +++++++------------ .../widgets/plots_next_gen/plot_base.py | 2 +- tests/unit_tests/test_round_frame.py | 3 +-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/bec_widgets/qt_utils/round_frame.py b/bec_widgets/qt_utils/round_frame.py index 0f943f5e..03bf5920 100644 --- a/bec_widgets/qt_utils/round_frame.py +++ b/bec_widgets/qt_utils/round_frame.py @@ -2,11 +2,10 @@ import pyqtgraph as pg from qtpy.QtCore import Property from qtpy.QtWidgets import QApplication, QFrame, QHBoxLayout, QVBoxLayout, QWidget -from bec_widgets.utils.bec_widget import BECWidget from bec_widgets.widgets.utility.visual.dark_mode_button.dark_mode_button import DarkModeButton -class RoundedFrame(BECWidget, QFrame): +class RoundedFrame(QFrame): """ A custom QFrame with rounded corners and optional theme updates. The frame can contain any QWidget, however it is mainly designed to wrap PlotWidgets to provide a consistent look and feel with other BEC Widgets. @@ -17,15 +16,11 @@ class RoundedFrame(BECWidget, QFrame): parent=None, content_widget: QWidget = None, background_color: str = None, - theme_update: bool = True, radius: int = 10, - **kwargs, ): - super().__init__(**kwargs) QFrame.__init__(self, parent) self.background_color = background_color - self.theme_update = theme_update if background_color is None else False self._radius = radius # Apply rounded frame styling @@ -46,14 +41,14 @@ class RoundedFrame(BECWidget, QFrame): # Automatically apply initial styles to the GraphicalLayoutWidget if applicable self.apply_plot_widget_style() - self._connect_to_theme_change() - def apply_theme(self, theme: str): """ Apply the theme to the frame and its content if theme updates are enabled. """ - if not self.theme_update: - return + if self.content_widget is not None and isinstance( + self.content_widget, pg.GraphicsLayoutWidget + ): + self.content_widget.setBackground(self.background_color) # Update background color based on the theme if theme == "light": @@ -129,8 +124,8 @@ class ExampleApp(QWidget): # pragma: no cover plot2.plot_item = plot_item_2 # Wrap PlotWidgets in RoundedFrame - rounded_plot1 = RoundedFrame(content_widget=plot1, theme_update=True) - rounded_plot2 = RoundedFrame(content_widget=plot2, theme_update=True) + rounded_plot1 = RoundedFrame(parent=self, content_widget=plot1) + rounded_plot2 = RoundedFrame(parent=self, content_widget=plot2) # Add to layout layout.addWidget(dark_button) diff --git a/bec_widgets/widgets/plots_next_gen/plot_base.py b/bec_widgets/widgets/plots_next_gen/plot_base.py index bdf0bafa..edbb5847 100644 --- a/bec_widgets/widgets/plots_next_gen/plot_base.py +++ b/bec_widgets/widgets/plots_next_gen/plot_base.py @@ -130,7 +130,7 @@ class PlotBase(BECWidget, QWidget): def _init_ui(self): self.layout.addWidget(self.layout_manager) - self.round_plot_widget = RoundedFrame(content_widget=self.plot_widget, theme_update=True) + self.round_plot_widget = RoundedFrame(parent=self, content_widget=self.plot_widget) self.layout_manager.add_widget(self.round_plot_widget) self.layout_manager.add_widget_relative(self.fps_label, self.round_plot_widget, "top") diff --git a/tests/unit_tests/test_round_frame.py b/tests/unit_tests/test_round_frame.py index fbd1a1e0..0c3c50b0 100644 --- a/tests/unit_tests/test_round_frame.py +++ b/tests/unit_tests/test_round_frame.py @@ -24,7 +24,7 @@ def basic_rounded_frame(qtbot): def plot_rounded_frame(qtbot): plot_widget = pg.PlotWidget() plot_widget.plot([0, 1, 2], [2, 1, 0]) - frame = RoundedFrame(content_widget=plot_widget, theme_update=True) + frame = RoundedFrame(content_widget=plot_widget) qtbot.addWidget(frame) qtbot.waitExposed(frame) yield frame @@ -35,7 +35,6 @@ def test_basic_rounded_frame_initialization(basic_rounded_frame): assert basic_rounded_frame.radius == 10 assert basic_rounded_frame.content_widget is None assert basic_rounded_frame.background_color is None - assert basic_rounded_frame.theme_update is True def test_set_radius(basic_rounded_frame):