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,219 @@
|
|
|
1
|
+
"""Finding a definition among a few dozen, and knowing how to run it.
|
|
2
|
+
|
|
3
|
+
Two jobs, both free of Qt so they can be checked without a display.
|
|
4
|
+
|
|
5
|
+
The first is searching. A catalogue of thirty-five grows, and scrolling a list
|
|
6
|
+
stops being how you find something long before it stops being how it is drawn.
|
|
7
|
+
Matching covers everything a person might remember about an effect — its id, its
|
|
8
|
+
title, what it does, where it came from, what it was tagged with.
|
|
9
|
+
|
|
10
|
+
The second is telling the window *how* a definition is played, which is the one
|
|
11
|
+
thing that differs between the four lifecycle forms and the one thing a caller
|
|
12
|
+
must not guess. A state is set and stays. A controlled overlay is set on a
|
|
13
|
+
channel and then fed values. A timed overlay runs itself out. An event is
|
|
14
|
+
emitted and never repeated on its own.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import Any, Iterable, Mapping
|
|
21
|
+
|
|
22
|
+
from lefx.engine import Preset, RegisteredEffect
|
|
23
|
+
from lefx.sdk import (
|
|
24
|
+
ControlledOverlayDefinition,
|
|
25
|
+
DefinitionBase,
|
|
26
|
+
DefinitionKind,
|
|
27
|
+
EventDefinition,
|
|
28
|
+
StateDefinition,
|
|
29
|
+
TimedOverlayDefinition,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# The four lifecycle forms, which is what a person is choosing between. The
|
|
33
|
+
# coarser DefinitionType groups the two overlays together, and they are the two
|
|
34
|
+
# a browser most needs to keep apart: one is fed values while it runs and the
|
|
35
|
+
# other runs itself out.
|
|
36
|
+
KIND_LABELS: dict[DefinitionKind, str] = {
|
|
37
|
+
DefinitionKind.STATE: "State",
|
|
38
|
+
DefinitionKind.CONTROLLED_OVERLAY: "Controlled Overlay",
|
|
39
|
+
DefinitionKind.TIMED_OVERLAY: "Timed Overlay",
|
|
40
|
+
DefinitionKind.EVENT: "Event",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(slots=True, frozen=True)
|
|
45
|
+
class Playback:
|
|
46
|
+
"""How a definition reaches the ring, and what it needs to get there."""
|
|
47
|
+
|
|
48
|
+
verb: str
|
|
49
|
+
"""``state``, ``overlay`` or ``event`` — which command applies it."""
|
|
50
|
+
|
|
51
|
+
needs_channel: bool
|
|
52
|
+
"""Whether it is addressed by channel once running."""
|
|
53
|
+
|
|
54
|
+
accepts_runtime_inputs: bool
|
|
55
|
+
"""Whether it reads values that arrive while it runs."""
|
|
56
|
+
|
|
57
|
+
repeatable: bool
|
|
58
|
+
"""Whether re-applying it continuously is meaningful.
|
|
59
|
+
|
|
60
|
+
False for events. An event is a thing that happened; replaying it thirty
|
|
61
|
+
times a second because a slider moved would be a different thing, and a
|
|
62
|
+
misleading one to judge the effect by.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
finite: bool
|
|
66
|
+
"""Whether it ends by itself."""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def playback_for(definition: DefinitionBase) -> Playback:
|
|
70
|
+
if isinstance(definition, StateDefinition):
|
|
71
|
+
return Playback(
|
|
72
|
+
verb="state",
|
|
73
|
+
needs_channel=False,
|
|
74
|
+
accepts_runtime_inputs=False,
|
|
75
|
+
repeatable=True,
|
|
76
|
+
finite=False,
|
|
77
|
+
)
|
|
78
|
+
if isinstance(definition, ControlledOverlayDefinition):
|
|
79
|
+
return Playback(
|
|
80
|
+
verb="overlay",
|
|
81
|
+
needs_channel=True,
|
|
82
|
+
accepts_runtime_inputs=True,
|
|
83
|
+
repeatable=True,
|
|
84
|
+
finite=False,
|
|
85
|
+
)
|
|
86
|
+
if isinstance(definition, TimedOverlayDefinition):
|
|
87
|
+
return Playback(
|
|
88
|
+
verb="overlay",
|
|
89
|
+
needs_channel=False,
|
|
90
|
+
accepts_runtime_inputs=False,
|
|
91
|
+
repeatable=True,
|
|
92
|
+
finite=True,
|
|
93
|
+
)
|
|
94
|
+
if isinstance(definition, EventDefinition):
|
|
95
|
+
return Playback(
|
|
96
|
+
verb="event",
|
|
97
|
+
needs_channel=False,
|
|
98
|
+
accepts_runtime_inputs=False,
|
|
99
|
+
repeatable=False,
|
|
100
|
+
finite=True,
|
|
101
|
+
)
|
|
102
|
+
raise TypeError(f"Unknown definition form: {type(definition).__name__}")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def pulls_a_provider(definition: DefinitionBase) -> str | None:
|
|
106
|
+
"""The capability this definition reads from a device, if it reads one.
|
|
107
|
+
|
|
108
|
+
A controlled overlay either pulls values from a provider or is pushed them
|
|
109
|
+
by a caller. Which one decides whether the studio should offer input
|
|
110
|
+
controls or get out of the way and let the device supply them.
|
|
111
|
+
"""
|
|
112
|
+
policy = getattr(definition, "input_sampling", None)
|
|
113
|
+
return None if policy is None else policy.provider_id
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@dataclass(slots=True, frozen=True)
|
|
117
|
+
class Entry:
|
|
118
|
+
"""One row in the browser."""
|
|
119
|
+
|
|
120
|
+
effect: RegisteredEffect
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def effect_id(self) -> str:
|
|
124
|
+
return self.effect.effect_id
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def definition(self) -> DefinitionBase:
|
|
128
|
+
return self.effect.definition
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def title(self) -> str:
|
|
132
|
+
return self.definition.title or self.definition.id
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def kind_label(self) -> str:
|
|
136
|
+
return KIND_LABELS.get(self.definition.kind, "Definition")
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def haystack(self) -> str:
|
|
140
|
+
definition = self.definition
|
|
141
|
+
return " ".join(
|
|
142
|
+
[
|
|
143
|
+
definition.id,
|
|
144
|
+
definition.title or "",
|
|
145
|
+
definition.description or "",
|
|
146
|
+
self.effect.source_id,
|
|
147
|
+
self.kind_label,
|
|
148
|
+
*definition.tags,
|
|
149
|
+
]
|
|
150
|
+
).casefold()
|
|
151
|
+
|
|
152
|
+
def matches(self, query: str) -> bool:
|
|
153
|
+
"""Every word has to appear somewhere. Order and field do not matter.
|
|
154
|
+
|
|
155
|
+
Requiring all of them is what makes a second word narrow a search
|
|
156
|
+
instead of widening it, which is what typing one more word is for.
|
|
157
|
+
"""
|
|
158
|
+
needles = query.casefold().split()
|
|
159
|
+
if not needles:
|
|
160
|
+
return True
|
|
161
|
+
hay = self.haystack
|
|
162
|
+
return all(needle in hay for needle in needles)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def entries(effects: Iterable[RegisteredEffect]) -> list[Entry]:
|
|
166
|
+
return [Entry(effect) for effect in effects]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def filtered(
|
|
170
|
+
items: Iterable[Entry],
|
|
171
|
+
*,
|
|
172
|
+
query: str = "",
|
|
173
|
+
kind: DefinitionKind | None = None,
|
|
174
|
+
source_id: str | None = None,
|
|
175
|
+
) -> list[Entry]:
|
|
176
|
+
return [
|
|
177
|
+
entry
|
|
178
|
+
for entry in items
|
|
179
|
+
if (kind is None or entry.definition.kind is kind)
|
|
180
|
+
and (source_id is None or entry.effect.source_id == source_id)
|
|
181
|
+
and entry.matches(query)
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def starting_config(definition: DefinitionBase, preset: Preset | None = None) -> dict[str, Any]:
|
|
186
|
+
"""The values an editor opens with: the schema's defaults, then a preset's.
|
|
187
|
+
|
|
188
|
+
Every declared parameter is present even when nothing supplies it, so the
|
|
189
|
+
editor shows the whole surface of the definition rather than the part
|
|
190
|
+
somebody happened to write down.
|
|
191
|
+
"""
|
|
192
|
+
config: dict[str, Any] = {}
|
|
193
|
+
for name, parameter in definition.parameter_schema.items():
|
|
194
|
+
config[name] = parameter.default if parameter.has_default else None
|
|
195
|
+
if preset is not None:
|
|
196
|
+
config.update({key: value for key, value in preset.params.items() if key in config})
|
|
197
|
+
return config
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def starting_inputs(definition: DefinitionBase) -> dict[str, Any]:
|
|
201
|
+
"""The runtime inputs an editor opens with, or nothing for a form with none."""
|
|
202
|
+
schema: Mapping[str, Any] = getattr(definition, "runtime_input_schema", {}) or {}
|
|
203
|
+
return {
|
|
204
|
+
name: (parameter.default if parameter.has_default else None)
|
|
205
|
+
for name, parameter in schema.items()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
__all__ = [
|
|
210
|
+
"KIND_LABELS",
|
|
211
|
+
"Entry",
|
|
212
|
+
"Playback",
|
|
213
|
+
"entries",
|
|
214
|
+
"filtered",
|
|
215
|
+
"playback_for",
|
|
216
|
+
"pulls_a_provider",
|
|
217
|
+
"starting_config",
|
|
218
|
+
"starting_inputs",
|
|
219
|
+
]
|