bec-widgets 0.99.15__py3-none-any.whl → 0.101.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 +24 -26
- PKG-INFO +1 -1
- bec_widgets/cli/client.py +30 -11
- bec_widgets/qt_utils/toolbar.py +2 -0
- bec_widgets/utils/bec_widget.py +56 -2
- bec_widgets/utils/colors.py +19 -23
- bec_widgets/widgets/dark_mode_button/dark_mode_button.py +14 -1
- bec_widgets/widgets/figure/plots/plot_base.py +14 -12
- bec_widgets/widgets/figure/plots/waveform/waveform.py +6 -5
- bec_widgets/widgets/lmfit_dialog/__init__.py +0 -0
- bec_widgets/widgets/lmfit_dialog/lm_fit_dialog.pyproject +1 -0
- bec_widgets/widgets/lmfit_dialog/lm_fit_dialog_plugin.py +54 -0
- bec_widgets/widgets/lmfit_dialog/lmfit_dialog.py +194 -0
- bec_widgets/widgets/lmfit_dialog/lmfit_dialog_compact.ui +120 -0
- bec_widgets/widgets/lmfit_dialog/lmfit_dialog_vertical.ui +147 -0
- bec_widgets/widgets/lmfit_dialog/register_lm_fit_dialog.py +15 -0
- bec_widgets/widgets/waveform/waveform_popups/dap_summary_dialog/dap_summary_dialog.py +15 -55
- bec_widgets/widgets/waveform/waveform_widget.py +8 -7
- {bec_widgets-0.99.15.dist-info → bec_widgets-0.101.0.dist-info}/METADATA +1 -1
- {bec_widgets-0.99.15.dist-info → bec_widgets-0.101.0.dist-info}/RECORD +24 -18
- pyproject.toml +1 -1
- bec_widgets/widgets/waveform/waveform_popups/dap_summary_dialog/dap_summary.ui +0 -127
- {bec_widgets-0.99.15.dist-info → bec_widgets-0.101.0.dist-info}/WHEEL +0 -0
- {bec_widgets-0.99.15.dist-info → bec_widgets-0.101.0.dist-info}/entry_points.txt +0 -0
- {bec_widgets-0.99.15.dist-info → bec_widgets-0.101.0.dist-info}/licenses/LICENSE +0 -0
CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## v0.101.0 (2024-09-02)
|
4
|
+
|
5
|
+
### Feature
|
6
|
+
|
7
|
+
* feat: add Dap dialog widget ([`9781b77`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9781b77de27b2810fbb1047a61b1832dd186db01))
|
8
|
+
|
9
|
+
### Refactor
|
10
|
+
|
11
|
+
* refactor: add docs, cleanup ([`61ecf49`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/61ecf491e52bfbfa0d5a84764a9095310659043d))
|
12
|
+
|
13
|
+
## v0.100.0 (2024-09-01)
|
14
|
+
|
15
|
+
### Documentation
|
16
|
+
|
17
|
+
* docs(becwidget): improvements to the bec widget base class docs; fixed type hint import for sphinx ([`99d5e8e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/99d5e8e71c7f89a53d7967126f4056dde005534c))
|
18
|
+
|
19
|
+
### Feature
|
20
|
+
|
21
|
+
* feat(theme): added theme handler to bec widget base class; added tests ([`7fb938a`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/7fb938a8506685278ee5eeb6fe9a03f74b713cf8))
|
22
|
+
|
23
|
+
### Fix
|
24
|
+
|
25
|
+
* fix(pyqt slot): removed slot decorator to avoid problems with pyqt6 ([`6c1f89a`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6c1f89ad39b7240ab1d1c1123422b99ae195bf01))
|
26
|
+
|
3
27
|
## v0.99.15 (2024-08-31)
|
4
28
|
|
5
29
|
### Fix
|
@@ -129,29 +153,3 @@
|
|
129
153
|
### Build
|
130
154
|
|
131
155
|
* build: updated min version of bec qthemes ([`d482434`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/d48243483ef8228cc5eb85e40a6b8f5da3b45520))
|
132
|
-
|
133
|
-
### Fix
|
134
|
-
|
135
|
-
* fix(cmaps): unified all defaults to magma cmap ([`1ca9499`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/1ca9499edd334c19fe1e7aac71d3940a80a1ec95))
|
136
|
-
|
137
|
-
* fix(color maps): color maps should take the background color into account; fixed min colors to 10 ([`060935f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/060935ffc5472a958c337bf60834c5291f104ece))
|
138
|
-
|
139
|
-
## v0.99.2 (2024-08-27)
|
140
|
-
|
141
|
-
### Ci
|
142
|
-
|
143
|
-
* ci: additional tests are not allowed to fail ([`bb385f0`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/bb385f07ca18904461a541b5cadde05398c84438))
|
144
|
-
|
145
|
-
### Fix
|
146
|
-
|
147
|
-
* fix(widgets): fixed default theme for widgets
|
148
|
-
|
149
|
-
If not theme is set, the init of the BECWidget base class sets the default theme to "dark" ([`cf28730`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/cf28730515e3c2d5914e0205768734c578711e5c))
|
150
|
-
|
151
|
-
## v0.99.1 (2024-08-27)
|
152
|
-
|
153
|
-
### Fix
|
154
|
-
|
155
|
-
* fix(crosshair): emit all crosshair events, not just line coordinates ([`2265458`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2265458dcc57970db18c62619f5877d542d72e81))
|
156
|
-
|
157
|
-
## v0.99.0 (2024-08-25)
|
PKG-INFO
CHANGED
bec_widgets/cli/client.py
CHANGED
@@ -26,6 +26,7 @@ class Widgets(str, enum.Enum):
|
|
26
26
|
DeviceBrowser = "DeviceBrowser"
|
27
27
|
DeviceComboBox = "DeviceComboBox"
|
28
28
|
DeviceLineEdit = "DeviceLineEdit"
|
29
|
+
LMFitDialog = "LMFitDialog"
|
29
30
|
PositionerBox = "PositionerBox"
|
30
31
|
PositionerControlLine = "PositionerControlLine"
|
31
32
|
ResetButton = "ResetButton"
|
@@ -1811,6 +1812,15 @@ class BECWaveform(RPCBase):
|
|
1811
1812
|
BECCurve: The curve object.
|
1812
1813
|
"""
|
1813
1814
|
|
1815
|
+
@rpc_call
|
1816
|
+
def get_dap_params(self) -> "dict":
|
1817
|
+
"""
|
1818
|
+
Get the DAP parameters of all DAP curves.
|
1819
|
+
|
1820
|
+
Returns:
|
1821
|
+
dict: DAP parameters of all DAP curves.
|
1822
|
+
"""
|
1823
|
+
|
1814
1824
|
@rpc_call
|
1815
1825
|
def set_x(self, x_name: "str", x_entry: "str | None" = None):
|
1816
1826
|
"""
|
@@ -1825,15 +1835,6 @@ class BECWaveform(RPCBase):
|
|
1825
1835
|
x_entry(str): Entry of the x signal.
|
1826
1836
|
"""
|
1827
1837
|
|
1828
|
-
@rpc_call
|
1829
|
-
def get_dap_params(self) -> "dict":
|
1830
|
-
"""
|
1831
|
-
Get the DAP parameters of all DAP curves.
|
1832
|
-
|
1833
|
-
Returns:
|
1834
|
-
dict: DAP parameters of all DAP curves.
|
1835
|
-
"""
|
1836
|
-
|
1837
1838
|
@rpc_call
|
1838
1839
|
def remove_curve(self, *identifiers):
|
1839
1840
|
"""
|
@@ -2096,10 +2097,10 @@ class BECWaveformWidget(RPCBase):
|
|
2096
2097
|
self,
|
2097
2098
|
x_name: "str",
|
2098
2099
|
y_name: "str",
|
2100
|
+
dap: "str",
|
2099
2101
|
x_entry: "str | None" = None,
|
2100
2102
|
y_entry: "str | None" = None,
|
2101
2103
|
color: "str | None" = None,
|
2102
|
-
dap: "str" = "GaussianModel",
|
2103
2104
|
validate_bec: "bool" = True,
|
2104
2105
|
**kwargs,
|
2105
2106
|
) -> "BECCurve":
|
@@ -2313,7 +2314,7 @@ class BECWaveformWidget(RPCBase):
|
|
2313
2314
|
|
2314
2315
|
class DarkModeButton(RPCBase):
|
2315
2316
|
@rpc_call
|
2316
|
-
def toggle_dark_mode(self) -> None:
|
2317
|
+
def toggle_dark_mode(self) -> "None":
|
2317
2318
|
"""
|
2318
2319
|
Toggle the dark mode state. This will change the theme of the entire
|
2319
2320
|
application to dark or light mode.
|
@@ -2392,6 +2393,24 @@ class DeviceLineEdit(RPCBase):
|
|
2392
2393
|
"""
|
2393
2394
|
|
2394
2395
|
|
2396
|
+
class LMFitDialog(RPCBase):
|
2397
|
+
@property
|
2398
|
+
@rpc_call
|
2399
|
+
def _config_dict(self) -> "dict":
|
2400
|
+
"""
|
2401
|
+
Get the configuration of the widget.
|
2402
|
+
|
2403
|
+
Returns:
|
2404
|
+
dict: The configuration of the widget.
|
2405
|
+
"""
|
2406
|
+
|
2407
|
+
@rpc_call
|
2408
|
+
def _get_all_rpc(self) -> "dict":
|
2409
|
+
"""
|
2410
|
+
Get all registered RPC objects.
|
2411
|
+
"""
|
2412
|
+
|
2413
|
+
|
2395
2414
|
class PositionerBox(RPCBase):
|
2396
2415
|
@rpc_call
|
2397
2416
|
def set_positioner(self, positioner: "str | Positioner"):
|
bec_widgets/qt_utils/toolbar.py
CHANGED
bec_widgets/utils/bec_widget.py
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from qtpy.QtCore import Slot
|
1
4
|
from qtpy.QtWidgets import QApplication, QWidget
|
2
5
|
|
3
6
|
from bec_widgets.utils.bec_connector import BECConnector, ConnectionConfig
|
@@ -11,7 +14,30 @@ class BECWidget(BECConnector):
|
|
11
14
|
# from fonts.google.com/icons. Override this in subclasses to set the icon name.
|
12
15
|
ICON_NAME = "widgets"
|
13
16
|
|
14
|
-
def __init__(
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
client=None,
|
20
|
+
config: ConnectionConfig = None,
|
21
|
+
gui_id: str = None,
|
22
|
+
theme_update: bool = False,
|
23
|
+
):
|
24
|
+
"""
|
25
|
+
Base class for all BEC widgets. This class should be used as a mixin class for all BEC widgets, e.g.:
|
26
|
+
|
27
|
+
|
28
|
+
>>> class MyWidget(BECWidget, QWidget):
|
29
|
+
>>> def __init__(self, parent=None, client=None, config=None, gui_id=None):
|
30
|
+
>>> super().__init__(client=client, config=config, gui_id=gui_id)
|
31
|
+
>>> QWidget.__init__(self, parent=parent)
|
32
|
+
|
33
|
+
|
34
|
+
Args:
|
35
|
+
client(BECClient, optional): The BEC client.
|
36
|
+
config(ConnectionConfig, optional): The connection configuration.
|
37
|
+
gui_id(str, optional): The GUI ID.
|
38
|
+
theme_update(bool, optional): Whether to subscribe to theme updates. Defaults to False. When set to True, the
|
39
|
+
widget's apply_theme method will be called when the theme changes.
|
40
|
+
"""
|
15
41
|
if not isinstance(self, QWidget):
|
16
42
|
raise RuntimeError(f"{repr(self)} is not a subclass of QWidget")
|
17
43
|
super().__init__(client, config, gui_id)
|
@@ -19,7 +45,35 @@ class BECWidget(BECConnector):
|
|
19
45
|
# Set the theme to auto if it is not set yet
|
20
46
|
app = QApplication.instance()
|
21
47
|
if not hasattr(app, "theme"):
|
22
|
-
set_theme("
|
48
|
+
set_theme("auto")
|
49
|
+
|
50
|
+
if theme_update:
|
51
|
+
self._connect_to_theme_change()
|
52
|
+
|
53
|
+
def _connect_to_theme_change(self):
|
54
|
+
"""Connect to the theme change signal."""
|
55
|
+
qapp = QApplication.instance()
|
56
|
+
if hasattr(qapp, "theme_signal"):
|
57
|
+
qapp.theme_signal.theme_updated.connect(self._update_theme)
|
58
|
+
|
59
|
+
def _update_theme(self, theme: str):
|
60
|
+
"""Update the theme."""
|
61
|
+
if theme is None:
|
62
|
+
qapp = QApplication.instance()
|
63
|
+
if hasattr(qapp, "theme"):
|
64
|
+
theme = qapp.theme["theme"]
|
65
|
+
else:
|
66
|
+
theme = "dark"
|
67
|
+
self.apply_theme(theme)
|
68
|
+
|
69
|
+
@Slot(str)
|
70
|
+
def apply_theme(self, theme: str):
|
71
|
+
"""
|
72
|
+
Apply the theme to the widget.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
theme(str, optional): The theme to be applied.
|
76
|
+
"""
|
23
77
|
|
24
78
|
def cleanup(self):
|
25
79
|
"""Cleanup the widget."""
|
bec_widgets/utils/colors.py
CHANGED
@@ -19,6 +19,17 @@ def get_theme_palette():
|
|
19
19
|
return bec_qthemes.load_palette(theme)
|
20
20
|
|
21
21
|
|
22
|
+
def _theme_update_callback():
|
23
|
+
"""
|
24
|
+
Internal callback function to update the theme based on the system theme.
|
25
|
+
"""
|
26
|
+
app = QApplication.instance()
|
27
|
+
# pylint: disable=protected-access
|
28
|
+
app.theme["theme"] = app.os_listener._theme.lower()
|
29
|
+
app.theme_signal.theme_updated.emit(app.theme["theme"])
|
30
|
+
apply_theme(app.os_listener._theme.lower())
|
31
|
+
|
32
|
+
|
22
33
|
def set_theme(theme: Literal["dark", "light", "auto"]):
|
23
34
|
"""
|
24
35
|
Set the theme for the application.
|
@@ -27,23 +38,17 @@ def set_theme(theme: Literal["dark", "light", "auto"]):
|
|
27
38
|
theme (Literal["dark", "light", "auto"]): The theme to set. "auto" will automatically switch between dark and light themes based on the system theme.
|
28
39
|
"""
|
29
40
|
app = QApplication.instance()
|
30
|
-
bec_qthemes.setup_theme(theme)
|
31
|
-
|
41
|
+
bec_qthemes.setup_theme(theme, install_event_filter=False)
|
42
|
+
|
32
43
|
app.theme_signal.theme_updated.emit(theme)
|
33
44
|
apply_theme(theme)
|
34
45
|
|
35
|
-
# pylint: disable=protected-access
|
36
46
|
if theme != "auto":
|
37
47
|
return
|
38
48
|
|
39
|
-
|
40
|
-
app.
|
41
|
-
app.
|
42
|
-
apply_theme(listener._theme.lower())
|
43
|
-
|
44
|
-
listener = OSThemeSwitchListener(callback)
|
45
|
-
|
46
|
-
app.installEventFilter(listener)
|
49
|
+
if not hasattr(app, "os_listener") or app.os_listener is None:
|
50
|
+
app.os_listener = OSThemeSwitchListener(_theme_update_callback)
|
51
|
+
app.installEventFilter(app.os_listener)
|
47
52
|
|
48
53
|
|
49
54
|
def apply_theme(theme: Literal["dark", "light"]):
|
@@ -55,21 +60,12 @@ def apply_theme(theme: Literal["dark", "light"]):
|
|
55
60
|
children = itertools.chain.from_iterable(
|
56
61
|
top.findChildren(pg.GraphicsLayoutWidget) for top in app.topLevelWidgets()
|
57
62
|
)
|
58
|
-
pg.setConfigOptions(
|
63
|
+
pg.setConfigOptions(
|
64
|
+
foreground="d" if theme == "dark" else "k", background="k" if theme == "dark" else "w"
|
65
|
+
)
|
59
66
|
for pg_widget in children:
|
60
67
|
pg_widget.setBackground("k" if theme == "dark" else "w")
|
61
68
|
|
62
|
-
dark_mode_buttons = [
|
63
|
-
button
|
64
|
-
for button in app.topLevelWidgets()
|
65
|
-
if hasattr(button, "dark_mode_enabled")
|
66
|
-
and hasattr(button, "mode_button")
|
67
|
-
and isinstance(button.mode_button, (QPushButton, QToolButton))
|
68
|
-
]
|
69
|
-
|
70
|
-
for button in dark_mode_buttons:
|
71
|
-
button.dark_mode_enabled = theme == "dark"
|
72
|
-
button.update_mode_button()
|
73
69
|
# now define stylesheet according to theme and apply it
|
74
70
|
style = bec_qthemes.load_stylesheet(theme)
|
75
71
|
app.setStyleSheet(style)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
from bec_qthemes import material_icon
|
2
4
|
from qtpy.QtCore import Property, Qt, Slot
|
3
5
|
from qtpy.QtWidgets import QApplication, QHBoxLayout, QPushButton, QToolButton, QWidget
|
@@ -18,7 +20,7 @@ class DarkModeButton(BECWidget, QWidget):
|
|
18
20
|
gui_id: str | None = None,
|
19
21
|
toolbar: bool = False,
|
20
22
|
) -> None:
|
21
|
-
super().__init__(client=client, gui_id=gui_id)
|
23
|
+
super().__init__(client=client, gui_id=gui_id, theme_update=True)
|
22
24
|
QWidget.__init__(self, parent)
|
23
25
|
|
24
26
|
self._dark_mode_enabled = False
|
@@ -39,6 +41,17 @@ class DarkModeButton(BECWidget, QWidget):
|
|
39
41
|
self.setLayout(self.layout)
|
40
42
|
self.setFixedSize(40, 40)
|
41
43
|
|
44
|
+
@Slot(str)
|
45
|
+
def apply_theme(self, theme: str):
|
46
|
+
"""
|
47
|
+
Apply the theme to the widget.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
theme(str, optional): The theme to be applied.
|
51
|
+
"""
|
52
|
+
self.dark_mode_enabled = theme == "dark"
|
53
|
+
self.update_mode_button()
|
54
|
+
|
42
55
|
def _get_qapp_dark_mode_state(self) -> bool:
|
43
56
|
"""
|
44
57
|
Get the dark mode state from the QApplication.
|
@@ -99,30 +99,32 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
|
99
99
|
|
100
100
|
self.add_legend()
|
101
101
|
self.crosshair = None
|
102
|
-
self.
|
103
|
-
self.apply_theme()
|
102
|
+
self._connect_to_theme_change()
|
104
103
|
|
105
|
-
def
|
104
|
+
def _connect_to_theme_change(self):
|
106
105
|
"""Connect to the theme change signal."""
|
107
106
|
qapp = QApplication.instance()
|
108
107
|
if hasattr(qapp, "theme_signal"):
|
109
|
-
qapp.theme_signal.theme_updated.connect(self.
|
108
|
+
qapp.theme_signal.theme_updated.connect(self._update_theme)
|
110
109
|
|
111
110
|
@Slot(str)
|
112
|
-
|
113
|
-
|
114
|
-
"""
|
115
|
-
Apply the theme to the plot widget.
|
116
|
-
|
117
|
-
Args:
|
118
|
-
theme(str, optional): The theme to be applied.
|
119
|
-
"""
|
111
|
+
def _update_theme(self, theme: str):
|
112
|
+
"""Update the theme."""
|
120
113
|
if theme is None:
|
121
114
|
qapp = QApplication.instance()
|
122
115
|
if hasattr(qapp, "theme"):
|
123
116
|
theme = qapp.theme["theme"]
|
124
117
|
else:
|
125
118
|
theme = "dark"
|
119
|
+
self.apply_theme(theme)
|
120
|
+
|
121
|
+
def apply_theme(self, theme: str):
|
122
|
+
"""
|
123
|
+
Apply the theme to the plot widget.
|
124
|
+
|
125
|
+
Args:
|
126
|
+
theme(str, optional): The theme to be applied.
|
127
|
+
"""
|
126
128
|
palette = bec_qthemes.load_palette(theme)
|
127
129
|
text_pen = pg.mkPen(color=palette.text().color())
|
128
130
|
|
@@ -49,8 +49,8 @@ class BECWaveform(BECPlotBase):
|
|
49
49
|
"_config_dict",
|
50
50
|
"plot",
|
51
51
|
"add_dap",
|
52
|
-
"set_x",
|
53
52
|
"get_dap_params",
|
53
|
+
"set_x",
|
54
54
|
"remove_curve",
|
55
55
|
"scan_history",
|
56
56
|
"curves",
|
@@ -74,8 +74,8 @@ class BECWaveform(BECPlotBase):
|
|
74
74
|
]
|
75
75
|
scan_signal_update = pyqtSignal()
|
76
76
|
async_signal_update = pyqtSignal()
|
77
|
-
dap_params_update = pyqtSignal(dict)
|
78
|
-
dap_summary_update = pyqtSignal(dict)
|
77
|
+
dap_params_update = pyqtSignal(dict, dict)
|
78
|
+
dap_summary_update = pyqtSignal(dict, dict)
|
79
79
|
autorange_signal = pyqtSignal()
|
80
80
|
new_scan = pyqtSignal()
|
81
81
|
|
@@ -1085,8 +1085,9 @@ class BECWaveform(BECPlotBase):
|
|
1085
1085
|
curve.setData(x, y)
|
1086
1086
|
curve.dap_params = msg["data"][1]["fit_parameters"]
|
1087
1087
|
curve.dap_summary = msg["data"][1]["fit_summary"]
|
1088
|
-
|
1089
|
-
self.
|
1088
|
+
metadata.update({"curve_id": curve_id_request})
|
1089
|
+
self.dap_params_update.emit(curve.dap_params, metadata)
|
1090
|
+
self.dap_summary_update.emit(curve.dap_summary, metadata)
|
1090
1091
|
break
|
1091
1092
|
|
1092
1093
|
@Slot(dict, dict)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{'files': ['lmfit_dialog.py']}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2022 The Qt Company Ltd.
|
2
|
+
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
3
|
+
|
4
|
+
from qtpy.QtDesigner import QDesignerCustomWidgetInterface
|
5
|
+
|
6
|
+
from bec_widgets.utils.bec_designer import designer_material_icon
|
7
|
+
from bec_widgets.widgets.lmfit_dialog.lmfit_dialog import LMFitDialog
|
8
|
+
|
9
|
+
DOM_XML = """
|
10
|
+
<ui language='c++'>
|
11
|
+
<widget class='LMFitDialog' name='lm_fit_dialog'>
|
12
|
+
</widget>
|
13
|
+
</ui>
|
14
|
+
"""
|
15
|
+
|
16
|
+
|
17
|
+
class LMFitDialogPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
18
|
+
def __init__(self):
|
19
|
+
super().__init__()
|
20
|
+
self._form_editor = None
|
21
|
+
|
22
|
+
def createWidget(self, parent):
|
23
|
+
t = LMFitDialog(parent)
|
24
|
+
return t
|
25
|
+
|
26
|
+
def domXml(self):
|
27
|
+
return DOM_XML
|
28
|
+
|
29
|
+
def group(self):
|
30
|
+
return "BEC Utils"
|
31
|
+
|
32
|
+
def icon(self):
|
33
|
+
return designer_material_icon(LMFitDialog.ICON_NAME)
|
34
|
+
|
35
|
+
def includeFile(self):
|
36
|
+
return "lm_fit_dialog"
|
37
|
+
|
38
|
+
def initialize(self, form_editor):
|
39
|
+
self._form_editor = form_editor
|
40
|
+
|
41
|
+
def isContainer(self):
|
42
|
+
return False
|
43
|
+
|
44
|
+
def isInitialized(self):
|
45
|
+
return self._form_editor is not None
|
46
|
+
|
47
|
+
def name(self):
|
48
|
+
return "LMFitDialog"
|
49
|
+
|
50
|
+
def toolTip(self):
|
51
|
+
return "LMFitDialog"
|
52
|
+
|
53
|
+
def whatsThis(self):
|
54
|
+
return self.toolTip()
|
@@ -0,0 +1,194 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from bec_lib.endpoints import MessageEndpoints
|
4
|
+
from bec_lib.logger import bec_logger
|
5
|
+
from qtpy.QtCore import Property, Signal, Slot
|
6
|
+
from qtpy.QtWidgets import QTreeWidgetItem, QVBoxLayout, QWidget
|
7
|
+
|
8
|
+
from bec_widgets.utils import UILoader
|
9
|
+
from bec_widgets.utils.bec_widget import BECWidget
|
10
|
+
|
11
|
+
logger = bec_logger.logger
|
12
|
+
|
13
|
+
|
14
|
+
class LMFitDialog(BECWidget, QWidget):
|
15
|
+
"""Dialog for displaying the fit summary and params for LMFit DAP processes"""
|
16
|
+
|
17
|
+
ICON_NAME = "monitoring"
|
18
|
+
selected_fit = Signal(str)
|
19
|
+
|
20
|
+
def __init__(
|
21
|
+
self,
|
22
|
+
parent=None,
|
23
|
+
client=None,
|
24
|
+
config=None,
|
25
|
+
target_widget=None,
|
26
|
+
gui_id: str | None = None,
|
27
|
+
ui_file="lmfit_dialog_vertical.ui",
|
28
|
+
):
|
29
|
+
"""
|
30
|
+
Initialises the LMFitDialog widget.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
parent (QWidget): The parent widget.
|
34
|
+
client: BEC client object.
|
35
|
+
config: Configuration of the widget.
|
36
|
+
target_widget: The widget that the settings will be taken from and applied to.
|
37
|
+
gui_id (str): GUI ID.
|
38
|
+
ui_file (str): The UI file to be loaded.
|
39
|
+
"""
|
40
|
+
super().__init__(client=client, config=config, gui_id=gui_id)
|
41
|
+
QWidget.__init__(self, parent=parent)
|
42
|
+
self._ui_file = ui_file
|
43
|
+
self.target_widget = target_widget
|
44
|
+
|
45
|
+
current_path = os.path.dirname(__file__)
|
46
|
+
self.ui = UILoader(self).loader(os.path.join(current_path, self._ui_file))
|
47
|
+
self.layout = QVBoxLayout(self)
|
48
|
+
self.layout.addWidget(self.ui)
|
49
|
+
self.summary_data = {}
|
50
|
+
self._fit_curve_id = None
|
51
|
+
self._deci_precision = 3
|
52
|
+
self.ui.curve_list.currentItemChanged.connect(self.display_fit_details)
|
53
|
+
self.layout.setContentsMargins(0, 0, 0, 0)
|
54
|
+
self.setLayout(self.layout)
|
55
|
+
|
56
|
+
@Property(bool)
|
57
|
+
def hide_curve_selection(self):
|
58
|
+
"""Property for showing the curve selection."""
|
59
|
+
return not self.ui.group_curve_selection.isVisible()
|
60
|
+
|
61
|
+
@hide_curve_selection.setter
|
62
|
+
def hide_curve_selection(self, show: bool):
|
63
|
+
"""Setter for showing the curve selection.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
show (bool): Whether to show the curve selection.
|
67
|
+
"""
|
68
|
+
self.ui.group_curve_selection.setVisible(not show)
|
69
|
+
|
70
|
+
@property
|
71
|
+
def fit_curve_id(self):
|
72
|
+
"""Property for the currently displayed fit curve_id."""
|
73
|
+
return self._fit_curve_id
|
74
|
+
|
75
|
+
@fit_curve_id.setter
|
76
|
+
def fit_curve_id(self, curve_id: str):
|
77
|
+
"""Setter for the currently displayed fit curve_id.
|
78
|
+
|
79
|
+
Args:
|
80
|
+
fit_curve_id (str): The curve_id of the fit curve to be displayed.
|
81
|
+
"""
|
82
|
+
self._fit_curve_id = curve_id
|
83
|
+
self.selected_fit.emit(curve_id)
|
84
|
+
|
85
|
+
@Slot(str)
|
86
|
+
def remove_dap_data(self, curve_id: str):
|
87
|
+
"""Remove the DAP data for the given curve_id.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
curve_id (str): The curve_id of the DAP data to be removed.
|
91
|
+
"""
|
92
|
+
self.summary_data.pop(curve_id, None)
|
93
|
+
self.refresh_curve_list()
|
94
|
+
|
95
|
+
@Slot(str)
|
96
|
+
def select_curve(self, curve_id: str):
|
97
|
+
"""Select active curve_id in the curve list.
|
98
|
+
|
99
|
+
Args:
|
100
|
+
curve_id (str): curve_id to be selected.
|
101
|
+
"""
|
102
|
+
self.fit_curve_id = curve_id
|
103
|
+
|
104
|
+
@Slot(dict, dict)
|
105
|
+
def update_summary_tree(self, data: dict, metadata: dict):
|
106
|
+
"""Update the summary tree with the given data.
|
107
|
+
|
108
|
+
Args:
|
109
|
+
data (dict): Data for the DAP Summary.
|
110
|
+
metadata (dict): Metadata of the fit curve.
|
111
|
+
"""
|
112
|
+
curve_id = metadata.get("curve_id", "")
|
113
|
+
self.summary_data.update({curve_id: data})
|
114
|
+
self.refresh_curve_list()
|
115
|
+
if self.fit_curve_id is None:
|
116
|
+
self.fit_curve_id = curve_id
|
117
|
+
if curve_id != self.fit_curve_id:
|
118
|
+
return
|
119
|
+
if data is None:
|
120
|
+
return
|
121
|
+
self.ui.summary_tree.clear()
|
122
|
+
properties = [
|
123
|
+
("Model", data.get("model", "")),
|
124
|
+
("Method", data.get("method", "")),
|
125
|
+
("Chi-Squared", f"{data.get('chisqr', 0.0):.{self._deci_precision}f}"),
|
126
|
+
("Reduced Chi-Squared", f"{data.get('redchi', 0.0):.{self._deci_precision}f}"),
|
127
|
+
("R-Squared", f"{data.get('rsquared', 0.0):.{self._deci_precision}f}"),
|
128
|
+
("Message", data.get("message", "")),
|
129
|
+
]
|
130
|
+
for prop, val in properties:
|
131
|
+
QTreeWidgetItem(self.ui.summary_tree, [prop, val])
|
132
|
+
self.update_param_tree(data.get("params", []))
|
133
|
+
|
134
|
+
def _update_summary_data(self, curve_id: str, data: dict):
|
135
|
+
"""Update the summary data with the given data.
|
136
|
+
|
137
|
+
Args:
|
138
|
+
curve_id (str): The curve_id of the fit curve.
|
139
|
+
data (dict): The data to be updated.
|
140
|
+
"""
|
141
|
+
self.summary_data.update({curve_id: data})
|
142
|
+
if self.fit_curve_id is not None:
|
143
|
+
return
|
144
|
+
self.fit_curve_id = curve_id
|
145
|
+
|
146
|
+
def update_param_tree(self, params):
|
147
|
+
"""Update the parameter tree with the given parameters.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
params (list): List of LMFit parameters for the fit curve.
|
151
|
+
"""
|
152
|
+
self.ui.param_tree.clear()
|
153
|
+
for param in params:
|
154
|
+
param_name, param_value, param_std = (
|
155
|
+
param[0],
|
156
|
+
f"{param[1]:.{self._deci_precision}f}",
|
157
|
+
f"{param[7]:.{self._deci_precision}f}",
|
158
|
+
)
|
159
|
+
QTreeWidgetItem(self.ui.param_tree, [param_name, param_value, param_std])
|
160
|
+
|
161
|
+
def populate_curve_list(self):
|
162
|
+
"""Populate the curve list with the available fit curves."""
|
163
|
+
for curve_name in self.summary_data.keys():
|
164
|
+
self.ui.curve_list.addItem(curve_name)
|
165
|
+
|
166
|
+
def refresh_curve_list(self):
|
167
|
+
"""Refresh the curve list with the updated data."""
|
168
|
+
self.ui.curve_list.clear()
|
169
|
+
self.populate_curve_list()
|
170
|
+
|
171
|
+
def display_fit_details(self, current):
|
172
|
+
"""Callback for displaying the fit details of the selected curve.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
current: The current item in the curve list.
|
176
|
+
"""
|
177
|
+
if current:
|
178
|
+
curve_name = current.text()
|
179
|
+
self.fit_curve_id = curve_name
|
180
|
+
data = self.summary_data[curve_name]
|
181
|
+
if data is None:
|
182
|
+
return
|
183
|
+
self.update_summary_tree(data, {"curve_id": curve_name})
|
184
|
+
|
185
|
+
|
186
|
+
if __name__ == "__main__":
|
187
|
+
import sys
|
188
|
+
|
189
|
+
from qtpy.QtWidgets import QApplication
|
190
|
+
|
191
|
+
app = QApplication(sys.argv)
|
192
|
+
dialog = LMFitDialog()
|
193
|
+
dialog.show()
|
194
|
+
sys.exit(app.exec_())
|