From 66c0e4ecfcc9aa744660099f443762a824eab040 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 9 May 2024 23:50:18 +0200 Subject: [PATCH] feat(widgets/progressbar): pydantic config structure added + extended the setting -rebased --- .../jupyter_console/jupyter_console_window.py | 1 - bec_widgets/widgets/__init__.py | 1 - .../widgets/circular_progress_bar/__init__.py | 1 - .../spiral_progress_bar.py | 119 ------------------ 4 files changed, 122 deletions(-) delete mode 100644 bec_widgets/widgets/circular_progress_bar/__init__.py delete mode 100644 bec_widgets/widgets/circular_progress_bar/spiral_progress_bar.py diff --git a/bec_widgets/examples/jupyter_console/jupyter_console_window.py b/bec_widgets/examples/jupyter_console/jupyter_console_window.py index 0afea16b..ce27d21a 100644 --- a/bec_widgets/examples/jupyter_console/jupyter_console_window.py +++ b/bec_widgets/examples/jupyter_console/jupyter_console_window.py @@ -12,7 +12,6 @@ from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget from bec_widgets.cli.rpc_register import RPCRegister from bec_widgets.utils import BECDispatcher from bec_widgets.widgets import BECFigure -from bec_widgets.widgets.circular_progress_bar.spiral_progress_bar import SpiralProgressBar from bec_widgets.widgets.dock.dock_area import BECDockArea from bec_widgets.widgets.spiral_progress_bar.spiral_progress_bar import SpiralProgressBar diff --git a/bec_widgets/widgets/__init__.py b/bec_widgets/widgets/__init__.py index 971f7c31..5e041775 100644 --- a/bec_widgets/widgets/__init__.py +++ b/bec_widgets/widgets/__init__.py @@ -1,4 +1,3 @@ -from .circular_progress_bar import SpiralProgressBar from .dock import BECDock, BECDockArea from .figure import BECFigure, FigureConfig from .scan_control import ScanControl diff --git a/bec_widgets/widgets/circular_progress_bar/__init__.py b/bec_widgets/widgets/circular_progress_bar/__init__.py deleted file mode 100644 index 81ed0f36..00000000 --- a/bec_widgets/widgets/circular_progress_bar/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .spiral_progress_bar import SpiralProgressBar diff --git a/bec_widgets/widgets/circular_progress_bar/spiral_progress_bar.py b/bec_widgets/widgets/circular_progress_bar/spiral_progress_bar.py deleted file mode 100644 index 132b215f..00000000 --- a/bec_widgets/widgets/circular_progress_bar/spiral_progress_bar.py +++ /dev/null @@ -1,119 +0,0 @@ -from qtpy import QtCore, QtGui -from qtpy.QtWidgets import QWidget - -from bec_widgets.utils import BECConnector, Colors, ConnectionConfig - - -class SpiralProgressBar(BECConnector, QWidget): - USER_ACCESS = [ - "set_number_of_bars", - "set_value", - "set_colors_from_map", - "set_colors_directly", - "set_line_widths", - ] - - def __init__( - self, - parent=None, - config: ConnectionConfig | None = None, - client=None, - gui_id: str | None = None, - num_bars=3, - ): - if config is None: - config = ConnectionConfig(widget_class=self.__class__.__name__) - else: - if isinstance(config, dict): - config = ConnectionConfig(**config, widget_class=self.__class__.__name__) - self.config = config - super().__init__(client=client, config=config, gui_id=gui_id) - QWidget.__init__(self, parent=None) - - self.min_bars = 2 - self.max_values = 6 - self.num_bars = max(2, min(num_bars, 6)) - self.initialize_bars(self.num_bars) - - def initialize_bars(self, num_bars): - self.values = [0] * num_bars - self.min_values = [0] * num_bars - self.max_values = [100] * num_bars - self.start_positions = [90 * 16] * num_bars - self.directions = [-1] * num_bars - self.colors = [QtGui.QColor(0, 159, 227)] * num_bars - self.lineWidths = [5] * num_bars - self.backgroundColors = [QtGui.QColor(200, 200, 200, 50)] * num_bars - self.gap = 10 - self.update() - - def set_number_of_bars(self, num_bars): - num_bars = max(2, min(num_bars, 6)) - if num_bars != self.num_bars: - self.num_bars = num_bars - self.initialize_bars(num_bars) - - def set_value(self, values): - if len(values) != self.num_bars: - raise ValueError("Value length must match the number of progress bars.") - self.values = [ - max(min_val, min(max_val, val)) - for val, min_val, max_val in zip(values, self.min_values, self.max_values) - ] - self.update() - - def set_colors_from_map(self, colormap, format="QColor"): - self.colors = Colors.golden_angle_color(colormap, self.num_bars, format) - self.update() - - def set_colors_directly(self, colors): - if len(colors) != self.num_bars: - raise ValueError("Colors length must match the number of progress bars.") - self.colors = [] - for color in colors: - if isinstance(color, QtGui.QColor): - self.colors.append(color) - elif isinstance(color, str): - self.colors.append(QtGui.QColor(color)) - elif isinstance(color, tuple): - self.colors.append(QtGui.QColor(*color)) - self.update() - - def set_line_widths(self, widths): - if len(widths) != self.num_bars: - raise ValueError("Widths length must match the number of progress bars.") - self.lineWidths = widths - self.update() - - def paintEvent(self, event): - painter = QtGui.QPainter(self) - painter.setRenderHint(QtGui.QPainter.Antialiasing) - size = min(self.width(), self.height()) - rect = QtCore.QRect(0, 0, size, size) - rect.adjust( - max(self.lineWidths), max(self.lineWidths), -max(self.lineWidths), -max(self.lineWidths) - ) - - for i in range(self.num_bars): - # Background arc - painter.setPen( - QtGui.QPen(self.backgroundColors[i], self.lineWidths[i], QtCore.Qt.SolidLine) - ) - offset = self.gap * i - adjusted_rect = QtCore.QRect( - rect.left() + offset, - rect.top() + offset, - rect.width() - 2 * offset, - rect.height() - 2 * offset, - ) - painter.drawArc(adjusted_rect, self.start_positions[i], 360 * 16) - - # Foreground arc - pen = QtGui.QPen(self.colors[i], self.lineWidths[i], QtCore.Qt.SolidLine) - pen.setCapStyle(QtCore.Qt.RoundCap) - painter.setPen(pen) - angle = int(self.values[i] / 100 * 360 * 16 * self.directions[i]) - painter.drawArc(adjusted_rect, self.start_positions[i], angle) - - def sizeHint(self): - return QtCore.QSize(200, 200)