bec-widgets 1.6.0__py3-none-any.whl → 1.8.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 +61 -59
- PKG-INFO +1 -1
- bec_widgets/cli/client.py +7 -1
- bec_widgets/qt_utils/round_frame.py +177 -0
- bec_widgets/qt_utils/toolbar.py +94 -6
- bec_widgets/widgets/editors/console/console.py +140 -5
- {bec_widgets-1.6.0.dist-info → bec_widgets-1.8.0.dist-info}/METADATA +1 -1
- {bec_widgets-1.6.0.dist-info → bec_widgets-1.8.0.dist-info}/RECORD +12 -11
- pyproject.toml +1 -1
- {bec_widgets-1.6.0.dist-info → bec_widgets-1.8.0.dist-info}/WHEEL +0 -0
- {bec_widgets-1.6.0.dist-info → bec_widgets-1.8.0.dist-info}/entry_points.txt +0 -0
- {bec_widgets-1.6.0.dist-info → bec_widgets-1.8.0.dist-info}/licenses/LICENSE +0 -0
CHANGELOG.md
CHANGED
@@ -1,14 +1,51 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
3
|
|
4
|
-
## v1.
|
4
|
+
## v1.8.0 (2024-12-10)
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
- **modular_toolbar**: Material icons can be added/removed/hide/show/update dynamically
|
9
|
+
([`a55134c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a55134c3bfcbda6dc2d33a17cf5a83df8be3fa7f))
|
10
|
+
|
11
|
+
- **modular_toolbar**: Orientation setting
|
12
|
+
([`5fdb232`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5fdb2325ae970a7ecf4e2f4960710029891ab943))
|
13
|
+
|
14
|
+
- **round_frame**: Rounded frame for plot widgets and contrast adjustments
|
15
|
+
([`6a36ca5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6a36ca512d88f2b4fe916ac991e4f17ae0baffab))
|
16
|
+
|
17
|
+
### Testing
|
18
|
+
|
19
|
+
- **modular_toolbar**: Tests added
|
20
|
+
([`9370351`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9370351abbd7a151065ea9300c500d5bea8ee4f6))
|
21
|
+
|
22
|
+
|
23
|
+
## v1.7.0 (2024-12-02)
|
5
24
|
|
6
25
|
### Bug Fixes
|
7
26
|
|
8
|
-
- **tests**:
|
9
|
-
([`
|
27
|
+
- **tests**: Add test for Console widget
|
28
|
+
([`da579b6`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/da579b6d213bcdf28c40c1a9e4e2535fdde824fb))
|
10
29
|
|
11
|
-
|
30
|
+
### Features
|
31
|
+
|
32
|
+
- **console**: Add "prompt" signal to inform when shell is at prompt
|
33
|
+
([`3aeb0b6`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/3aeb0b66fbeb03d3d0ee60e108cc6b98fd9aa9b9))
|
34
|
+
|
35
|
+
- **console**: Add 'terminate' and 'send_ctrl_c' methods to Console
|
36
|
+
([`02086ae`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/02086aeae09233ec4e6ccc0e6a17f2b078d500b8))
|
37
|
+
|
38
|
+
.terminate() ends the started process, sending SIGTERM signal. If process is not dead after optional
|
39
|
+
timeout, SIGKILL is sent. .send_ctrl_c() sends SIGINT to the child process, and waits for prompt
|
40
|
+
until optional timeout is reached. Timeouts raise 'TimeoutError' exception.
|
41
|
+
|
42
|
+
|
43
|
+
## v1.6.0 (2024-11-27)
|
44
|
+
|
45
|
+
### Bug Fixes
|
46
|
+
|
47
|
+
- Add back accidentally removed variables
|
48
|
+
([`e998352`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e9983521ed2a1c04af048a55ece70a1943a84313))
|
12
49
|
|
13
50
|
- Differentiate click and drag for DeviceItem, adapt tests accordingly
|
14
51
|
([`cffcdf2`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/cffcdf292363249bcc7efa9d130431d0bc727fda))
|
@@ -17,12 +54,6 @@ This fixes the blocking "QDrag.exec_()" on Linux, indeed before the drag'n'drop
|
|
17
54
|
started with a simple click and it was waiting for drop forever. Now there are 2 different cases,
|
18
55
|
click or drag'n'drop - the drag'n'drop test actually moves the mouse and releases the button.
|
19
56
|
|
20
|
-
- **server**: Use dock area by default
|
21
|
-
([`2fe7f5e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2fe7f5e1510a5ea72676045e6ea3485e6b11c220))
|
22
|
-
|
23
|
-
- **rpc**: Gui hide/show also hide/show all floating docks
|
24
|
-
([`c27d058`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c27d058b01fe604eccec76454e39360122e48515))
|
25
|
-
|
26
57
|
- Do not quit automatically when last window is "closed"
|
27
58
|
([`96e255e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/96e255e4ef394eb79006a66d13e06775ae235667))
|
28
59
|
|
@@ -31,8 +62,16 @@ Qt confuses closed and hidden
|
|
31
62
|
- No need to call inspect.signature - it can fail on methods coming from C (like Qt methods)
|
32
63
|
([`6029246`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/60292465e9e52d3248ae681c68c07298b9b3ce14))
|
33
64
|
|
34
|
-
-
|
35
|
-
([`
|
65
|
+
- **rpc**: Gui hide/show also hide/show all floating docks
|
66
|
+
([`c27d058`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c27d058b01fe604eccec76454e39360122e48515))
|
67
|
+
|
68
|
+
- **server**: Use dock area by default
|
69
|
+
([`2fe7f5e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2fe7f5e1510a5ea72676045e6ea3485e6b11c220))
|
70
|
+
|
71
|
+
- **tests**: Make use of BECDockArea with client mixin to start server and use it in tests
|
72
|
+
([`da18c2c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/da18c2ceecf9aeaf0e0ea9b78f4c867b27b9c314))
|
73
|
+
|
74
|
+
Depending on the test, auto-updates are enabled or not.
|
36
75
|
|
37
76
|
### Features
|
38
77
|
|
@@ -40,26 +79,26 @@ Qt confuses closed and hidden
|
|
40
79
|
BECDockArea
|
41
80
|
([`31d8703`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/31d87036c9801e639a7ca6fc003c90e0c4edb19d))
|
42
81
|
|
43
|
-
- Add
|
44
|
-
([`
|
45
|
-
|
46
|
-
- **client**: Add show()/hide() methods to "gui" object
|
47
|
-
([`e68e2b5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e68e2b5978339475b97555c3e20795807932fbc9))
|
48
|
-
|
49
|
-
- **server**: Add main window, with proper gui_id derived from given id
|
50
|
-
([`daf6ea0`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/daf6ea0159c9ffc7b53bb7ae6b9abc16a302972c))
|
82
|
+
- Add '--hide' argument to BEC GUI server
|
83
|
+
([`1f60fec`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/1f60fec7201ed252d7e49bf16f2166ee7f6bed6a))
|
51
84
|
|
52
85
|
- Add main window container widget
|
53
86
|
([`f80ec33`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/f80ec33ae5a261dbcab901ae30f4cc802316e554))
|
54
87
|
|
88
|
+
- Add rpc_id member to client objects
|
89
|
+
([`3ba0b1d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/3ba0b1daf5b83da840e90fbbc063ed7b86ebe99b))
|
90
|
+
|
55
91
|
- Asynchronous .start() for GUI
|
56
92
|
([`2047e48`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2047e484d5a4b2f5ea494a1e49035b35b1bbde35))
|
57
93
|
|
58
94
|
- Do not take focus when GUI is loaded
|
59
95
|
([`1f71d8e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/1f71d8e5eded9952f9b34bfc427e2ff44cf5fc18))
|
60
96
|
|
61
|
-
- Add
|
62
|
-
([`
|
97
|
+
- **client**: Add show()/hide() methods to "gui" object
|
98
|
+
([`e68e2b5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e68e2b5978339475b97555c3e20795807932fbc9))
|
99
|
+
|
100
|
+
- **server**: Add main window, with proper gui_id derived from given id
|
101
|
+
([`daf6ea0`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/daf6ea0159c9ffc7b53bb7ae6b9abc16a302972c))
|
63
102
|
|
64
103
|
|
65
104
|
## v1.5.3 (2024-11-21)
|
@@ -171,40 +210,3 @@ Qt confuses closed and hidden
|
|
171
210
|
|
172
211
|
- Pyside6 version fixed 6.7.2
|
173
212
|
([`c6e48ec`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c6e48ec1fe5aaee6a7c7a6f930f1520cd439cdb2))
|
174
|
-
|
175
|
-
|
176
|
-
## v1.3.1 (2024-10-31)
|
177
|
-
|
178
|
-
### Bug Fixes
|
179
|
-
|
180
|
-
- **ophyd_kind_util**: Kind enums are imported from the bec widget util class
|
181
|
-
([`940ee65`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/940ee6552c1ee8d9b4e4a74c62351f2e133ab678))
|
182
|
-
|
183
|
-
|
184
|
-
## v1.3.0 (2024-10-30)
|
185
|
-
|
186
|
-
### Bug Fixes
|
187
|
-
|
188
|
-
- **colors**: Extend color map validation for matplotlib and colorcet maps (if available)
|
189
|
-
([`14dd8c5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/14dd8c5b2947c92f6643b888d71975e4e8d4ee88))
|
190
|
-
|
191
|
-
### Features
|
192
|
-
|
193
|
-
- **colormap_button**: Colormap button with menu to select colormap filtered by the colormap type
|
194
|
-
([`b039933`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b039933405e2fbe92bd81bd0748e79e8d443a741))
|
195
|
-
|
196
|
-
|
197
|
-
## v1.2.0 (2024-10-25)
|
198
|
-
|
199
|
-
### Features
|
200
|
-
|
201
|
-
- **colors**: Evenly spaced color generation + new golden ratio calculation
|
202
|
-
([`40c9fea`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/40c9fea35f869ef52e05948dd1989bcd99f602e0))
|
203
|
-
|
204
|
-
### Refactoring
|
205
|
-
|
206
|
-
- Add bec_lib version to statusbox
|
207
|
-
([`5d4b86e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5d4b86e1c6e1800051afce4f991153e370767fa6))
|
208
|
-
|
209
|
-
|
210
|
-
## v1.1.0 (2024-10-25)
|
PKG-INFO
CHANGED
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()
|
bec_widgets/qt_utils/toolbar.py
CHANGED
@@ -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 (
|
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__(
|
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.
|
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 (
|
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.
|
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)
|
@@ -10,9 +10,13 @@ import fcntl
|
|
10
10
|
import html
|
11
11
|
import os
|
12
12
|
import pty
|
13
|
+
import re
|
14
|
+
import signal
|
13
15
|
import sys
|
16
|
+
import time
|
14
17
|
|
15
18
|
import pyte
|
19
|
+
from pygments.token import Token
|
16
20
|
from pyte.screens import History
|
17
21
|
from qtpy import QtCore, QtGui, QtWidgets
|
18
22
|
from qtpy.QtCore import Property as pyqtProperty
|
@@ -235,10 +239,14 @@ class BECConsole(QtWidgets.QWidget):
|
|
235
239
|
PLUGIN = True
|
236
240
|
ICON_NAME = "terminal"
|
237
241
|
|
242
|
+
prompt = pyqtSignal(bool)
|
243
|
+
|
238
244
|
def __init__(self, parent=None, cols=132):
|
239
245
|
super().__init__(parent)
|
240
246
|
|
241
247
|
self.term = _TerminalWidget(self, cols, rows=43)
|
248
|
+
self.term.prompt.connect(self.prompt) # forward signal from term to this widget
|
249
|
+
|
242
250
|
self.scroll_bar = QScrollBar(Qt.Vertical, self)
|
243
251
|
# self.scroll_bar.hide()
|
244
252
|
layout = QHBoxLayout(self)
|
@@ -320,9 +328,38 @@ class BECConsole(QtWidgets.QWidget):
|
|
320
328
|
def start(self, deactivate_ctrl_d=True):
|
321
329
|
self.term.start(deactivate_ctrl_d=deactivate_ctrl_d)
|
322
330
|
|
323
|
-
def push(self, text):
|
331
|
+
def push(self, text, hit_return=False):
|
324
332
|
"""Push some text to the terminal"""
|
325
|
-
return self.term.push(text)
|
333
|
+
return self.term.push(text, hit_return=hit_return)
|
334
|
+
|
335
|
+
def execute_command(self, command):
|
336
|
+
self.push(command, hit_return=True)
|
337
|
+
|
338
|
+
def set_prompt_tokens(self, *tokens):
|
339
|
+
"""Prepare regexp to identify prompt, based on tokens
|
340
|
+
|
341
|
+
Tokens are returned from get_ipython().prompts.in_prompt_tokens()
|
342
|
+
"""
|
343
|
+
regex_parts = []
|
344
|
+
for token_type, token_value in tokens:
|
345
|
+
if token_type == Token.PromptNum: # Handle dynamic prompt number
|
346
|
+
regex_parts.append(r"[\d\?]+") # Match one or more digits or '?'
|
347
|
+
else:
|
348
|
+
# Escape other prompt parts (e.g., "In [", "]: ")
|
349
|
+
if not token_value:
|
350
|
+
regex_parts.append(".+?") # arbitrary string
|
351
|
+
else:
|
352
|
+
regex_parts.append(re.escape(token_value))
|
353
|
+
|
354
|
+
# Combine into a single regex
|
355
|
+
prompt_pattern = "".join(regex_parts)
|
356
|
+
self.term._prompt_re = re.compile(prompt_pattern + r"\s*$")
|
357
|
+
|
358
|
+
def terminate(self, timeout=10):
|
359
|
+
self.term.stop(timeout=timeout)
|
360
|
+
|
361
|
+
def send_ctrl_c(self, timeout=None):
|
362
|
+
self.term.send_ctrl_c(timeout)
|
326
363
|
|
327
364
|
cols = pyqtProperty(int, get_cols, set_cols)
|
328
365
|
rows = pyqtProperty(int, get_rows, set_rows)
|
@@ -336,7 +373,15 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
336
373
|
Start ``Backend`` process and render Pyte output as text.
|
337
374
|
"""
|
338
375
|
|
376
|
+
prompt = pyqtSignal(bool)
|
377
|
+
|
339
378
|
def __init__(self, parent, cols=125, rows=50, **kwargs):
|
379
|
+
# regexp to match prompt
|
380
|
+
self._prompt_re = None
|
381
|
+
# last prompt
|
382
|
+
self._prompt_str = None
|
383
|
+
# process pid
|
384
|
+
self.pid = None
|
340
385
|
# file descriptor to communicate with the subprocess
|
341
386
|
self.fd = None
|
342
387
|
self.backend = None
|
@@ -433,7 +478,7 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
433
478
|
self.update_term_size()
|
434
479
|
|
435
480
|
# Start the Bash process
|
436
|
-
self.fd = self.fork_shell()
|
481
|
+
self.pid, self.fd = self.fork_shell()
|
437
482
|
|
438
483
|
if self.fd:
|
439
484
|
# Create the ``Backend`` object
|
@@ -449,6 +494,62 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
449
494
|
self.appendHtml(f"<br><h2>{repr(self._cmd)} - Process exited.</h2>")
|
450
495
|
self.setReadOnly(True)
|
451
496
|
|
497
|
+
def send_ctrl_c(self, wait_prompt=True, timeout=None):
|
498
|
+
"""Send CTRL-C to the process
|
499
|
+
|
500
|
+
If wait_prompt=True (default), wait for a new prompt after CTRL-C
|
501
|
+
If no prompt is displayed after 'timeout' seconds, TimeoutError is raised
|
502
|
+
"""
|
503
|
+
os.kill(self.pid, signal.SIGINT)
|
504
|
+
if wait_prompt:
|
505
|
+
timeout_error = False
|
506
|
+
if timeout:
|
507
|
+
|
508
|
+
def set_timeout_error():
|
509
|
+
nonlocal timeout_error
|
510
|
+
timeout_error = True
|
511
|
+
|
512
|
+
timeout_timer = QTimer()
|
513
|
+
timeout_timer.singleShot(timeout * 1000, set_timeout_error)
|
514
|
+
while self._prompt_str is None:
|
515
|
+
QApplication.instance().process_events()
|
516
|
+
if timeout_error:
|
517
|
+
raise TimeoutError(
|
518
|
+
f"CTRL-C: could not get back to prompt after {timeout} seconds."
|
519
|
+
)
|
520
|
+
|
521
|
+
def _is_running(self):
|
522
|
+
if os.waitpid(self.pid, os.WNOHANG) == (0, 0):
|
523
|
+
return True
|
524
|
+
return False
|
525
|
+
|
526
|
+
def stop(self, kill=True, timeout=None):
|
527
|
+
"""Stop the running process
|
528
|
+
|
529
|
+
SIGTERM is the default signal for terminating processes.
|
530
|
+
|
531
|
+
If kill=True (default), SIGKILL will be sent if the process does not exit after timeout
|
532
|
+
"""
|
533
|
+
# try to exit gracefully
|
534
|
+
os.kill(self.pid, signal.SIGTERM)
|
535
|
+
|
536
|
+
# wait until process is truly dead
|
537
|
+
t0 = time.perf_counter()
|
538
|
+
while self._is_running():
|
539
|
+
time.sleep(1)
|
540
|
+
if timeout is not None and time.perf_counter() - t0 > timeout:
|
541
|
+
# still alive after 'timeout' seconds
|
542
|
+
if kill:
|
543
|
+
# send SIGKILL and make a last check in loop
|
544
|
+
os.kill(self.pid, signal.SIGKILL)
|
545
|
+
kill = False
|
546
|
+
else:
|
547
|
+
# still running after timeout...
|
548
|
+
raise TimeoutError(
|
549
|
+
f"Could not terminate process with pid: {self.pid} within timeout"
|
550
|
+
)
|
551
|
+
self.process_exited()
|
552
|
+
|
452
553
|
def data_ready(self, screen):
|
453
554
|
"""Handle new screen: redraw, set scroll bar max and slider, move cursor to its position
|
454
555
|
|
@@ -540,11 +641,13 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
540
641
|
elif code is not None:
|
541
642
|
self.write(code)
|
542
643
|
|
543
|
-
def push(self, text):
|
644
|
+
def push(self, text, hit_return=False):
|
544
645
|
"""
|
545
646
|
Write 'text' to terminal
|
546
647
|
"""
|
547
648
|
self.write(text.encode("utf-8"))
|
649
|
+
if hit_return:
|
650
|
+
self.write(b"\n")
|
548
651
|
|
549
652
|
def contextMenuEvent(self, event):
|
550
653
|
if self.fd is None:
|
@@ -650,6 +753,20 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
650
753
|
self.output[line_no] = line
|
651
754
|
# fill the text area with HTML contents in one go
|
652
755
|
self.appendHtml(f"<pre>{chr(10).join(self.output)}</pre>")
|
756
|
+
|
757
|
+
if self._prompt_re is not None:
|
758
|
+
text_buf = self.toPlainText()
|
759
|
+
prompt = self._prompt_re.search(text_buf)
|
760
|
+
if prompt is None:
|
761
|
+
if self._prompt_str:
|
762
|
+
self.prompt.emit(False)
|
763
|
+
self._prompt_str = None
|
764
|
+
else:
|
765
|
+
prompt_str = prompt.string.rstrip()
|
766
|
+
if prompt_str != self._prompt_str:
|
767
|
+
self._prompt_str = prompt_str
|
768
|
+
self.prompt.emit(True)
|
769
|
+
|
653
770
|
# did updates, all clean
|
654
771
|
screen.dirty.clear()
|
655
772
|
|
@@ -711,7 +828,7 @@ class _TerminalWidget(QtWidgets.QPlainTextEdit):
|
|
711
828
|
# We are in the parent process.
|
712
829
|
# Set file control
|
713
830
|
fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
|
714
|
-
return fd
|
831
|
+
return pid, fd
|
715
832
|
|
716
833
|
|
717
834
|
if __name__ == "__main__":
|
@@ -728,6 +845,24 @@ if __name__ == "__main__":
|
|
728
845
|
|
729
846
|
console = BECConsole(mainwin)
|
730
847
|
mainwin.setCentralWidget(console)
|
848
|
+
|
849
|
+
def check_prompt(at_prompt):
|
850
|
+
if at_prompt:
|
851
|
+
print("NEW PROMPT")
|
852
|
+
else:
|
853
|
+
print("EXECUTING SOMETHING...")
|
854
|
+
|
855
|
+
console.set_prompt_tokens(
|
856
|
+
(Token.OutPromptNum, "•"),
|
857
|
+
(Token.Prompt, ""), # will match arbitrary string,
|
858
|
+
(Token.Prompt, " ["),
|
859
|
+
(Token.PromptNum, "3"),
|
860
|
+
(Token.Prompt, "/"),
|
861
|
+
(Token.PromptNum, "1"),
|
862
|
+
(Token.Prompt, "] "),
|
863
|
+
(Token.Prompt, "❯❯"),
|
864
|
+
)
|
865
|
+
console.prompt.connect(check_prompt)
|
731
866
|
console.start()
|
732
867
|
|
733
868
|
# Show widget and launch Qt's event loop.
|
@@ -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=
|
5
|
+
CHANGELOG.md,sha256=tsLjli6mOqvULXg4ZhW3Un83h0N3EVMWlO8-XoDM6ac,7898
|
6
6
|
LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
|
7
|
-
PKG-INFO,sha256=
|
7
|
+
PKG-INFO,sha256=PITOTEI21SfFd0AnvPLVX4xld5y48S79WCqdRBfqWUU,1308
|
8
8
|
README.md,sha256=Od69x-RS85Hph0-WwWACwal4yUd67XkEn4APEfHhHFw,2649
|
9
|
-
pyproject.toml,sha256=
|
9
|
+
pyproject.toml,sha256=ITOEvWKMjOJbMjqOR4e4b-zFRDu428jAgVN-KRAlWvM,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=
|
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,9 @@ 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=
|
54
|
+
bec_widgets/qt_utils/toolbar.py,sha256=RcWoWjibhlpL26Bnbft-uWA1q2WCglJRnO6U3hGMBw8,13277
|
54
55
|
bec_widgets/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
56
|
bec_widgets/tests/utils.py,sha256=D1v3JLzzbnX3HXBQCjoFlNz5cYhjqrRkFcjx3yptMJA,6687
|
56
57
|
bec_widgets/utils/__init__.py,sha256=1930ji1Jj6dVuY81Wd2kYBhHYNV-2R0bN_L4o9zBj1U,533
|
@@ -197,7 +198,7 @@ bec_widgets/widgets/dap/lmfit_dialog/lmfit_dialog_vertical.ui,sha256=LQCQKQMcocd
|
|
197
198
|
bec_widgets/widgets/dap/lmfit_dialog/register_lm_fit_dialog.py,sha256=7tB1gsvv310_kVuKf2u4EdSR4F1posm7QCrWH5Kih-Q,480
|
198
199
|
bec_widgets/widgets/editors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
199
200
|
bec_widgets/widgets/editors/console/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
200
|
-
bec_widgets/widgets/editors/console/console.py,sha256=
|
201
|
+
bec_widgets/widgets/editors/console/console.py,sha256=RLzN-a2h27NLeQVjJiZRCtngRDPBmsGdouZ22bKbTUE,29327
|
201
202
|
bec_widgets/widgets/editors/console/console.pyproject,sha256=JcoDuZG03g1Bxkd3Aipo7jjLexujfbibIZqXHIgLSWc,26
|
202
203
|
bec_widgets/widgets/editors/console/console_plugin.py,sha256=EvFTruYDVHiS4pHIwZnuEvJhS9eQoktuB_k5mcPuEts,1357
|
203
204
|
bec_widgets/widgets/editors/console/register_console.py,sha256=zoF-i3R9sRGzb85sdoxVunebYOfOD53fkCELTPtrFRc,471
|
@@ -313,8 +314,8 @@ bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py,sha256=Z
|
|
313
314
|
bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.pyproject,sha256=Lbi9zb6HNlIq14k6hlzR-oz6PIFShBuF7QxE6d87d64,34
|
314
315
|
bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button_plugin.py,sha256=CzChz2SSETYsR8-36meqWnsXCT-FIy_J_xeU5coWDY8,1350
|
315
316
|
bec_widgets/widgets/utility/visual/dark_mode_button/register_dark_mode_button.py,sha256=rMpZ1CaoucwobgPj1FuKTnt07W82bV1GaSYdoqcdMb8,521
|
316
|
-
bec_widgets-1.
|
317
|
-
bec_widgets-1.
|
318
|
-
bec_widgets-1.
|
319
|
-
bec_widgets-1.
|
320
|
-
bec_widgets-1.
|
317
|
+
bec_widgets-1.8.0.dist-info/METADATA,sha256=PITOTEI21SfFd0AnvPLVX4xld5y48S79WCqdRBfqWUU,1308
|
318
|
+
bec_widgets-1.8.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
319
|
+
bec_widgets-1.8.0.dist-info/entry_points.txt,sha256=dItMzmwA1wizJ1Itx15qnfJ0ZzKVYFLVJ1voxT7K7D4,214
|
320
|
+
bec_widgets-1.8.0.dist-info/licenses/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
|
321
|
+
bec_widgets-1.8.0.dist-info/RECORD,,
|
pyproject.toml
CHANGED
File without changes
|
File without changes
|
File without changes
|