solprop-gui 0.2.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.
- solprop_gui/__init__.py +24 -0
- solprop_gui/__main__.py +11 -0
- solprop_gui/app.py +67 -0
- solprop_gui/classes/__init__.py +9 -0
- solprop_gui/classes/catalog.py +854 -0
- solprop_gui/classes/problem.py +868 -0
- solprop_gui/classes/workflow.py +139 -0
- solprop_gui/help/__init__.py +7 -0
- solprop_gui/help/figures/antiresonant.svg +70 -0
- solprop_gui/help/figures/capillary-averaged.svg +63 -0
- solprop_gui/help/figures/capillary-modal.svg +65 -0
- solprop_gui/help/figures/cartesian.svg +164 -0
- solprop_gui/help/figures/gnlse.svg +64 -0
- solprop_gui/help/figures/grin.svg +63 -0
- solprop_gui/help/figures/line.svg +84 -0
- solprop_gui/help/figures/radial.svg +68 -0
- solprop_gui/help/figures/rectangular.svg +63 -0
- solprop_gui/help/figures/slab.svg +68 -0
- solprop_gui/help/figures/step-index.svg +63 -0
- solprop_gui/help/figures.py +106 -0
- solprop_gui/help/guide/analysis.md +96 -0
- solprop_gui/help/guide/classes.md +94 -0
- solprop_gui/help/guide/design.md +59 -0
- solprop_gui/help/guide/first-run.md +101 -0
- solprop_gui/help/guide/images/capillary-along.png +0 -0
- solprop_gui/help/guide/images/capillary-overview.png +0 -0
- solprop_gui/help/guide/images/capillary-plane.png +0 -0
- solprop_gui/help/guide/images/capillary-run.png +0 -0
- solprop_gui/help/guide/images/capillary-sheet.png +0 -0
- solprop_gui/help/guide/images/capillary-target.png +0 -0
- solprop_gui/help/guide/images/design.png +0 -0
- solprop_gui/help/guide/images/filament-overview.png +0 -0
- solprop_gui/help/guide/images/filament-sheet.png +0 -0
- solprop_gui/help/guide/images/home.png +0 -0
- solprop_gui/help/guide/images/plot-menu.png +0 -0
- solprop_gui/help/guide/images/scan.png +0 -0
- solprop_gui/help/guide/index.md +104 -0
- solprop_gui/help/guide/scans.md +55 -0
- solprop_gui/help/guide.py +48 -0
- solprop_gui/help/manual.py +199 -0
- solprop_gui/model/__init__.py +12 -0
- solprop_gui/model/compressor.py +407 -0
- solprop_gui/model/display.py +501 -0
- solprop_gui/model/plot_options.py +343 -0
- solprop_gui/model/quantities.py +179 -0
- solprop_gui/model/recipe.py +473 -0
- solprop_gui/model/scans.py +288 -0
- solprop_gui/model/snippets.py +118 -0
- solprop_gui/model/stats_layout.py +115 -0
- solprop_gui/model/values.py +195 -0
- solprop_gui/model/workspace.py +151 -0
- solprop_gui/py.typed +0 -0
- solprop_gui/registry/__init__.py +12 -0
- solprop_gui/registry/explore.py +481 -0
- solprop_gui/registry/pages.py +273 -0
- solprop_gui/registry/routes.py +450 -0
- solprop_gui/registry/units.py +135 -0
- solprop_gui/service/__init__.py +12 -0
- solprop_gui/service/beam.py +226 -0
- solprop_gui/service/beams.py +257 -0
- solprop_gui/service/client.py +398 -0
- solprop_gui/service/design.py +362 -0
- solprop_gui/service/figures.py +106 -0
- solprop_gui/service/handlers.py +709 -0
- solprop_gui/service/kernel.py +187 -0
- solprop_gui/service/messages.py +210 -0
- solprop_gui/service/outbox.py +139 -0
- solprop_gui/service/postprocess.py +513 -0
- solprop_gui/service/reduce.py +368 -0
- solprop_gui/service/remote.py +513 -0
- solprop_gui/service/results.py +951 -0
- solprop_gui/service/run.py +648 -0
- solprop_gui/service/scan_reductions.py +261 -0
- solprop_gui/service/server.py +501 -0
- solprop_gui/service/sheet.py +1023 -0
- solprop_gui/service/states.py +146 -0
- solprop_gui/service/waveguide.py +320 -0
- solprop_gui/service/worker.py +97 -0
- solprop_gui/ui/__init__.py +11 -0
- solprop_gui/ui/analyse.py +808 -0
- solprop_gui/ui/analysis.py +338 -0
- solprop_gui/ui/analysis_pages.py +2954 -0
- solprop_gui/ui/assets/chevron.svg +6 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-Medium.ttf +0 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-Regular.ttf +0 -0
- solprop_gui/ui/assets/fonts/IBMPlexSans-SemiBold.ttf +0 -0
- solprop_gui/ui/assets/fonts/LICENSE.txt +93 -0
- solprop_gui/ui/assets/icon/solprop-1024.png +0 -0
- solprop_gui/ui/assets/icon/solprop-128.png +0 -0
- solprop_gui/ui/assets/icon/solprop-16.png +0 -0
- solprop_gui/ui/assets/icon/solprop-24.png +0 -0
- solprop_gui/ui/assets/icon/solprop-256.png +0 -0
- solprop_gui/ui/assets/icon/solprop-32.png +0 -0
- solprop_gui/ui/assets/icon/solprop-48.png +0 -0
- solprop_gui/ui/assets/icon/solprop-512.png +0 -0
- solprop_gui/ui/assets/icon/solprop-64.png +0 -0
- solprop_gui/ui/assets/icon/solprop-compact.svg +19 -0
- solprop_gui/ui/assets/icon/solprop.svg +20 -0
- solprop_gui/ui/betas.py +245 -0
- solprop_gui/ui/bridge.py +258 -0
- solprop_gui/ui/design_stage.py +956 -0
- solprop_gui/ui/document.py +693 -0
- solprop_gui/ui/fields.py +812 -0
- solprop_gui/ui/help_window.py +214 -0
- solprop_gui/ui/home.py +291 -0
- solprop_gui/ui/icons.py +191 -0
- solprop_gui/ui/identity.py +230 -0
- solprop_gui/ui/launch.py +261 -0
- solprop_gui/ui/objects.py +530 -0
- solprop_gui/ui/pages.py +436 -0
- solprop_gui/ui/pin.py +286 -0
- solprop_gui/ui/plot_options.py +439 -0
- solprop_gui/ui/postprocess.py +532 -0
- solprop_gui/ui/quantity.py +532 -0
- solprop_gui/ui/results.py +482 -0
- solprop_gui/ui/run_options.py +179 -0
- solprop_gui/ui/run_panel.py +767 -0
- solprop_gui/ui/scan_editor.py +421 -0
- solprop_gui/ui/scan_stage.py +724 -0
- solprop_gui/ui/sheet.py +1371 -0
- solprop_gui/ui/theme.py +247 -0
- solprop_gui/ui/tile_art.py +146 -0
- solprop_gui/ui/workflow_window.py +1332 -0
- solprop_gui/views/__init__.py +11 -0
- solprop_gui/views/compare.py +114 -0
- solprop_gui/views/compression.py +146 -0
- solprop_gui/views/controls.py +211 -0
- solprop_gui/views/cross_section.py +124 -0
- solprop_gui/views/live.py +704 -0
- solprop_gui/views/page_plots.py +1073 -0
- solprop_gui/views/plane.py +650 -0
- solprop_gui/views/plotting.py +381 -0
- solprop_gui/views/scan_browser.py +149 -0
- solprop_gui/views/sparkline.py +131 -0
- solprop_gui/views/splitter.py +141 -0
- solprop_gui/views/statistics.py +501 -0
- solprop_gui-0.2.0.dist-info/METADATA +92 -0
- solprop_gui-0.2.0.dist-info/RECORD +143 -0
- solprop_gui-0.2.0.dist-info/WHEEL +4 -0
- solprop_gui-0.2.0.dist-info/entry_points.txt +2 -0
- solprop_gui-0.2.0.dist-info/licenses/LICENSE +674 -0
- solprop_gui-0.2.0.dist-info/licenses/LICENSE-CC-BY-4.0.txt +156 -0
- solprop_gui-0.2.0.dist-info/licenses/src/solprop_gui/ui/assets/fonts/LICENSE.txt +93 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
"""What the application is: its icon, its name to the system, and its About dialog.
|
|
6
|
+
|
|
7
|
+
The icon is ``assets/icon/``, drawn by ``gui/tools/app_icon.py``: PNGs from 16 to 1024
|
|
8
|
+
pixels, so each platform takes the size it draws. macOS shows the window icon in the
|
|
9
|
+
dock; Windows groups the taskbar button under the process's application id, which is
|
|
10
|
+
set before the first window so that the button shows this icon rather than Python's;
|
|
11
|
+
Linux desktops match the window to a ``solprop-gui.desktop`` file by its name.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import ctypes
|
|
15
|
+
import platform
|
|
16
|
+
import sys
|
|
17
|
+
from importlib.metadata import PackageNotFoundError, metadata
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Final
|
|
20
|
+
|
|
21
|
+
from PySide6 import __version__ as pyside_version
|
|
22
|
+
from PySide6.QtCore import Qt
|
|
23
|
+
from PySide6.QtGui import QIcon
|
|
24
|
+
from PySide6.QtWidgets import (
|
|
25
|
+
QApplication,
|
|
26
|
+
QDialog,
|
|
27
|
+
QDialogButtonBox,
|
|
28
|
+
QHBoxLayout,
|
|
29
|
+
QLabel,
|
|
30
|
+
QVBoxLayout,
|
|
31
|
+
QWidget,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from solprop_gui import __version__
|
|
35
|
+
from solprop_gui.help.guide import MANUAL
|
|
36
|
+
from solprop_gui.ui.theme import named_label
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"APP_ID",
|
|
40
|
+
"LINKS",
|
|
41
|
+
"AboutDialog",
|
|
42
|
+
"app_icon",
|
|
43
|
+
"apply_identity",
|
|
44
|
+
"authors",
|
|
45
|
+
"set_windows_app_id",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
_ICON: Final = Path(__file__).resolve().parent / "assets" / "icon"
|
|
49
|
+
"""The icon's renderings."""
|
|
50
|
+
|
|
51
|
+
APP_ID: Final = "LupoLab.solprop.gui"
|
|
52
|
+
"""The application id Windows groups the taskbar button by."""
|
|
53
|
+
|
|
54
|
+
LINKS: Final = {
|
|
55
|
+
"manual": MANUAL,
|
|
56
|
+
"guide": MANUAL + "guide/front-end/index.html",
|
|
57
|
+
"source": "https://github.com/LupoLab/solprop",
|
|
58
|
+
"issues": "https://github.com/LupoLab/solprop/issues",
|
|
59
|
+
"pypi": "https://pypi.org/project/solprop/",
|
|
60
|
+
}
|
|
61
|
+
"""Where the project lives."""
|
|
62
|
+
|
|
63
|
+
COPYRIGHT: Final = "© 2026 John C. Travers and contributors"
|
|
64
|
+
"""The copyright line, as the source files' SPDX headers give it."""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def app_icon() -> QIcon:
|
|
68
|
+
"""Return the application's icon, with every size drawn.
|
|
69
|
+
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
PySide6.QtGui.QIcon
|
|
73
|
+
The icon; empty if its files are missing.
|
|
74
|
+
"""
|
|
75
|
+
icon = QIcon()
|
|
76
|
+
for path in sorted(_ICON.glob("solprop-*.png")):
|
|
77
|
+
icon.addFile(str(path))
|
|
78
|
+
return icon
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def set_windows_app_id() -> bool:
|
|
82
|
+
"""Give the process its own application id on Windows, before any window.
|
|
83
|
+
|
|
84
|
+
Without it Windows groups the window under ``python.exe`` and shows Python's icon on
|
|
85
|
+
the taskbar.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
bool
|
|
90
|
+
Whether it was set: only on Windows.
|
|
91
|
+
"""
|
|
92
|
+
if sys.platform != "win32":
|
|
93
|
+
return False
|
|
94
|
+
shell = ctypes.windll.shell32 # pyright: ignore[reportAttributeAccessIssue]
|
|
95
|
+
shell.SetCurrentProcessExplicitAppUserModelID(APP_ID)
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def apply_identity(application: QApplication) -> None:
|
|
100
|
+
"""Name the application to the system and give it its icon.
|
|
101
|
+
|
|
102
|
+
Parameters
|
|
103
|
+
----------
|
|
104
|
+
application : PySide6.QtWidgets.QApplication
|
|
105
|
+
The application.
|
|
106
|
+
"""
|
|
107
|
+
application.setApplicationName("solprop")
|
|
108
|
+
application.setApplicationVersion(__version__)
|
|
109
|
+
application.setDesktopFileName("solprop-gui")
|
|
110
|
+
application.setWindowIcon(app_icon())
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def authors() -> list[str]:
|
|
114
|
+
"""Return the package's authors, as its metadata names them.
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
list of str
|
|
119
|
+
Each author's name, without an address; solprop's own when the metadata is
|
|
120
|
+
missing.
|
|
121
|
+
"""
|
|
122
|
+
try:
|
|
123
|
+
found = metadata("solprop-gui")
|
|
124
|
+
except PackageNotFoundError:
|
|
125
|
+
return ["John C. Travers", "Christian Brahms"]
|
|
126
|
+
names: list[str] = []
|
|
127
|
+
# Those with an address come first, as solprop's metadata lists them.
|
|
128
|
+
for field in ("Author-email", "Author"):
|
|
129
|
+
for entry in found.get_all(field) or []:
|
|
130
|
+
for person in str(entry).split(","):
|
|
131
|
+
name = person.split("<", 1)[0].strip().strip('"')
|
|
132
|
+
if name and name not in names:
|
|
133
|
+
names.append(name)
|
|
134
|
+
return names
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _solprop_version() -> str:
|
|
138
|
+
"""Return the installed solprop's version.
|
|
139
|
+
|
|
140
|
+
Returns
|
|
141
|
+
-------
|
|
142
|
+
str
|
|
143
|
+
The version, or ``unknown``.
|
|
144
|
+
"""
|
|
145
|
+
try:
|
|
146
|
+
return str(metadata("solprop")["Version"])
|
|
147
|
+
except PackageNotFoundError:
|
|
148
|
+
return "unknown"
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class AboutDialog(QDialog):
|
|
152
|
+
"""Who made solprop, which versions are running, and where the project lives.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
parent : PySide6.QtWidgets.QWidget or None, optional
|
|
157
|
+
The owner.
|
|
158
|
+
|
|
159
|
+
Attributes
|
|
160
|
+
----------
|
|
161
|
+
versions : PySide6.QtWidgets.QLabel
|
|
162
|
+
The versions of the front end, solprop, Qt and Python.
|
|
163
|
+
links : PySide6.QtWidgets.QLabel
|
|
164
|
+
The manual, the source, the issues and the package index.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
168
|
+
"""Lay the dialog out."""
|
|
169
|
+
super().__init__(parent)
|
|
170
|
+
self.setWindowTitle("About solprop")
|
|
171
|
+
self.setObjectName("page")
|
|
172
|
+
picture = QLabel()
|
|
173
|
+
picture.setPixmap(app_icon().pixmap(96, 96))
|
|
174
|
+
picture.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
175
|
+
title = named_label("solprop", "h2")
|
|
176
|
+
summary = named_label(
|
|
177
|
+
"Ultrafast nonlinear pulse propagation in waveguides and free space, "
|
|
178
|
+
"set up, run and read in one window.",
|
|
179
|
+
"note",
|
|
180
|
+
)
|
|
181
|
+
summary.setWordWrap(True)
|
|
182
|
+
self.versions = named_label(
|
|
183
|
+
f"solprop-gui {__version__} · solprop {_solprop_version()} · "
|
|
184
|
+
f"Qt {pyside_version} · Python {platform.python_version()}",
|
|
185
|
+
"note",
|
|
186
|
+
)
|
|
187
|
+
self.versions.setWordWrap(True)
|
|
188
|
+
self.versions.setTextInteractionFlags(
|
|
189
|
+
Qt.TextInteractionFlag.TextSelectableByMouse
|
|
190
|
+
)
|
|
191
|
+
self.links = QLabel(
|
|
192
|
+
" · ".join(
|
|
193
|
+
f'<a href="{LINKS[key]}">{text}</a>'
|
|
194
|
+
for key, text in (
|
|
195
|
+
("manual", "The manual"),
|
|
196
|
+
("guide", "This window's guide"),
|
|
197
|
+
("source", "Source on GitHub"),
|
|
198
|
+
("pypi", "solprop on PyPI"),
|
|
199
|
+
("issues", "Report an issue"),
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
self.links.setOpenExternalLinks(True)
|
|
204
|
+
self.links.setWordWrap(True)
|
|
205
|
+
credits_ = named_label(
|
|
206
|
+
f"{COPYRIGHT}.<br>By {', '.join(authors())}.<br><br>"
|
|
207
|
+
"solprop is free software: you can redistribute it and modify it under "
|
|
208
|
+
"the terms of the GNU General Public License, version 3 or (at your "
|
|
209
|
+
"option) any later version. It comes with no warranty. The user guide "
|
|
210
|
+
"and the icon are under Creative Commons Attribution 4.0, and the "
|
|
211
|
+
"window's typeface, IBM Plex Sans, under the SIL Open Font License 1.1.",
|
|
212
|
+
"note",
|
|
213
|
+
)
|
|
214
|
+
credits_.setWordWrap(True)
|
|
215
|
+
text = QVBoxLayout()
|
|
216
|
+
text.setSpacing(8)
|
|
217
|
+
for widget in (title, summary, self.versions, self.links, credits_):
|
|
218
|
+
text.addWidget(widget)
|
|
219
|
+
row = QHBoxLayout()
|
|
220
|
+
row.setSpacing(20)
|
|
221
|
+
row.addWidget(picture)
|
|
222
|
+
row.addLayout(text, 1)
|
|
223
|
+
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
|
|
224
|
+
buttons.rejected.connect(self.reject)
|
|
225
|
+
column = QVBoxLayout(self)
|
|
226
|
+
column.setContentsMargins(24, 24, 24, 16)
|
|
227
|
+
column.addLayout(row)
|
|
228
|
+
column.addWidget(buttons)
|
|
229
|
+
self.setMinimumWidth(600)
|
|
230
|
+
self.adjustSize()
|
solprop_gui/ui/launch.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
"""The launch table: which modes the pulse enters, with what share and phase (9.2).
|
|
6
|
+
|
|
7
|
+
Each row names a mode by solprop's label (``HE1,1``), its share (energy fractions,
|
|
8
|
+
normalised by solprop) and its phase in radians. The labels offered are the ones the
|
|
9
|
+
mode preview gives for the setup; a label typed by hand is checked by solprop. One
|
|
10
|
+
table launches every pulse alike; a list of tables, one per pulse, is edited as text.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from collections.abc import Mapping, Sequence
|
|
14
|
+
|
|
15
|
+
from PySide6.QtCore import Signal
|
|
16
|
+
from PySide6.QtWidgets import (
|
|
17
|
+
QHBoxLayout,
|
|
18
|
+
QTableWidget,
|
|
19
|
+
QTableWidgetItem,
|
|
20
|
+
QToolButton,
|
|
21
|
+
QVBoxLayout,
|
|
22
|
+
QWidget,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__all__ = ["LaunchField", "launch_rows", "launch_value"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def launch_rows(value: object) -> list[tuple[str, float, float]] | None:
|
|
29
|
+
"""Return a launch mapping's rows, if it is one mapping.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
value : object
|
|
34
|
+
The recipe's ``launch``.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
list of tuple or None
|
|
39
|
+
Each mode's label, share and phase; ``None`` for a value that is not one
|
|
40
|
+
mapping of shares (a list per pulse, say).
|
|
41
|
+
|
|
42
|
+
Examples
|
|
43
|
+
--------
|
|
44
|
+
>>> launch_rows({"HE1,1": 0.9, "HE1,2": {"share": 0.1, "phase": 1.57}})
|
|
45
|
+
[('HE1,1', 0.9, 0.0), ('HE1,2', 0.1, 1.57)]
|
|
46
|
+
>>> launch_rows([{"HE1,1": 1.0}]) is None
|
|
47
|
+
True
|
|
48
|
+
"""
|
|
49
|
+
if not isinstance(value, Mapping):
|
|
50
|
+
return None
|
|
51
|
+
rows: list[tuple[str, float, float]] = []
|
|
52
|
+
for name, entry in value.items():
|
|
53
|
+
if isinstance(entry, int | float) and not isinstance(entry, bool):
|
|
54
|
+
rows.append((str(name), float(entry), 0.0))
|
|
55
|
+
elif isinstance(entry, Mapping) and isinstance(entry.get("share"), int | float):
|
|
56
|
+
rows.append(
|
|
57
|
+
(str(name), float(entry["share"]), float(entry.get("phase", 0.0))) # pyright: ignore[reportArgumentType]
|
|
58
|
+
)
|
|
59
|
+
else:
|
|
60
|
+
return None
|
|
61
|
+
return rows
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def launch_value(rows: Sequence[tuple[str, float, float]]) -> dict[str, object]:
|
|
65
|
+
"""Return the launch mapping of rows: a bare share where the phase is zero.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
rows : Sequence of tuple
|
|
70
|
+
Each mode's label, share and phase.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
dict
|
|
75
|
+
The recipe's ``launch``.
|
|
76
|
+
|
|
77
|
+
Examples
|
|
78
|
+
--------
|
|
79
|
+
>>> launch_value([("HE1,1", 0.9, 0.0), ("HE1,2", 0.1, 1.57)])
|
|
80
|
+
{'HE1,1': 0.9, 'HE1,2': {'share': 0.1, 'phase': 1.57}}
|
|
81
|
+
"""
|
|
82
|
+
return {
|
|
83
|
+
name: share if phase == 0.0 else {"share": share, "phase": phase}
|
|
84
|
+
for name, share, phase in rows
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class LaunchField(QWidget):
|
|
89
|
+
"""A table of the launched modes.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
parent : PySide6.QtWidgets.QWidget or None, optional
|
|
94
|
+
The owner.
|
|
95
|
+
|
|
96
|
+
Attributes
|
|
97
|
+
----------
|
|
98
|
+
changed : Signal
|
|
99
|
+
Emitted with the launch mapping, or ``None`` for an empty table.
|
|
100
|
+
refused : Signal
|
|
101
|
+
Emitted with the reason a cell does not read.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
changed = Signal(object)
|
|
105
|
+
refused = Signal(str)
|
|
106
|
+
|
|
107
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
108
|
+
"""Make the empty table and its buttons."""
|
|
109
|
+
super().__init__(parent)
|
|
110
|
+
self.labels: list[str] = []
|
|
111
|
+
self._updating = False
|
|
112
|
+
self.table = QTableWidget(0, 3)
|
|
113
|
+
self.table.setObjectName("launch-table")
|
|
114
|
+
self.table.setHorizontalHeaderLabels(["Mode", "Share", "Phase (rad)"])
|
|
115
|
+
self.table.verticalHeader().setVisible(False)
|
|
116
|
+
self.table.horizontalHeader().setStretchLastSection(True)
|
|
117
|
+
self.table.setMaximumHeight(130)
|
|
118
|
+
self.table.itemChanged.connect(self._edited)
|
|
119
|
+
self.add = QToolButton()
|
|
120
|
+
self.add.setText("+")
|
|
121
|
+
self.add.setToolTip("Launch into another mode.")
|
|
122
|
+
self.add.clicked.connect(self.add_row)
|
|
123
|
+
self.remove = QToolButton()
|
|
124
|
+
self.remove.setText("−") # noqa: RUF001 - a minus sign
|
|
125
|
+
self.remove.setToolTip("Remove the selected mode.")
|
|
126
|
+
self.remove.clicked.connect(self.remove_row)
|
|
127
|
+
buttons = QHBoxLayout()
|
|
128
|
+
buttons.addWidget(self.add)
|
|
129
|
+
buttons.addWidget(self.remove)
|
|
130
|
+
buttons.addStretch(1)
|
|
131
|
+
layout = QVBoxLayout(self)
|
|
132
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
133
|
+
layout.setSpacing(2)
|
|
134
|
+
layout.addWidget(self.table)
|
|
135
|
+
layout.addLayout(buttons)
|
|
136
|
+
|
|
137
|
+
def set_labels(self, labels: Sequence[str]) -> None:
|
|
138
|
+
"""Know the setup's mode labels, for new rows.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
labels : Sequence of str
|
|
143
|
+
The labels, as the mode preview gives them.
|
|
144
|
+
"""
|
|
145
|
+
self.labels = [label.split(":")[0] for label in labels]
|
|
146
|
+
|
|
147
|
+
def _row(self, name: str, share: float, phase: float) -> None:
|
|
148
|
+
"""Append a row.
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
name : str
|
|
153
|
+
The mode's label.
|
|
154
|
+
share : float
|
|
155
|
+
Its share.
|
|
156
|
+
phase : float
|
|
157
|
+
Its phase, rad.
|
|
158
|
+
"""
|
|
159
|
+
row = self.table.rowCount()
|
|
160
|
+
self.table.insertRow(row)
|
|
161
|
+
for column, text in enumerate((name, f"{share:g}", f"{phase:g}")):
|
|
162
|
+
self.table.setItem(row, column, QTableWidgetItem(text))
|
|
163
|
+
|
|
164
|
+
def rows(self) -> list[tuple[str, float, float]]:
|
|
165
|
+
"""Return the table's rows.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
list of tuple
|
|
170
|
+
Each mode's label, share and phase.
|
|
171
|
+
|
|
172
|
+
Raises
|
|
173
|
+
------
|
|
174
|
+
ValueError
|
|
175
|
+
If a share or a phase is not a number.
|
|
176
|
+
"""
|
|
177
|
+
rows = []
|
|
178
|
+
for row in range(self.table.rowCount()):
|
|
179
|
+
cells = [self.table.item(row, column) for column in range(3)]
|
|
180
|
+
name = cells[0].text().strip() if cells[0] else ""
|
|
181
|
+
if not name:
|
|
182
|
+
continue
|
|
183
|
+
share = float(cells[1].text()) if cells[1] else 0.0
|
|
184
|
+
phase = float(cells[2].text() or 0.0) if cells[2] else 0.0
|
|
185
|
+
rows.append((name, share, phase))
|
|
186
|
+
return rows
|
|
187
|
+
|
|
188
|
+
def set_value(self, value: object) -> bool:
|
|
189
|
+
"""Show a launch mapping, without announcing it.
|
|
190
|
+
|
|
191
|
+
Parameters
|
|
192
|
+
----------
|
|
193
|
+
value : object
|
|
194
|
+
The recipe's ``launch``, or ``None``.
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
bool
|
|
199
|
+
Whether the table can show it (one mapping of shares).
|
|
200
|
+
"""
|
|
201
|
+
rows = [] if value is None else launch_rows(value)
|
|
202
|
+
if rows is None:
|
|
203
|
+
return False
|
|
204
|
+
self._updating = True
|
|
205
|
+
try:
|
|
206
|
+
self.table.setRowCount(0)
|
|
207
|
+
for row in rows:
|
|
208
|
+
self._row(*row)
|
|
209
|
+
finally:
|
|
210
|
+
self._updating = False
|
|
211
|
+
return True
|
|
212
|
+
|
|
213
|
+
def add_row(self) -> None:
|
|
214
|
+
"""Add a row for the first mode not yet in the table."""
|
|
215
|
+
used = {name for name, _, _ in self._names()}
|
|
216
|
+
name = next((label for label in self.labels if label not in used), "")
|
|
217
|
+
self._updating = True
|
|
218
|
+
try:
|
|
219
|
+
self._row(name, 1.0 if not used else 0.0, 0.0)
|
|
220
|
+
finally:
|
|
221
|
+
self._updating = False
|
|
222
|
+
self._edited()
|
|
223
|
+
|
|
224
|
+
def _names(self) -> list[tuple[str, int, int]]:
|
|
225
|
+
"""Return the table's labels.
|
|
226
|
+
|
|
227
|
+
Returns
|
|
228
|
+
-------
|
|
229
|
+
list of tuple
|
|
230
|
+
Each row's label, with two placeholders.
|
|
231
|
+
"""
|
|
232
|
+
names = []
|
|
233
|
+
for row in range(self.table.rowCount()):
|
|
234
|
+
item = self.table.item(row, 0)
|
|
235
|
+
names.append((item.text() if item else "", row, 0))
|
|
236
|
+
return names
|
|
237
|
+
|
|
238
|
+
def remove_row(self) -> None:
|
|
239
|
+
"""Remove the selected row, or the last."""
|
|
240
|
+
row = self.table.currentRow()
|
|
241
|
+
if self.table.rowCount() == 0:
|
|
242
|
+
return
|
|
243
|
+
self.table.removeRow(row if row >= 0 else self.table.rowCount() - 1)
|
|
244
|
+
self._edited()
|
|
245
|
+
|
|
246
|
+
def _edited(self, *_args: object) -> None:
|
|
247
|
+
"""Announce the table's launch.
|
|
248
|
+
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
*_args : object
|
|
252
|
+
What the signal that calls it carries, unused.
|
|
253
|
+
"""
|
|
254
|
+
if self._updating:
|
|
255
|
+
return
|
|
256
|
+
try:
|
|
257
|
+
rows = self.rows()
|
|
258
|
+
except ValueError as error:
|
|
259
|
+
self.refused.emit(f"a share and a phase are numbers: {error}")
|
|
260
|
+
return
|
|
261
|
+
self.changed.emit(launch_value(rows) if rows else None)
|