led-controller-version-3-effect-creation 3.0.2__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.
- led_controller_version_3_effect_creation-3.0.2.dist-info/METADATA +144 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/RECORD +25 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/WHEEL +4 -0
- led_controller_version_3_effect_creation-3.0.2.dist-info/entry_points.txt +3 -0
- lefx/effect_creation/__init__.py +54 -0
- lefx/effect_creation/build.py +217 -0
- lefx/effect_creation/cli.py +156 -0
- lefx/effect_creation/imports.py +143 -0
- lefx/effect_creation/scaffold.py +330 -0
- lefx/effect_creation/source.py +258 -0
- lefx/effect_creation/studio/__init__.py +95 -0
- lefx/effect_creation/studio/app.py +169 -0
- lefx/effect_creation/studio/authoring.py +196 -0
- lefx/effect_creation/studio/blueprint.py +759 -0
- lefx/effect_creation/studio/calibrate.py +185 -0
- lefx/effect_creation/studio/calibration_page.py +420 -0
- lefx/effect_creation/studio/catalogue.py +219 -0
- lefx/effect_creation/studio/parameters.py +730 -0
- lefx/effect_creation/studio/preset_dialog.py +188 -0
- lefx/effect_creation/studio/project.py +302 -0
- lefx/effect_creation/studio/ring.py +172 -0
- lefx/effect_creation/studio/session.py +307 -0
- lefx/effect_creation/studio/source_editor.py +902 -0
- lefx/effect_creation/studio/window.py +656 -0
- lefx/effect_creation/validate.py +263 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Turning what is on screen into a preset in the source tree.
|
|
2
|
+
|
|
3
|
+
The values are already there — somebody just spent ten minutes arriving at them.
|
|
4
|
+
What is missing is a name, a sentence about when to use it, and somewhere to put
|
|
5
|
+
it, and only the last of those is a question the studio can partly answer for
|
|
6
|
+
itself.
|
|
7
|
+
|
|
8
|
+
Everything the dialog decides is checked before it is offered: the id it
|
|
9
|
+
proposes, whether it collides, whether the values still satisfy the schema. A
|
|
10
|
+
dialog that accepted and then failed on write would have collected the same
|
|
11
|
+
information twice.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any, Mapping
|
|
18
|
+
|
|
19
|
+
from PySide6.QtWidgets import (
|
|
20
|
+
QDialog,
|
|
21
|
+
QDialogButtonBox,
|
|
22
|
+
QFileDialog,
|
|
23
|
+
QFormLayout,
|
|
24
|
+
QHBoxLayout,
|
|
25
|
+
QLabel,
|
|
26
|
+
QLineEdit,
|
|
27
|
+
QPlainTextEdit,
|
|
28
|
+
QPushButton,
|
|
29
|
+
QVBoxLayout,
|
|
30
|
+
QWidget,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
from lefx.effect_creation import SourceError
|
|
34
|
+
from lefx.sdk import DefinitionBase
|
|
35
|
+
|
|
36
|
+
from .authoring import (
|
|
37
|
+
PresetDraft,
|
|
38
|
+
check_draft,
|
|
39
|
+
find_source_dir,
|
|
40
|
+
read_presets,
|
|
41
|
+
suggest_preset_id,
|
|
42
|
+
write_preset_checked,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class PresetDialog(QDialog):
|
|
47
|
+
"""Name the current parameters and write them into the effect's source."""
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
definition: DefinitionBase,
|
|
52
|
+
params: Mapping[str, Any],
|
|
53
|
+
parent: QWidget | None = None,
|
|
54
|
+
*,
|
|
55
|
+
source_roots: "list[Path] | None" = None,
|
|
56
|
+
) -> None:
|
|
57
|
+
super().__init__(parent)
|
|
58
|
+
self.definition = definition
|
|
59
|
+
self.params = dict(params)
|
|
60
|
+
self.source_roots = source_roots
|
|
61
|
+
self.written: Path | None = None
|
|
62
|
+
self.overwrite = False
|
|
63
|
+
|
|
64
|
+
self.setWindowTitle("Als Preset sichern")
|
|
65
|
+
self.setMinimumWidth(520)
|
|
66
|
+
self._build()
|
|
67
|
+
found = find_source_dir(definition.id, source_roots or ("effects",))
|
|
68
|
+
self.source_dir.setText(str(found or ""))
|
|
69
|
+
self._revalidate()
|
|
70
|
+
|
|
71
|
+
def _build(self) -> None:
|
|
72
|
+
layout = QVBoxLayout(self)
|
|
73
|
+
form = QFormLayout()
|
|
74
|
+
|
|
75
|
+
self.label = QLineEdit()
|
|
76
|
+
self.label.setPlaceholderText("z. B. Ruhiges Blau")
|
|
77
|
+
self.label.textChanged.connect(self._on_label_changed)
|
|
78
|
+
form.addRow("Bezeichnung", self.label)
|
|
79
|
+
|
|
80
|
+
self.preset_id = QLineEdit()
|
|
81
|
+
self.preset_id.setPlaceholderText(f"{self.definition.id}_…")
|
|
82
|
+
self.preset_id.textEdited.connect(self._revalidate)
|
|
83
|
+
form.addRow("Kennung", self.preset_id)
|
|
84
|
+
|
|
85
|
+
self.description = QPlainTextEdit()
|
|
86
|
+
self.description.setPlaceholderText("Wofür ist das gedacht?")
|
|
87
|
+
self.description.setMaximumHeight(72)
|
|
88
|
+
form.addRow("Beschreibung", self.description)
|
|
89
|
+
|
|
90
|
+
row = QHBoxLayout()
|
|
91
|
+
self.source_dir = QLineEdit()
|
|
92
|
+
self.source_dir.setPlaceholderText("Quellverzeichnis des Effekts")
|
|
93
|
+
self.source_dir.textChanged.connect(self._revalidate)
|
|
94
|
+
browse = QPushButton("…")
|
|
95
|
+
browse.setFixedWidth(32)
|
|
96
|
+
browse.clicked.connect(self._browse)
|
|
97
|
+
row.addWidget(self.source_dir, stretch=1)
|
|
98
|
+
row.addWidget(browse)
|
|
99
|
+
holder = QWidget()
|
|
100
|
+
holder.setLayout(row)
|
|
101
|
+
form.addRow("Quelle", holder)
|
|
102
|
+
layout.addLayout(form)
|
|
103
|
+
|
|
104
|
+
self.summary = QLabel("")
|
|
105
|
+
self.summary.setWordWrap(True)
|
|
106
|
+
layout.addWidget(self.summary)
|
|
107
|
+
|
|
108
|
+
self.problems = QLabel("")
|
|
109
|
+
self.problems.setWordWrap(True)
|
|
110
|
+
self.problems.setStyleSheet("color: #d76;")
|
|
111
|
+
layout.addWidget(self.problems)
|
|
112
|
+
|
|
113
|
+
self.buttons = QDialogButtonBox(
|
|
114
|
+
QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel
|
|
115
|
+
)
|
|
116
|
+
self.buttons.accepted.connect(self._save)
|
|
117
|
+
self.buttons.rejected.connect(self.reject)
|
|
118
|
+
layout.addWidget(self.buttons)
|
|
119
|
+
|
|
120
|
+
# -- keeping the dialog honest -----------------------------------------
|
|
121
|
+
|
|
122
|
+
def _on_label_changed(self, text: str) -> None:
|
|
123
|
+
# The id follows the label until somebody types one, then it is theirs.
|
|
124
|
+
if not self.preset_id.isModified():
|
|
125
|
+
self.preset_id.setText(suggest_preset_id(self.definition.id, text))
|
|
126
|
+
self._revalidate()
|
|
127
|
+
|
|
128
|
+
def _browse(self) -> None:
|
|
129
|
+
chosen = QFileDialog.getExistingDirectory(self, "Quellverzeichnis wählen")
|
|
130
|
+
if chosen:
|
|
131
|
+
self.source_dir.setText(chosen)
|
|
132
|
+
|
|
133
|
+
def draft(self) -> PresetDraft:
|
|
134
|
+
return PresetDraft(
|
|
135
|
+
effect_id=self.definition.id,
|
|
136
|
+
preset_id=self.preset_id.text().strip(),
|
|
137
|
+
title=self.label.text().strip(),
|
|
138
|
+
description=self.description.toPlainText().strip(),
|
|
139
|
+
params=self.params,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def _revalidate(self) -> None:
|
|
143
|
+
draft = self.draft()
|
|
144
|
+
problems = check_draft(self.definition, draft)
|
|
145
|
+
|
|
146
|
+
directory = self.source_dir.text().strip()
|
|
147
|
+
existing: dict[str, Any] = {}
|
|
148
|
+
if not directory:
|
|
149
|
+
problems.append(
|
|
150
|
+
f"Kein Quellverzeichnis für {self.definition.id!r} gefunden — bitte auswählen."
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
try:
|
|
154
|
+
existing = read_presets(directory)
|
|
155
|
+
except SourceError as exc:
|
|
156
|
+
problems.append(str(exc))
|
|
157
|
+
|
|
158
|
+
self.overwrite = draft.preset_id in existing
|
|
159
|
+
if self.overwrite:
|
|
160
|
+
self.summary.setText(
|
|
161
|
+
f"{len(self.params)} Parameter · {draft.preset_id} ist vorhanden "
|
|
162
|
+
"und wird überschrieben."
|
|
163
|
+
)
|
|
164
|
+
else:
|
|
165
|
+
self.summary.setText(
|
|
166
|
+
f"{len(self.params)} Parameter · {len(existing)} Presets bereits in dieser Quelle."
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
self.problems.setText("\n".join(problems))
|
|
170
|
+
self.buttons.button(QDialogButtonBox.StandardButton.Save).setEnabled(not problems)
|
|
171
|
+
|
|
172
|
+
def _save(self) -> None:
|
|
173
|
+
try:
|
|
174
|
+
self.written = write_preset_checked(
|
|
175
|
+
self.definition,
|
|
176
|
+
self.source_dir.text().strip(),
|
|
177
|
+
self.draft(),
|
|
178
|
+
overwrite=self.overwrite,
|
|
179
|
+
)
|
|
180
|
+
except SourceError as exc:
|
|
181
|
+
# The source was put back the way it was; say what happened and let
|
|
182
|
+
# the values stay on screen rather than closing over the problem.
|
|
183
|
+
self.problems.setText(str(exc))
|
|
184
|
+
return
|
|
185
|
+
self.accept()
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
__all__ = ["PresetDialog"]
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"""Which checkout the studio is working on.
|
|
2
|
+
|
|
3
|
+
Run from a source tree, everything the studio needs is findable relative to the
|
|
4
|
+
working directory, and that is what the rest of the system assumes: the service
|
|
5
|
+
looks beside the cwd for a catalogue, a calibration lands in the cwd. That
|
|
6
|
+
assumption is exactly what a standalone build breaks. An executable is started
|
|
7
|
+
from wherever it happens to sit — a Start menu, a desktop, a folder of tools —
|
|
8
|
+
and "beside the working directory" then means somewhere nobody chose.
|
|
9
|
+
|
|
10
|
+
So the studio stops inferring and is told: one root, and every path derived from
|
|
11
|
+
it. That is not a concession to the frozen build. It is better in the checkout
|
|
12
|
+
too, because it makes "which project am I editing" a thing on screen rather than
|
|
13
|
+
a property of how the terminal happened to be opened, and it lets one studio
|
|
14
|
+
switch between two catalogues without being restarted.
|
|
15
|
+
|
|
16
|
+
No Qt: where files are is not a question about widgets.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
from dataclasses import dataclass
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Any, Iterable
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger("lefx.effect_creation.studio.project")
|
|
29
|
+
|
|
30
|
+
CATALOGUE_DIR = "effects"
|
|
31
|
+
CALIBRATION_FILE = "doa_calibration.json"
|
|
32
|
+
STATE_FILE = "build/studio-state.json"
|
|
33
|
+
|
|
34
|
+
SET_PACKAGE_DIR = "packages"
|
|
35
|
+
"""Where a built set lands: inside the distribution that ships it.
|
|
36
|
+
|
|
37
|
+
There used to be a ``build/effects`` for this, and it was a third place a
|
|
38
|
+
``.lefxset`` could be. Now each set has exactly one home — ``src/lefx/sets/
|
|
39
|
+
<module>/`` inside its own distribution — and that home is the same directory
|
|
40
|
+
in a checkout, in an editable workspace and in an installed wheel. A set that is
|
|
41
|
+
built is a set that is installed; there is no step in between to forget.
|
|
42
|
+
|
|
43
|
+
Which distribution directory that is gets looked up rather than computed, so
|
|
44
|
+
that renaming a distribution does not silently move where builds land. The
|
|
45
|
+
constant below is only the fallback for a project that has no package for the
|
|
46
|
+
set yet, which is a project where somebody is about to add one.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
NEW_SET_DISTRIBUTION = "led-controller-version-3-set-{short}"
|
|
50
|
+
"""How a distribution for a new set is named when there is not one already."""
|
|
51
|
+
|
|
52
|
+
RECENT_FILE = Path.home() / ".lefx" / "studio.json"
|
|
53
|
+
"""Where the last project is remembered.
|
|
54
|
+
|
|
55
|
+
In the user's home rather than beside the executable: a tool that wrote next to
|
|
56
|
+
itself would need to live somewhere writable, and would forget everything the
|
|
57
|
+
first time it was copied elsewhere.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(slots=True, frozen=True)
|
|
62
|
+
class Project:
|
|
63
|
+
"""A checkout the studio can read effects from and write sources into."""
|
|
64
|
+
|
|
65
|
+
root: Path
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def at(cls, path: str | Path | None = None) -> "Project":
|
|
69
|
+
"""A project at the given path, or at the working directory."""
|
|
70
|
+
return cls(root=Path(path if path is not None else Path.cwd()).expanduser().resolve())
|
|
71
|
+
|
|
72
|
+
# -- what lives where ---------------------------------------------------
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def catalogue_root(self) -> Path:
|
|
76
|
+
"""Where effect *sources* live, one directory per set."""
|
|
77
|
+
return self.root / CATALOGUE_DIR
|
|
78
|
+
|
|
79
|
+
def set_module_dir(self, set_name: str) -> Path:
|
|
80
|
+
"""The ``src/lefx/sets/<module>`` directory that ships the named set.
|
|
81
|
+
|
|
82
|
+
Found by looking for the module rather than by assembling a
|
|
83
|
+
distribution name: the module path is fixed by the import name and the
|
|
84
|
+
distribution name is not. When no distribution has it yet — a project
|
|
85
|
+
where the set is new — the conventional name is used, and creating the
|
|
86
|
+
directory is what makes it real.
|
|
87
|
+
"""
|
|
88
|
+
module = set_name.replace("-", "_")
|
|
89
|
+
packages = self.root / SET_PACKAGE_DIR
|
|
90
|
+
for candidate in sorted(packages.glob(f"*/src/lefx/sets/{module}")):
|
|
91
|
+
if candidate.is_dir():
|
|
92
|
+
return candidate
|
|
93
|
+
short = set_name.removesuffix("-set") or set_name
|
|
94
|
+
return (
|
|
95
|
+
packages / NEW_SET_DISTRIBUTION.format(short=short)
|
|
96
|
+
/ "src" / "lefx" / "sets" / module
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def build_target(self, set_name: str) -> Path:
|
|
100
|
+
"""Where the named set's archive belongs, built or not."""
|
|
101
|
+
return self.set_module_dir(set_name) / f"{set_name}.lefxset"
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def built_set_dirs(self) -> list[Path]:
|
|
105
|
+
"""The directories holding this project's built archives.
|
|
106
|
+
|
|
107
|
+
Globbed off the project rather than read from the installed entry
|
|
108
|
+
points on purpose. The studio is pointed at *a checkout* — possibly not
|
|
109
|
+
the one it was built from — and has to show that checkout's catalogue,
|
|
110
|
+
not whichever one happened to be installed alongside the executable.
|
|
111
|
+
"""
|
|
112
|
+
found = self.root.glob(f"{SET_PACKAGE_DIR}/*/src/lefx/sets/*")
|
|
113
|
+
return sorted(path for path in found if path.is_dir() and path.name != "__pycache__")
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def package_search_paths(self) -> list[Path]:
|
|
117
|
+
"""What the embedded service scans, in the order the service uses.
|
|
118
|
+
|
|
119
|
+
The built catalogue first, then the source tree — the same two places
|
|
120
|
+
``lefx serve`` looks, so the studio shows what the service would load.
|
|
121
|
+
"""
|
|
122
|
+
return [*self.built_set_dirs, self.catalogue_root]
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def calibration_file(self) -> Path:
|
|
126
|
+
return self.root / CALIBRATION_FILE
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def state_file(self) -> Path:
|
|
130
|
+
"""Where the embedded service persists a background state.
|
|
131
|
+
|
|
132
|
+
Inside ``build/`` because it is scratch: a studio session should not
|
|
133
|
+
leave a state behind that the next real service picks up.
|
|
134
|
+
"""
|
|
135
|
+
return self.root / STATE_FILE
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def source_roots(self) -> list[Path]:
|
|
139
|
+
return [self.catalogue_root]
|
|
140
|
+
|
|
141
|
+
def sets(self) -> list[Path]:
|
|
142
|
+
"""Every effect set in the project, found by its manifest."""
|
|
143
|
+
if not self.catalogue_root.is_dir():
|
|
144
|
+
return []
|
|
145
|
+
found = {
|
|
146
|
+
manifest.parent
|
|
147
|
+
for stem in ("set.yaml", "set.yml", "set.json")
|
|
148
|
+
for manifest in self.catalogue_root.glob(f"*/{stem}")
|
|
149
|
+
}
|
|
150
|
+
return sorted(found)
|
|
151
|
+
|
|
152
|
+
def sources_in(self, set_root: str | Path) -> list[Path]:
|
|
153
|
+
"""The effect sources of one set, in the order a build takes them."""
|
|
154
|
+
root = Path(set_root)
|
|
155
|
+
return sorted(
|
|
156
|
+
{
|
|
157
|
+
manifest.parent
|
|
158
|
+
for stem in ("effect.yaml", "effect.yml", "effect.json")
|
|
159
|
+
for manifest in (root / "sources").rglob(stem)
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# -- whether it is one --------------------------------------------------
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def looks_like_a_project(self) -> bool:
|
|
167
|
+
"""Whether there is anything here for the studio to work on.
|
|
168
|
+
|
|
169
|
+
A directory with neither sources nor a built catalogue is not wrong —
|
|
170
|
+
it is where a first effect gets written — but the window should say so
|
|
171
|
+
rather than present an empty list as if it were a finding.
|
|
172
|
+
"""
|
|
173
|
+
return self.catalogue_root.is_dir() or bool(self.built_set_dirs)
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def label(self) -> str:
|
|
177
|
+
return self.root.name or str(self.root)
|
|
178
|
+
|
|
179
|
+
def describe(self) -> dict[str, Any]:
|
|
180
|
+
return {
|
|
181
|
+
"root": str(self.root),
|
|
182
|
+
"catalogue": str(self.catalogue_root),
|
|
183
|
+
"build": [str(path) for path in self.built_set_dirs],
|
|
184
|
+
"sets": [path.name for path in self.sets()],
|
|
185
|
+
"is_project": self.looks_like_a_project,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
# -- building -----------------------------------------------------------
|
|
189
|
+
|
|
190
|
+
def build_catalogue(self) -> list[dict[str, Any]]:
|
|
191
|
+
"""Build every set in the project, the way the build script does.
|
|
192
|
+
|
|
193
|
+
Carried here rather than shelled out to ``scripts/build_effects.py``,
|
|
194
|
+
because a standalone studio has no ``scripts/`` — and because a tool
|
|
195
|
+
that can write a source should be able to build it without asking for a
|
|
196
|
+
terminal. The staging directory is removed afterwards for the same
|
|
197
|
+
reason the script removes it: it sits inside a directory the service
|
|
198
|
+
scans, and every member left there is found a second time.
|
|
199
|
+
"""
|
|
200
|
+
import shutil
|
|
201
|
+
|
|
202
|
+
from lefx.effect_creation import build_effect_set
|
|
203
|
+
|
|
204
|
+
results: list[dict[str, Any]] = []
|
|
205
|
+
for set_root in self.sets():
|
|
206
|
+
target = self.build_target(set_root.name)
|
|
207
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
208
|
+
staging = set_root / "effects"
|
|
209
|
+
if staging.exists():
|
|
210
|
+
shutil.rmtree(staging)
|
|
211
|
+
try:
|
|
212
|
+
results.append(
|
|
213
|
+
build_effect_set(set_root, self.sources_in(set_root), target)
|
|
214
|
+
)
|
|
215
|
+
finally:
|
|
216
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
217
|
+
return results
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# -- remembering the last one ----------------------------------------------
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def remember(project: Project, *, path: Path = RECENT_FILE) -> None:
|
|
224
|
+
"""Record the project, so double-clicking the tool reopens it."""
|
|
225
|
+
try:
|
|
226
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
227
|
+
path.write_text(
|
|
228
|
+
json.dumps({"recent": str(project.root)}, indent=2), encoding="utf-8"
|
|
229
|
+
)
|
|
230
|
+
except OSError as exc:
|
|
231
|
+
# Not being able to remember is a smaller problem than refusing to run.
|
|
232
|
+
logger.warning("could not record the recent project: %s", exc)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def recalled(*, path: Path = RECENT_FILE) -> Project | None:
|
|
236
|
+
"""The last project, if there was one and it is still there."""
|
|
237
|
+
try:
|
|
238
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
239
|
+
except (OSError, json.JSONDecodeError):
|
|
240
|
+
return None
|
|
241
|
+
recent = payload.get("recent")
|
|
242
|
+
if not recent:
|
|
243
|
+
return None
|
|
244
|
+
project = Project.at(recent)
|
|
245
|
+
return project if project.root.is_dir() else None
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def resolve(explicit: str | Path | None = None, *, path: Path = RECENT_FILE) -> Project:
|
|
249
|
+
"""Which project to open: what was asked for, what was last used, or here.
|
|
250
|
+
|
|
251
|
+
In that order. An explicit ``--project`` always wins; a frozen build started
|
|
252
|
+
by double-clicking has no useful working directory and falls back to what it
|
|
253
|
+
was last pointed at; a checkout started from its own root gets that root
|
|
254
|
+
without anybody having to say so.
|
|
255
|
+
"""
|
|
256
|
+
if explicit is not None:
|
|
257
|
+
return Project.at(explicit)
|
|
258
|
+
|
|
259
|
+
here = Project.at()
|
|
260
|
+
if here.looks_like_a_project:
|
|
261
|
+
return here
|
|
262
|
+
|
|
263
|
+
remembered = recalled(path=path)
|
|
264
|
+
if remembered is not None:
|
|
265
|
+
return remembered
|
|
266
|
+
return here
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def under_a_frozen_build() -> bool:
|
|
270
|
+
"""Whether this is running as a standalone executable.
|
|
271
|
+
|
|
272
|
+
Only used to decide how loudly to ask for a project: a checkout can guess
|
|
273
|
+
from the working directory, a bundle should not pretend to.
|
|
274
|
+
"""
|
|
275
|
+
import sys
|
|
276
|
+
|
|
277
|
+
return bool(getattr(sys, "frozen", False)) and hasattr(sys, "_MEIPASS")
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def iter_paths(project: Project) -> Iterable[tuple[str, Path]]:
|
|
281
|
+
"""For the window's status line and for tests to assert against."""
|
|
282
|
+
yield "Wurzel", project.root
|
|
283
|
+
yield "Quellen", project.catalogue_root
|
|
284
|
+
for path in project.built_set_dirs:
|
|
285
|
+
yield f"Gebaut ({path.name})", path
|
|
286
|
+
yield "Kalibrierung", project.calibration_file
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
__all__ = [
|
|
290
|
+
"CALIBRATION_FILE",
|
|
291
|
+
"CATALOGUE_DIR",
|
|
292
|
+
"NEW_SET_DISTRIBUTION",
|
|
293
|
+
"SET_PACKAGE_DIR",
|
|
294
|
+
"RECENT_FILE",
|
|
295
|
+
"STATE_FILE",
|
|
296
|
+
"Project",
|
|
297
|
+
"iter_paths",
|
|
298
|
+
"recalled",
|
|
299
|
+
"remember",
|
|
300
|
+
"resolve",
|
|
301
|
+
"under_a_frozen_build",
|
|
302
|
+
]
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""The ring the studio shows: what the device is being sent, as it is sent.
|
|
2
|
+
|
|
3
|
+
Not a second rendering of the effect — the frames come off the path to the
|
|
4
|
+
device, so what is drawn here and what the LEDs do cannot drift apart.
|
|
5
|
+
|
|
6
|
+
Two things this draws that the simulator's window deliberately does not. LED
|
|
7
|
+
indices, because when you are tuning an effect the question is usually "which
|
|
8
|
+
one is that" rather than "how does it look". And the half-LED sectors, because
|
|
9
|
+
a direction lands on one of ``2 * led_count`` of them and a ring without the
|
|
10
|
+
gaps marked makes calibrating one a matter of counting.
|
|
11
|
+
|
|
12
|
+
Black is drawn as black. ``0x000000`` is a colour that covers; an LED that is
|
|
13
|
+
off looks the same but means something else, and a monitor that showed them
|
|
14
|
+
alike would hide the difference exactly where it is being checked.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import math
|
|
20
|
+
|
|
21
|
+
from PySide6.QtCore import QPointF, QRectF, Qt, Signal
|
|
22
|
+
from PySide6.QtGui import QColor, QFont, QPainter, QPen
|
|
23
|
+
from PySide6.QtWidgets import QSizePolicy, QWidget
|
|
24
|
+
|
|
25
|
+
BODY_COLOR = QColor(20, 22, 28)
|
|
26
|
+
RIM_COLOR = QColor(44, 48, 58)
|
|
27
|
+
SOCKET_COLOR = QColor(32, 35, 42)
|
|
28
|
+
INDEX_COLOR = QColor(120, 126, 140)
|
|
29
|
+
SECTOR_COLOR = QColor(70, 76, 92)
|
|
30
|
+
MARK_COLOR = QColor(210, 170, 60)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class RingMonitor(QWidget):
|
|
34
|
+
"""Draws one frame at a time, at whatever size it is given."""
|
|
35
|
+
|
|
36
|
+
led_clicked = Signal(int)
|
|
37
|
+
"""Which LED was clicked. Calibrating is pointing at one and saying 'that one'."""
|
|
38
|
+
|
|
39
|
+
def __init__(self, led_count: int = 12, parent: QWidget | None = None) -> None:
|
|
40
|
+
super().__init__(parent)
|
|
41
|
+
self._led_count = max(1, int(led_count))
|
|
42
|
+
self._colors: list[int] = [0] * self._led_count
|
|
43
|
+
self._show_indices = True
|
|
44
|
+
self._show_sectors = False
|
|
45
|
+
self._marked_sector: int | None = None
|
|
46
|
+
self.setMinimumSize(220, 220)
|
|
47
|
+
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
|
48
|
+
|
|
49
|
+
# -- what it shows ------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def led_count(self) -> int:
|
|
53
|
+
return self._led_count
|
|
54
|
+
|
|
55
|
+
def set_led_count(self, led_count: int) -> None:
|
|
56
|
+
count = max(1, int(led_count))
|
|
57
|
+
if count == self._led_count:
|
|
58
|
+
return
|
|
59
|
+
self._led_count = count
|
|
60
|
+
self._colors = [0] * count
|
|
61
|
+
self.update()
|
|
62
|
+
|
|
63
|
+
def set_colors(self, colors: list[int] | tuple[int, ...]) -> None:
|
|
64
|
+
"""Take a frame. A frame of the wrong length is ignored, not reshaped.
|
|
65
|
+
|
|
66
|
+
The same rule the sinks follow: padding would light positions the
|
|
67
|
+
renderer never addressed, and the monitor exists to show what was sent.
|
|
68
|
+
"""
|
|
69
|
+
values = list(colors)
|
|
70
|
+
if len(values) != self._led_count:
|
|
71
|
+
return
|
|
72
|
+
self._colors = [int(value) & 0xFFFFFF for value in values]
|
|
73
|
+
self.update()
|
|
74
|
+
|
|
75
|
+
def set_show_indices(self, show: bool) -> None:
|
|
76
|
+
self._show_indices = bool(show)
|
|
77
|
+
self.update()
|
|
78
|
+
|
|
79
|
+
def set_show_sectors(self, show: bool) -> None:
|
|
80
|
+
"""Draw the ``2 * led_count`` half-LED sectors a direction can land on."""
|
|
81
|
+
self._show_sectors = bool(show)
|
|
82
|
+
self.update()
|
|
83
|
+
|
|
84
|
+
def mark_sector(self, sector: int | None) -> None:
|
|
85
|
+
"""Highlight one sector, for stepping through a calibration."""
|
|
86
|
+
self._marked_sector = None if sector is None else int(sector) % (2 * self._led_count)
|
|
87
|
+
self.update()
|
|
88
|
+
|
|
89
|
+
# -- drawing ------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
def _geometry(self) -> tuple[QPointF, float, float]:
|
|
92
|
+
side = min(self.width(), self.height())
|
|
93
|
+
center = QPointF(self.width() / 2.0, self.height() / 2.0)
|
|
94
|
+
radius = side * 0.36
|
|
95
|
+
led_size = max(6.0, min(side * 0.075, 2.0 * math.pi * radius / self._led_count * 0.62))
|
|
96
|
+
return center, radius, led_size
|
|
97
|
+
|
|
98
|
+
def _angle_of(self, index: int) -> float:
|
|
99
|
+
"""LED zero at the top, clockwise — the way the ring sits on a desk."""
|
|
100
|
+
return math.radians(index * 360.0 / self._led_count - 90.0)
|
|
101
|
+
|
|
102
|
+
def paintEvent(self, event) -> None: # noqa: N802 — Qt's spelling
|
|
103
|
+
del event
|
|
104
|
+
painter = QPainter(self)
|
|
105
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
106
|
+
center, radius, led_size = self._geometry()
|
|
107
|
+
|
|
108
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
109
|
+
painter.setBrush(BODY_COLOR)
|
|
110
|
+
painter.drawEllipse(center, radius * 1.42, radius * 1.42)
|
|
111
|
+
painter.setBrush(SOCKET_COLOR)
|
|
112
|
+
painter.drawEllipse(center, radius * 0.55, radius * 0.55)
|
|
113
|
+
painter.setPen(QPen(RIM_COLOR, 1.5))
|
|
114
|
+
painter.setBrush(Qt.BrushStyle.NoBrush)
|
|
115
|
+
painter.drawEllipse(center, radius * 1.42, radius * 1.42)
|
|
116
|
+
|
|
117
|
+
if self._show_sectors:
|
|
118
|
+
self._draw_sectors(painter, center, radius)
|
|
119
|
+
|
|
120
|
+
for index, color_int in enumerate(self._colors):
|
|
121
|
+
angle = self._angle_of(index)
|
|
122
|
+
position = QPointF(
|
|
123
|
+
center.x() + radius * math.cos(angle), center.y() + radius * math.sin(angle)
|
|
124
|
+
)
|
|
125
|
+
color = QColor(
|
|
126
|
+
(color_int >> 16) & 0xFF, (color_int >> 8) & 0xFF, color_int & 0xFF
|
|
127
|
+
)
|
|
128
|
+
painter.setPen(QPen(RIM_COLOR, 1.0))
|
|
129
|
+
painter.setBrush(color)
|
|
130
|
+
painter.drawEllipse(position, led_size / 2.0, led_size / 2.0)
|
|
131
|
+
|
|
132
|
+
if self._show_indices:
|
|
133
|
+
painter.setPen(QPen(INDEX_COLOR))
|
|
134
|
+
font = QFont(painter.font())
|
|
135
|
+
font.setPointSizeF(max(6.0, led_size * 0.42))
|
|
136
|
+
painter.setFont(font)
|
|
137
|
+
label = QRectF(
|
|
138
|
+
center.x() + radius * 1.22 * math.cos(angle) - 12.0,
|
|
139
|
+
center.y() + radius * 1.22 * math.sin(angle) - 8.0,
|
|
140
|
+
24.0,
|
|
141
|
+
16.0,
|
|
142
|
+
)
|
|
143
|
+
painter.drawText(label, Qt.AlignmentFlag.AlignCenter, str(index))
|
|
144
|
+
painter.end()
|
|
145
|
+
|
|
146
|
+
def _draw_sectors(self, painter: QPainter, center: QPointF, radius: float) -> None:
|
|
147
|
+
sectors = 2 * self._led_count
|
|
148
|
+
for sector in range(sectors):
|
|
149
|
+
angle = math.radians(sector * 360.0 / sectors - 90.0)
|
|
150
|
+
inner = radius * 0.72
|
|
151
|
+
outer = radius * 0.86 if sector % 2 else radius * 0.92
|
|
152
|
+
marked = sector == self._marked_sector
|
|
153
|
+
painter.setPen(QPen(MARK_COLOR if marked else SECTOR_COLOR, 3.0 if marked else 1.0))
|
|
154
|
+
painter.drawLine(
|
|
155
|
+
QPointF(center.x() + inner * math.cos(angle), center.y() + inner * math.sin(angle)),
|
|
156
|
+
QPointF(center.x() + outer * math.cos(angle), center.y() + outer * math.sin(angle)),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def mousePressEvent(self, event) -> None: # noqa: N802 — Qt's spelling
|
|
160
|
+
center, radius, led_size = self._geometry()
|
|
161
|
+
point = event.position()
|
|
162
|
+
for index in range(self._led_count):
|
|
163
|
+
angle = self._angle_of(index)
|
|
164
|
+
spot = QPointF(
|
|
165
|
+
center.x() + radius * math.cos(angle), center.y() + radius * math.sin(angle)
|
|
166
|
+
)
|
|
167
|
+
if math.hypot(point.x() - spot.x(), point.y() - spot.y()) <= led_size:
|
|
168
|
+
self.led_clicked.emit(index)
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
__all__ = ["RingMonitor"]
|