bec-widgets 1.7.0__py3-none-any.whl → 1.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
CHANGELOG.md CHANGED
@@ -1,6 +1,38 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v1.9.0 (2024-12-10)
5
+
6
+ ### Features
7
+
8
+ - **side_menu**: Side menu with stack widget added
9
+ ([`c7d7c6d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c7d7c6d9ed7c2dcc42b33fcd590f1f27499322c1))
10
+
11
+ ### Testing
12
+
13
+ - **side_panel**: Tests added
14
+ ([`9b95b5d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9b95b5d6164ff42673dbbc3031e5b1f45fbcde0a))
15
+
16
+
17
+ ## v1.8.0 (2024-12-10)
18
+
19
+ ### Features
20
+
21
+ - **modular_toolbar**: Material icons can be added/removed/hide/show/update dynamically
22
+ ([`a55134c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a55134c3bfcbda6dc2d33a17cf5a83df8be3fa7f))
23
+
24
+ - **modular_toolbar**: Orientation setting
25
+ ([`5fdb232`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5fdb2325ae970a7ecf4e2f4960710029891ab943))
26
+
27
+ - **round_frame**: Rounded frame for plot widgets and contrast adjustments
28
+ ([`6a36ca5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6a36ca512d88f2b4fe916ac991e4f17ae0baffab))
29
+
30
+ ### Testing
31
+
32
+ - **modular_toolbar**: Tests added
33
+ ([`9370351`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9370351abbd7a151065ea9300c500d5bea8ee4f6))
34
+
35
+
4
36
  ## v1.7.0 (2024-12-02)
5
37
 
6
38
  ### Bug Fixes
@@ -178,37 +210,3 @@ Depending on the test, auto-updates are enabled or not.
178
210
 
179
211
  - Update outdated text in docs
180
212
  ([`4f0693c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/4f0693cae34b391d75884837e1ae6353a0501868))
181
-
182
-
183
- ## v1.3.2 (2024-11-05)
184
-
185
- ### Bug Fixes
186
-
187
- - **plot_base**: Legend text color is changed when changing dark-light theme
188
- ([`2304c9f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2304c9f8497c1ab1492f3e6690bb79b0464c0df8))
189
-
190
- ### Build System
191
-
192
- - Pyside6 version fixed 6.7.2
193
- ([`c6e48ec`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c6e48ec1fe5aaee6a7c7a6f930f1520cd439cdb2))
194
-
195
-
196
- ## v1.3.1 (2024-10-31)
197
-
198
- ### Bug Fixes
199
-
200
- - **ophyd_kind_util**: Kind enums are imported from the bec widget util class
201
- ([`940ee65`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/940ee6552c1ee8d9b4e4a74c62351f2e133ab678))
202
-
203
-
204
- ## v1.3.0 (2024-10-30)
205
-
206
- ### Bug Fixes
207
-
208
- - **colors**: Extend color map validation for matplotlib and colorcet maps (if available)
209
- ([`14dd8c5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/14dd8c5b2947c92f6643b888d71975e4e8d4ee88))
210
-
211
- ### Features
212
-
213
- - **colormap_button**: Colormap button with menu to select colormap filtered by the colormap type
214
- ([`b039933`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b039933405e2fbe92bd81bd0748e79e8d443a741))
PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bec_widgets
3
- Version: 1.7.0
3
+ Version: 1.9.0
4
4
  Summary: BEC Widgets
5
5
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec_widgets/issues
6
6
  Project-URL: Homepage, https://gitlab.psi.ch/bec/bec_widgets
bec_widgets/cli/client.py CHANGED
@@ -19,7 +19,6 @@ class Widgets(str, enum.Enum):
19
19
  BECColorMapWidget = "BECColorMapWidget"
20
20
  BECDockArea = "BECDockArea"
21
21
  BECImageWidget = "BECImageWidget"
22
- BECMainWindow = "BECMainWindow"
23
22
  BECMotorMapWidget = "BECMotorMapWidget"
24
23
  BECMultiWaveformWidget = "BECMultiWaveformWidget"
25
24
  BECProgressBar = "BECProgressBar"
@@ -64,6 +63,13 @@ class AbortButton(RPCBase):
64
63
  Get all registered RPC objects.
65
64
  """
66
65
 
66
+ @property
67
+ @rpc_call
68
+ def _rpc_id(self) -> "str":
69
+ """
70
+ Get the RPC ID of the widget.
71
+ """
72
+
67
73
 
68
74
  class BECColorMapWidget(RPCBase):
69
75
  @property
@@ -0,0 +1,177 @@
1
+ import pyqtgraph as pg
2
+ from qtpy.QtCore import Property
3
+ from qtpy.QtWidgets import QApplication, QFrame, QVBoxLayout, QWidget
4
+
5
+ from bec_widgets.utils.bec_widget import BECWidget
6
+ from bec_widgets.widgets.utility.visual.dark_mode_button.dark_mode_button import DarkModeButton
7
+
8
+
9
+ class RoundedFrame(BECWidget, QFrame):
10
+ """
11
+ A custom QFrame with rounded corners and optional theme updates.
12
+ 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.
13
+ """
14
+
15
+ def __init__(
16
+ self,
17
+ parent=None,
18
+ content_widget: QWidget = None,
19
+ background_color: str = None,
20
+ theme_update: bool = True,
21
+ radius: int = 10,
22
+ **kwargs,
23
+ ):
24
+ super().__init__(**kwargs)
25
+ QFrame.__init__(self, parent)
26
+
27
+ self.background_color = background_color
28
+ self.theme_update = theme_update if background_color is None else False
29
+ self._radius = radius
30
+
31
+ # Apply rounded frame styling
32
+ self.setObjectName("roundedFrame")
33
+ self.update_style()
34
+
35
+ # Create a layout for the frame
36
+ layout = QVBoxLayout(self)
37
+ layout.setContentsMargins(5, 5, 5, 5) # Set 5px margin
38
+
39
+ # Add the content widget to the layout
40
+ if content_widget:
41
+ layout.addWidget(content_widget)
42
+
43
+ # Store reference to the content widget
44
+ self.content_widget = content_widget
45
+
46
+ # Automatically apply initial styles to the PlotWidget if applicable
47
+ if isinstance(content_widget, pg.PlotWidget):
48
+ self.apply_plot_widget_style()
49
+
50
+ self._connect_to_theme_change()
51
+
52
+ def apply_theme(self, theme: str):
53
+ """
54
+ Apply the theme to the frame and its content if theme updates are enabled.
55
+ """
56
+ if not self.theme_update:
57
+ return
58
+
59
+ # Update background color based on the theme
60
+ if theme == "light":
61
+ self.background_color = "#e9ecef" # Subtle contrast for light mode
62
+ else:
63
+ self.background_color = "#141414" # Dark mode
64
+
65
+ self.update_style()
66
+
67
+ # Update PlotWidget's background color and axis styles if applicable
68
+ if isinstance(self.content_widget, pg.PlotWidget):
69
+ self.apply_plot_widget_style()
70
+
71
+ @Property(int)
72
+ def radius(self):
73
+ """Radius of the rounded corners."""
74
+ return self._radius
75
+
76
+ @radius.setter
77
+ def radius(self, value: int):
78
+ self._radius = value
79
+ self.update_style()
80
+
81
+ def update_style(self):
82
+ """
83
+ Update the style of the frame based on the background color.
84
+ """
85
+ if self.background_color:
86
+ self.setStyleSheet(
87
+ f"""
88
+ QFrame#roundedFrame {{
89
+ background-color: {self.background_color};
90
+ border-radius: {self._radius}; /* Rounded corners */
91
+ }}
92
+ """
93
+ )
94
+
95
+ def apply_plot_widget_style(self, border: str = "none"):
96
+ """
97
+ Automatically apply background, border, and axis styles to the PlotWidget.
98
+
99
+ Args:
100
+ border (str): Border style (e.g., 'none', '1px solid red').
101
+ """
102
+ if isinstance(self.content_widget, pg.PlotWidget):
103
+ # Sync PlotWidget's background color with the RoundedFrame's background color
104
+ self.content_widget.setBackground(self.background_color)
105
+
106
+ # Calculate contrast-optimized axis and label colors
107
+ if self.background_color == "#e9ecef": # Light mode
108
+ label_color = "#000000"
109
+ axis_color = "#666666"
110
+ else: # Dark mode
111
+ label_color = "#FFFFFF"
112
+ axis_color = "#CCCCCC"
113
+
114
+ # Apply axis label and tick colors
115
+ plot_item = self.content_widget.getPlotItem()
116
+ plot_item.getAxis("left").setPen(pg.mkPen(color=axis_color))
117
+ plot_item.getAxis("bottom").setPen(pg.mkPen(color=axis_color))
118
+ plot_item.getAxis("left").setTextPen(pg.mkPen(color=label_color))
119
+ plot_item.getAxis("bottom").setTextPen(pg.mkPen(color=label_color))
120
+
121
+ # Apply border style via stylesheet
122
+ self.content_widget.setStyleSheet(
123
+ f"""
124
+ PlotWidget {{
125
+ border: {border}; /* Explicitly set the border */
126
+ }}
127
+ """
128
+ )
129
+
130
+
131
+ class ExampleApp(QWidget): # pragma: no cover
132
+ def __init__(self):
133
+ super().__init__()
134
+ self.setWindowTitle("Rounded Plots Example")
135
+
136
+ # Main layout
137
+ layout = QVBoxLayout(self)
138
+
139
+ dark_button = DarkModeButton()
140
+
141
+ # Create PlotWidgets
142
+ plot1 = pg.PlotWidget()
143
+ plot1.plot([1, 3, 2, 4, 6, 5], pen="r")
144
+
145
+ plot2 = pg.PlotWidget()
146
+ plot2.plot([1, 2, 4, 8, 16, 32], pen="r")
147
+
148
+ # Wrap PlotWidgets in RoundedFrame
149
+ rounded_plot1 = RoundedFrame(content_widget=plot1, theme_update=True)
150
+ rounded_plot2 = RoundedFrame(content_widget=plot2, theme_update=True)
151
+ round = RoundedFrame()
152
+
153
+ # Add to layout
154
+ layout.addWidget(dark_button)
155
+ layout.addWidget(rounded_plot1)
156
+ layout.addWidget(rounded_plot2)
157
+ layout.addWidget(round)
158
+
159
+ self.setLayout(layout)
160
+
161
+ # Simulate theme change after 2 seconds
162
+ from qtpy.QtCore import QTimer
163
+
164
+ def change_theme():
165
+ rounded_plot1.apply_theme("light")
166
+ rounded_plot2.apply_theme("dark")
167
+
168
+ QTimer.singleShot(100, change_theme)
169
+
170
+
171
+ if __name__ == "__main__": # pragma: no cover
172
+ app = QApplication([])
173
+
174
+ window = ExampleApp()
175
+ window.show()
176
+
177
+ app.exec()
@@ -0,0 +1,386 @@
1
+ import sys
2
+ from typing import Literal, Optional
3
+
4
+ from qtpy.QtCore import Property, QEasingCurve, QPropertyAnimation
5
+ from qtpy.QtGui import QAction
6
+ from qtpy.QtWidgets import (
7
+ QApplication,
8
+ QHBoxLayout,
9
+ QLabel,
10
+ QMainWindow,
11
+ QSizePolicy,
12
+ QSpacerItem,
13
+ QStackedWidget,
14
+ QVBoxLayout,
15
+ QWidget,
16
+ )
17
+
18
+ from bec_widgets.qt_utils.toolbar import MaterialIconAction, ModularToolBar
19
+ from bec_widgets.widgets.plots.waveform.waveform_widget import BECWaveformWidget
20
+
21
+
22
+ class SidePanel(QWidget):
23
+ """
24
+ Side panel widget that can be placed on the left, right, top, or bottom of the main widget.
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ parent=None,
30
+ orientation: Literal["left", "right", "top", "bottom"] = "left",
31
+ panel_max_width: int = 200,
32
+ animation_duration: int = 200,
33
+ animations_enabled: bool = True,
34
+ ):
35
+ super().__init__(parent=parent)
36
+
37
+ self._orientation = orientation
38
+ self._panel_max_width = panel_max_width
39
+ self._animation_duration = animation_duration
40
+ self._animations_enabled = animations_enabled
41
+ self._orientation = orientation
42
+
43
+ self._panel_width = 0
44
+ self._panel_height = 0
45
+ self.panel_visible = False
46
+ self.current_action: Optional[QAction] = None
47
+ self.current_index: Optional[int] = None
48
+ self.switching_actions = False
49
+
50
+ self._init_ui()
51
+
52
+ def _init_ui(self):
53
+ """
54
+ Initialize the UI elements.
55
+ """
56
+ if self._orientation in ("left", "right"):
57
+ self.main_layout = QHBoxLayout(self)
58
+ self.main_layout.setContentsMargins(0, 0, 0, 0)
59
+ self.main_layout.setSpacing(0)
60
+
61
+ self.toolbar = ModularToolBar(target_widget=self, orientation="vertical")
62
+
63
+ self.container = QWidget()
64
+ self.container.layout = QVBoxLayout(self.container)
65
+ self.container.layout.setContentsMargins(0, 0, 0, 0)
66
+ self.container.layout.setSpacing(0)
67
+
68
+ self.stack_widget = QStackedWidget()
69
+ self.stack_widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
70
+ self.stack_widget.setMinimumWidth(5)
71
+
72
+ if self._orientation == "left":
73
+ self.main_layout.addWidget(self.toolbar)
74
+ self.main_layout.addWidget(self.container)
75
+ else:
76
+ self.main_layout.addWidget(self.container)
77
+ self.main_layout.addWidget(self.toolbar)
78
+
79
+ self.container.layout.addWidget(self.stack_widget)
80
+ self.stack_widget.setMaximumWidth(self._panel_max_width)
81
+
82
+ else:
83
+ self.main_layout = QVBoxLayout(self)
84
+ self.main_layout.setContentsMargins(0, 0, 0, 0)
85
+ self.main_layout.setSpacing(0)
86
+
87
+ self.toolbar = ModularToolBar(target_widget=self, orientation="horizontal")
88
+
89
+ self.container = QWidget()
90
+ self.container.layout = QVBoxLayout(self.container)
91
+ self.container.layout.setContentsMargins(0, 0, 0, 0)
92
+ self.container.layout.setSpacing(0)
93
+
94
+ self.stack_widget = QStackedWidget()
95
+ self.stack_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
96
+ self.stack_widget.setMinimumHeight(5)
97
+
98
+ if self._orientation == "top":
99
+ self.main_layout.addWidget(self.toolbar)
100
+ self.main_layout.addWidget(self.container)
101
+ else:
102
+ self.main_layout.addWidget(self.container)
103
+ self.main_layout.addWidget(self.toolbar)
104
+
105
+ self.container.layout.addWidget(self.stack_widget)
106
+ self.stack_widget.setMaximumHeight(self._panel_max_width)
107
+
108
+ if self._orientation in ("left", "right"):
109
+ self.menu_anim = QPropertyAnimation(self, b"panel_width")
110
+ else:
111
+ self.menu_anim = QPropertyAnimation(self, b"panel_height")
112
+
113
+ self.menu_anim.setDuration(self._animation_duration)
114
+ self.menu_anim.setEasingCurve(QEasingCurve.InOutQuad)
115
+
116
+ if self._orientation in ("left", "right"):
117
+ self.panel_width = 0
118
+ else:
119
+ self.panel_height = 0
120
+
121
+ @Property(int)
122
+ def panel_width(self):
123
+ """
124
+ Get the panel width.
125
+ """
126
+ return self._panel_width
127
+
128
+ @panel_width.setter
129
+ def panel_width(self, width: int):
130
+ """
131
+ Set the panel width.
132
+
133
+ Args:
134
+ width(int): The width of the panel.
135
+ """
136
+ self._panel_width = width
137
+ if self._orientation in ("left", "right"):
138
+ self.stack_widget.setFixedWidth(width)
139
+
140
+ @Property(int)
141
+ def panel_height(self):
142
+ """
143
+ Get the panel height.
144
+ """
145
+ return self._panel_height
146
+
147
+ @panel_height.setter
148
+ def panel_height(self, height: int):
149
+ """
150
+ Set the panel height.
151
+
152
+ Args:
153
+ height(int): The height of the panel.
154
+ """
155
+ self._panel_height = height
156
+ if self._orientation in ("top", "bottom"):
157
+ self.stack_widget.setFixedHeight(height)
158
+
159
+ @Property(int)
160
+ def panel_max_width(self):
161
+ """
162
+ Get the maximum width of the panel.
163
+ """
164
+ return self._panel_max_width
165
+
166
+ @panel_max_width.setter
167
+ def panel_max_width(self, size: int):
168
+ """
169
+ Set the maximum width of the panel.
170
+
171
+ Args:
172
+ size(int): The maximum width of the panel.
173
+ """
174
+ self._panel_max_width = size
175
+ if self._orientation in ("left", "right"):
176
+ self.stack_widget.setMaximumWidth(self._panel_max_width)
177
+ else:
178
+ self.stack_widget.setMaximumHeight(self._panel_max_width)
179
+
180
+ @Property(int)
181
+ def animation_duration(self):
182
+ """
183
+ Get the duration of the animation.
184
+ """
185
+ return self._animation_duration
186
+
187
+ @animation_duration.setter
188
+ def animation_duration(self, duration: int):
189
+ """
190
+ Set the duration of the animation.
191
+
192
+ Args:
193
+ duration(int): The duration of the animation.
194
+ """
195
+ self._animation_duration = duration
196
+ self.menu_anim.setDuration(duration)
197
+
198
+ @Property(bool)
199
+ def animations_enabled(self):
200
+ """
201
+ Get the status of the animations.
202
+ """
203
+ return self._animations_enabled
204
+
205
+ @animations_enabled.setter
206
+ def animations_enabled(self, enabled: bool):
207
+ """
208
+ Set the status of the animations.
209
+
210
+ Args:
211
+ enabled(bool): The status of the animations.
212
+ """
213
+ self._animations_enabled = enabled
214
+
215
+ def show_panel(self, idx: int):
216
+ """
217
+ Show the side panel with animation and switch to idx.
218
+
219
+ Args:
220
+ idx(int): The index of the panel to show.
221
+ """
222
+ self.stack_widget.setCurrentIndex(idx)
223
+ self.panel_visible = True
224
+ self.current_index = idx
225
+
226
+ if self._orientation in ("left", "right"):
227
+ start_val, end_val = 0, self._panel_max_width
228
+ else:
229
+ start_val, end_val = 0, self._panel_max_width
230
+
231
+ if self._animations_enabled:
232
+ self.menu_anim.stop()
233
+ self.menu_anim.setStartValue(start_val)
234
+ self.menu_anim.setEndValue(end_val)
235
+ self.menu_anim.start()
236
+ else:
237
+ if self._orientation in ("left", "right"):
238
+ self.panel_width = end_val
239
+ else:
240
+ self.panel_height = end_val
241
+
242
+ def hide_panel(self):
243
+ """
244
+ Hide the side panel with animation.
245
+ """
246
+ self.panel_visible = False
247
+ self.current_index = None
248
+
249
+ if self._orientation in ("left", "right"):
250
+ start_val, end_val = self._panel_max_width, 0
251
+ else:
252
+ start_val, end_val = self._panel_max_width, 0
253
+
254
+ if self._animations_enabled:
255
+ self.menu_anim.stop()
256
+ self.menu_anim.setStartValue(start_val)
257
+ self.menu_anim.setEndValue(end_val)
258
+ self.menu_anim.start()
259
+ else:
260
+ if self._orientation in ("left", "right"):
261
+ self.panel_width = end_val
262
+ else:
263
+ self.panel_height = end_val
264
+
265
+ def switch_to(self, idx: int):
266
+ """
267
+ Switch to the specified index without animation.
268
+
269
+ Args:
270
+ idx(int): The index of the panel to switch to.
271
+ """
272
+ if self.current_index != idx:
273
+ self.stack_widget.setCurrentIndex(idx)
274
+ self.current_index = idx
275
+
276
+ def add_menu(self, action_id: str, icon_name: str, tooltip: str, widget: QWidget, title: str):
277
+ """
278
+ Add a menu to the side panel.
279
+
280
+ Args:
281
+ action_id(str): The ID of the action.
282
+ icon_name(str): The name of the icon.
283
+ tooltip(str): The tooltip for the action.
284
+ widget(QWidget): The widget to add to the panel.
285
+ title(str): The title of the panel.
286
+ """
287
+ container_widget = QWidget()
288
+ container_layout = QVBoxLayout(container_widget)
289
+ container_widget.setStyleSheet("background-color: rgba(0,0,0,0);")
290
+ title_label = QLabel(f"<b>{title}</b>")
291
+ title_label.setStyleSheet("font-size: 16px;")
292
+ spacer = QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)
293
+ container_layout.addWidget(title_label)
294
+ container_layout.addWidget(widget)
295
+ container_layout.addItem(spacer)
296
+ container_layout.setContentsMargins(5, 5, 5, 5)
297
+ container_layout.setSpacing(5)
298
+
299
+ index = self.stack_widget.count()
300
+ self.stack_widget.addWidget(container_widget)
301
+
302
+ action = MaterialIconAction(icon_name=icon_name, tooltip=tooltip, checkable=True)
303
+ self.toolbar.add_action(action_id, action, target_widget=self)
304
+
305
+ def on_action_toggled(checked: bool):
306
+ if self.switching_actions:
307
+ return
308
+
309
+ if checked:
310
+ if self.current_action and self.current_action != action.action:
311
+ self.switching_actions = True
312
+ self.current_action.setChecked(False)
313
+ self.switching_actions = False
314
+
315
+ self.current_action = action.action
316
+
317
+ if not self.panel_visible:
318
+ self.show_panel(index)
319
+ else:
320
+ self.switch_to(index)
321
+ else:
322
+ if self.current_action == action.action:
323
+ self.current_action = None
324
+ self.hide_panel()
325
+
326
+ action.action.toggled.connect(on_action_toggled)
327
+
328
+
329
+ class ExampleApp(QMainWindow): # pragma: no cover
330
+ def __init__(self):
331
+ super().__init__()
332
+ self.setWindowTitle("Side Panel Example")
333
+
334
+ central_widget = QWidget()
335
+ self.setCentralWidget(central_widget)
336
+
337
+ self.side_panel = SidePanel(self, orientation="left")
338
+
339
+ self.layout = QHBoxLayout(central_widget)
340
+
341
+ self.layout.addWidget(self.side_panel)
342
+ self.plot = BECWaveformWidget()
343
+ self.layout.addWidget(self.plot)
344
+ self.add_side_menus()
345
+
346
+ def add_side_menus(self):
347
+ widget1 = QWidget()
348
+ widget1_layout = QVBoxLayout(widget1)
349
+ widget1_layout.addWidget(QLabel("This is Widget 1"))
350
+ self.side_panel.add_menu(
351
+ action_id="widget1",
352
+ icon_name="counter_1",
353
+ tooltip="Show Widget 1",
354
+ widget=widget1,
355
+ title="Widget 1 Panel",
356
+ )
357
+
358
+ widget2 = QWidget()
359
+ widget2_layout = QVBoxLayout(widget2)
360
+ widget2_layout.addWidget(QLabel("This is Widget 2"))
361
+ self.side_panel.add_menu(
362
+ action_id="widget2",
363
+ icon_name="counter_2",
364
+ tooltip="Show Widget 2",
365
+ widget=widget2,
366
+ title="Widget 2 Panel",
367
+ )
368
+
369
+ widget3 = QWidget()
370
+ widget3_layout = QVBoxLayout(widget3)
371
+ widget3_layout.addWidget(QLabel("This is Widget 3"))
372
+ self.side_panel.add_menu(
373
+ action_id="widget3",
374
+ icon_name="counter_3",
375
+ tooltip="Show Widget 3",
376
+ widget=widget3,
377
+ title="Widget 3 Panel",
378
+ )
379
+
380
+
381
+ if __name__ == "__main__": # pragma: no cover
382
+ app = QApplication(sys.argv)
383
+ window = ExampleApp()
384
+ window.resize(800, 600)
385
+ window.show()
386
+ sys.exit(app.exec())
@@ -261,17 +261,31 @@ class ExpandableMenuAction(ToolBarAction):
261
261
 
262
262
  class ModularToolBar(QToolBar):
263
263
  """Modular toolbar with optional automatic initialization.
264
+
264
265
  Args:
265
266
  parent (QWidget, optional): The parent widget of the toolbar. Defaults to None.
266
- actions (list[ToolBarAction], optional): A list of action creators to populate the toolbar. Defaults to None.
267
+ actions (dict, optional): A dictionary of action creators to populate the toolbar. Defaults to None.
267
268
  target_widget (QWidget, optional): The widget that the actions will target. Defaults to None.
269
+ orientation (Literal["horizontal", "vertical"], optional): The initial orientation of the toolbar. Defaults to "horizontal".
270
+ background_color (str, optional): The background color of the toolbar. Defaults to "rgba(0, 0, 0, 0)" - transparent background.
268
271
  """
269
272
 
270
- def __init__(self, parent=None, actions: dict | None = None, target_widget=None):
273
+ def __init__(
274
+ self,
275
+ parent=None,
276
+ actions: dict | None = None,
277
+ target_widget=None,
278
+ orientation: Literal["horizontal", "vertical"] = "horizontal",
279
+ background_color: str = "rgba(0, 0, 0, 0)",
280
+ ):
271
281
  super().__init__(parent)
272
282
 
273
283
  self.widgets = defaultdict(dict)
274
- self.set_background_color()
284
+ self.background_color = background_color
285
+ self.set_background_color(self.background_color)
286
+
287
+ # Set the initial orientation
288
+ self.set_orientation(orientation)
275
289
 
276
290
  if actions is not None and target_widget is not None:
277
291
  self.populate_toolbar(actions, target_widget)
@@ -280,7 +294,7 @@ class ModularToolBar(QToolBar):
280
294
  """Populates the toolbar with a set of actions.
281
295
 
282
296
  Args:
283
- actions (list[ToolBarAction]): A list of action creators to populate the toolbar.
297
+ actions (dict): A dictionary of action creators to populate the toolbar.
284
298
  target_widget (QWidget): The widget that the actions will target.
285
299
  """
286
300
  self.clear()
@@ -288,9 +302,83 @@ class ModularToolBar(QToolBar):
288
302
  action.add_to_toolbar(self, target_widget)
289
303
  self.widgets[action_id] = action
290
304
 
291
- def set_background_color(self):
305
+ def set_background_color(self, color: str = "rgba(0, 0, 0, 0)"):
306
+ """
307
+ Sets the background color and other appearance settings.
308
+
309
+ Args:
310
+ color(str): The background color of the toolbar.
311
+ """
292
312
  self.setIconSize(QSize(20, 20))
293
313
  self.setMovable(False)
294
314
  self.setFloatable(False)
295
315
  self.setContentsMargins(0, 0, 0, 0)
296
- self.setStyleSheet("QToolBar { background-color: rgba(0, 0, 0, 0); border: none; }")
316
+ self.background_color = color
317
+ self.setStyleSheet(f"QToolBar {{ background-color: {color}; border: none; }}")
318
+
319
+ def set_orientation(self, orientation: Literal["horizontal", "vertical"]):
320
+ """Sets the orientation of the toolbar.
321
+
322
+ Args:
323
+ orientation (Literal["horizontal", "vertical"]): The desired orientation of the toolbar.
324
+ """
325
+ if orientation == "horizontal":
326
+ self.setOrientation(Qt.Horizontal)
327
+ elif orientation == "vertical":
328
+ self.setOrientation(Qt.Vertical)
329
+ else:
330
+ raise ValueError("Orientation must be 'horizontal' or 'vertical'.")
331
+
332
+ def update_material_icon_colors(self, new_color: str | tuple | QColor):
333
+ """
334
+ Updates the color of all MaterialIconAction icons in the toolbar.
335
+
336
+ Args:
337
+ new_color (str | tuple | QColor): The new color for the icons.
338
+ """
339
+ for action in self.widgets.values():
340
+ if isinstance(action, MaterialIconAction):
341
+ action.color = new_color
342
+ # Refresh the icon
343
+ updated_icon = action.get_icon()
344
+ action.action.setIcon(updated_icon)
345
+
346
+ def add_action(self, action_id: str, action: ToolBarAction, target_widget: QWidget):
347
+ """
348
+ Adds a new action to the toolbar dynamically.
349
+
350
+ Args:
351
+ action_id (str): Unique identifier for the action.
352
+ action (ToolBarAction): The action to add to the toolbar.
353
+ target_widget (QWidget): The target widget for the action.
354
+ """
355
+ if action_id in self.widgets:
356
+ raise ValueError(f"Action with ID '{action_id}' already exists.")
357
+ action.add_to_toolbar(self, target_widget)
358
+ self.widgets[action_id] = action
359
+
360
+ def hide_action(self, action_id: str):
361
+ """
362
+ Hides a specific action on the toolbar.
363
+
364
+ Args:
365
+ action_id (str): Unique identifier for the action to hide.
366
+ """
367
+ if action_id not in self.widgets:
368
+ raise ValueError(f"Action with ID '{action_id}' does not exist.")
369
+ action = self.widgets[action_id]
370
+ if hasattr(action, "action") and isinstance(action.action, QAction):
371
+ action.action.setVisible(False)
372
+
373
+ def show_action(self, action_id: str):
374
+ """
375
+ Shows a specific action on the toolbar.
376
+
377
+ Args:
378
+ action_id (str): Unique identifier for the action to show.
379
+ """
380
+ if action_id not in self.widgets:
381
+ raise ValueError(f"Action with ID '{action_id}' does not exist.")
382
+ action = self.widgets[action_id]
383
+ if hasattr(action, "action") and isinstance(action.action, QAction):
384
+ action.action.setVisible(True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bec_widgets
3
- Version: 1.7.0
3
+ Version: 1.9.0
4
4
  Summary: BEC Widgets
5
5
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec_widgets/issues
6
6
  Project-URL: Homepage, https://gitlab.psi.ch/bec/bec_widgets
@@ -2,11 +2,11 @@
2
2
  .gitlab-ci.yml,sha256=bAWGX_NR9rQZmv_bmyLXkEMRreWp0JzVNpsNTxk0NwE,8637
3
3
  .pylintrc,sha256=eeY8YwSI74oFfq6IYIbCqnx3Vk8ZncKaatv96n_Y8Rs,18544
4
4
  .readthedocs.yaml,sha256=aSOc277LqXcsTI6lgvm_JY80lMlr69GbPKgivua2cS0,603
5
- CHANGELOG.md,sha256=-XyIDJ1C204NhjKieHBciyZVtpEQnlqAZgusnhdxU-k,7859
5
+ CHANGELOG.md,sha256=vk99JDb0HVTJZsEm6TJ8g-RemuqHi7tQsDKkk-GVF2k,7866
6
6
  LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
7
- PKG-INFO,sha256=0rkaKmhcyUiRQJnmMXE8GgO0BMm8JMEcVGpGzkTwdOc,1308
7
+ PKG-INFO,sha256=QjMuyUkfdYQ7l0gazbGYeGbf96Sx3xRfbSaBsM9rcrY,1308
8
8
  README.md,sha256=Od69x-RS85Hph0-WwWACwal4yUd67XkEn4APEfHhHFw,2649
9
- pyproject.toml,sha256=MH0RsHdGV1exWgR_0BWw67wwFgluGLni_d2Qdn3HlLk,2586
9
+ pyproject.toml,sha256=_ntcDbeIJWyJtMIlP5r3Hq9h1z4vuth-KYYJyK14PF0,2586
10
10
  .git_hooks/pre-commit,sha256=n3RofIZHJl8zfJJIUomcMyYGFi_rwq4CC19z0snz3FI,286
11
11
  .gitlab/issue_templates/bug_report_template.md,sha256=gAuyEwl7XlnebBrkiJ9AqffSNOywmr8vygUFWKTuQeI,386
12
12
  .gitlab/issue_templates/documentation_update_template.md,sha256=FHLdb3TS_D9aL4CYZCjyXSulbaW5mrN2CmwTaeLPbNw,860
@@ -24,7 +24,7 @@ bec_widgets/assets/app_icons/alignment_1d.png,sha256=5VouaWieb4lVv3wUBNHaO5ovUW2
24
24
  bec_widgets/assets/app_icons/bec_widgets_icon.png,sha256=K8dgGwIjalDh9PRHUsSQBqgdX7a00nM3igZdc20pkYM,1747017
25
25
  bec_widgets/cli/__init__.py,sha256=d0Q6Fn44e7wFfLabDOBxpcJ1DPKWlFunGYDUBmO-4hA,22
26
26
  bec_widgets/cli/auto_updates.py,sha256=DwzRChcFIWPH2kCYvp8H7dXvyYSKGYv6LwCmK2sDR2E,5676
27
- bec_widgets/cli/client.py,sha256=1XWSLn7CwqVkN9g3ELYTacjAsBaRPkGRboq9IvhDcpc,98538
27
+ bec_widgets/cli/client.py,sha256=smVHOupX4BfpdPMgLDA1maGCFcXMPKJiIIgG4lIvjAY,98625
28
28
  bec_widgets/cli/client_utils.py,sha256=5qlMFOh-7J6CclEKMj0BD09cNA4XCp1d1Wj2Z5hPpnA,14106
29
29
  bec_widgets/cli/generate_cli.py,sha256=YyYEPBpu5v9plCFQZHnyvEeFKoeHatpplPGil_D8DJM,6643
30
30
  bec_widgets/cli/rpc_register.py,sha256=8s-YJxqYoKc2K7jRLvs0TjW6_OnhaRYCK00RIok_4qE,2252
@@ -49,8 +49,10 @@ bec_widgets/qt_utils/compact_popup.py,sha256=3yeb-GJ1PUla5Q_hT0XDKqvyIEH9yV_eGid
49
49
  bec_widgets/qt_utils/error_popups.py,sha256=y9gKKWaafp468ioHr96nBhf02ZpEgjDc-BAVOTWh-e8,7680
50
50
  bec_widgets/qt_utils/palette_viewer.py,sha256=--B0x7aE7bniHIeuuLY_pH8yBDrTTXaE0IDrC_AM1mo,6326
51
51
  bec_widgets/qt_utils/redis_message_waiter.py,sha256=fvL_QgC0cTDv_FPJdRyp5AKjf401EJU4z3r38p47ydY,1745
52
+ bec_widgets/qt_utils/round_frame.py,sha256=Ba_sTzYB_vYDepBBMPPqU8XDwKOAiU6ClZ3xUqiveK0,5734
52
53
  bec_widgets/qt_utils/settings_dialog.py,sha256=NhtzTer_xzlB2lLLrGklkI1QYLJEWQpJoZbCz4o5daI,3645
53
- bec_widgets/qt_utils/toolbar.py,sha256=yR2WNPv7dD8jU12aHgUMAi5-FYyCKe2MNSsqMzsa5pg,9856
54
+ bec_widgets/qt_utils/side_panel.py,sha256=5XtHIGfEJJj5m7cvkm-Vaxzz1TQogwglrmBaVcmcngY,12332
55
+ bec_widgets/qt_utils/toolbar.py,sha256=RcWoWjibhlpL26Bnbft-uWA1q2WCglJRnO6U3hGMBw8,13277
54
56
  bec_widgets/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
57
  bec_widgets/tests/utils.py,sha256=D1v3JLzzbnX3HXBQCjoFlNz5cYhjqrRkFcjx3yptMJA,6687
56
58
  bec_widgets/utils/__init__.py,sha256=1930ji1Jj6dVuY81Wd2kYBhHYNV-2R0bN_L4o9zBj1U,533
@@ -313,8 +315,8 @@ bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py,sha256=Z
313
315
  bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.pyproject,sha256=Lbi9zb6HNlIq14k6hlzR-oz6PIFShBuF7QxE6d87d64,34
314
316
  bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button_plugin.py,sha256=CzChz2SSETYsR8-36meqWnsXCT-FIy_J_xeU5coWDY8,1350
315
317
  bec_widgets/widgets/utility/visual/dark_mode_button/register_dark_mode_button.py,sha256=rMpZ1CaoucwobgPj1FuKTnt07W82bV1GaSYdoqcdMb8,521
316
- bec_widgets-1.7.0.dist-info/METADATA,sha256=0rkaKmhcyUiRQJnmMXE8GgO0BMm8JMEcVGpGzkTwdOc,1308
317
- bec_widgets-1.7.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
318
- bec_widgets-1.7.0.dist-info/entry_points.txt,sha256=dItMzmwA1wizJ1Itx15qnfJ0ZzKVYFLVJ1voxT7K7D4,214
319
- bec_widgets-1.7.0.dist-info/licenses/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
320
- bec_widgets-1.7.0.dist-info/RECORD,,
318
+ bec_widgets-1.9.0.dist-info/METADATA,sha256=QjMuyUkfdYQ7l0gazbGYeGbf96Sx3xRfbSaBsM9rcrY,1308
319
+ bec_widgets-1.9.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
320
+ bec_widgets-1.9.0.dist-info/entry_points.txt,sha256=dItMzmwA1wizJ1Itx15qnfJ0ZzKVYFLVJ1voxT7K7D4,214
321
+ bec_widgets-1.9.0.dist-info/licenses/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
322
+ bec_widgets-1.9.0.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bec_widgets"
7
- version = "1.7.0"
7
+ version = "1.9.0"
8
8
  description = "BEC Widgets"
9
9
  requires-python = ">=3.10"
10
10
  classifiers = [