conformtools 0.6.5 → 0.6.6
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.
- package/README.md +3 -3
- package/dist/account-HDXVTS5T.js +3 -0
- package/dist/arriraw-YIJ3BYNN.js +525 -0
- package/dist/avid-panel/MANIFEST.json +11 -0
- package/dist/avid-panel/avid-manifest.json +46 -0
- package/dist/avid-panel/icon.svg +4 -0
- package/dist/avid-panel/icons/conformtools.svg +4 -0
- package/dist/avid-panel/index.html +26 -0
- package/dist/avid-panel/panel.css +12 -0
- package/dist/avid-panel/panel.js +7 -0
- package/dist/bridge-D5KPIUSY.js +3 -0
- package/dist/browser/timeline_core_bg.wasm +0 -0
- package/dist/chunk-3OCQA33E.js +3 -0
- package/dist/chunk-3XD6NC4G.js +10 -0
- package/dist/chunk-5JBUCVRI.js +20 -0
- package/dist/chunk-5RSNFPED.js +8 -0
- package/dist/chunk-5SUGU2YR.js +3 -0
- package/dist/chunk-6ML26TIK.js +3 -0
- package/dist/chunk-7D7H6VFW.js +3 -0
- package/dist/chunk-7MC7M2Y5.js +3 -0
- package/dist/chunk-AACY2V3L.js +3 -0
- package/dist/chunk-AS7IXHYM.js +19 -0
- package/dist/chunk-BL6L5ZBP.js +39 -0
- package/dist/chunk-C2ESM27Z.js +3 -0
- package/dist/chunk-C5IX63YF.js +3 -0
- package/dist/chunk-D6YDLKSA.js +3 -0
- package/dist/chunk-DKGGJM6Z.js +3 -0
- package/dist/chunk-EJGVNQ3E.js +8 -0
- package/dist/chunk-HGDO3OED.js +3 -0
- package/dist/chunk-JV7TZDKJ.js +3 -0
- package/dist/chunk-LFJLRLEP.js +3 -0
- package/dist/chunk-NFJHWZJX.js +3 -0
- package/dist/chunk-NQHQKEP5.js +3 -0
- package/dist/chunk-NU3X7P4N.js +3 -0
- package/dist/chunk-OJWIBQK4.js +376 -0
- package/dist/chunk-OVUCL3YY.js +5 -0
- package/dist/chunk-P7OVDUA5.js +3 -0
- package/dist/chunk-PFISREY4.js +3 -0
- package/dist/chunk-PFZVET7S.js +3 -0
- package/dist/chunk-PLRB2YXJ.js +3 -0
- package/dist/chunk-PSANHDZM.js +3 -0
- package/dist/chunk-RFIPLBQ4.js +5 -0
- package/dist/chunk-SZD4C5MB.js +6 -0
- package/dist/chunk-TK55FA56.js +3 -0
- package/dist/chunk-TXQR2HI2.js +4 -0
- package/dist/chunk-UCMNH6Q6.js +3 -0
- package/dist/chunk-UKKRZ574.js +7 -0
- package/dist/chunk-VS3MKKJ5.js +3 -0
- package/dist/chunk-X53BNWNV.js +3 -0
- package/dist/chunk-XNR7M4VX.js +3 -0
- package/dist/claude-setup-IIWUB4CE.js +5 -0
- package/dist/cli.js +17 -0
- package/dist/clip-state-B6JOX3JE.js +3 -0
- package/dist/conformtools-analyze +0 -0
- package/dist/conformtools-decode +0 -0
- package/dist/cr3-wasm-L2LFY3LM.js +3 -0
- package/dist/dng-wasm-U6NC3MDK.js +3 -0
- package/dist/dpx-wasm-RMKEUKED.js +3 -0
- package/dist/engine-P6H5P6HP.js +5 -0
- package/dist/esm-SFFBP7PS.js +3 -0
- package/dist/exr-wasm-LBAOMOZD.js +3 -0
- package/dist/flame/hook/conformtools_flame/__init__.py +10 -0
- package/dist/flame/hook/conformtools_flame/building.py +191 -0
- package/dist/flame/hook/conformtools_flame/hook.py +177 -0
- package/dist/flame/hook/conformtools_flame/render.py +622 -0
- package/dist/flame/hook/conformtools_flame/util.py +33 -0
- package/dist/flame/hook/conformtools_flame/verbs.py +1037 -0
- package/dist/flame/hook/conformtools_flame_hook.py +42 -0
- package/dist/fonts/gfx/BarlowCondensed-Bold.ttf +0 -0
- package/dist/fonts/gfx/BarlowCondensed-Regular.ttf +0 -0
- package/dist/fonts/gfx/InstrumentSerif-Regular.ttf +0 -0
- package/dist/fonts/gfx/Inter-Bold.ttf +0 -0
- package/dist/fonts/gfx/Inter-Regular.ttf +0 -0
- package/dist/fonts/gfx/JetBrainsMono-Bold.ttf +0 -0
- package/dist/fonts/gfx/JetBrainsMono-Regular.ttf +0 -0
- package/dist/fonts/gfx/OFL.txt +100 -0
- package/dist/framing-SRCJKAYO.js +3 -0
- package/dist/gfx-worker.js +3 -0
- package/dist/h264-3ESGVT6G.js +3 -0
- package/dist/h264-mxf-NPFS7NGH.js +3 -0
- package/dist/host-relink-D6CB2VOQ.js +10 -0
- package/dist/hosts-W4AD2MYH.js +3 -0
- package/dist/http.js +5 -0
- package/dist/i2o-transfer +0 -0
- package/dist/inspect-7ASUPU73.js +68 -0
- package/dist/isobmff-SIOE67WL.js +3 -0
- package/dist/mcp.js +13 -0
- package/dist/media-7AUNRKHF.js +3 -0
- package/dist/media_core-Q2PIEV7D.js +9 -0
- package/dist/media_core_bg-FDL7GJZP.js +3 -0
- package/dist/media_core_bg-XRBVKQZH.js +3 -0
- package/dist/mxf-74TTDICM.js +3 -0
- package/dist/nuke/panel/python/Startup/conformtools_nuke_startup.py +44 -0
- package/dist/nuke/panel/python/conformtools_nuke/__init__.py +10 -0
- package/dist/nuke/panel/python/conformtools_nuke/panel.py +217 -0
- package/dist/nuke/panel/python/conformtools_nuke/verbs.py +837 -0
- package/dist/ops-FSOOBXMV.js +3 -0
- package/dist/peer-kit/ctpeer/__init__.py +21 -0
- package/dist/peer-kit/ctpeer/client.py +247 -0
- package/dist/peer-kit/ctpeer/neutral.py +178 -0
- package/dist/peer-kit/ctpeer/pairing.py +139 -0
- package/dist/peer-kit/ctpeer/protocol.py +209 -0
- package/dist/peer-kit/ctpeer/websocket.py +289 -0
- package/dist/premiere-uxp/icons/panel.png +0 -0
- package/dist/premiere-uxp/icons/panel@2x.png +0 -0
- package/dist/premiere-uxp/icons/plugin.png +0 -0
- package/dist/premiere-uxp/icons/plugin@2x.png +0 -0
- package/dist/premiere-uxp/index.html +38 -0
- package/dist/premiere-uxp/index.js +93 -0
- package/dist/premiere-uxp/lib/clipmeta.js +170 -0
- package/dist/premiere-uxp/lib/ctx.js +68 -0
- package/dist/premiere-uxp/lib/edit.js +516 -0
- package/dist/premiere-uxp/lib/handles.js +57 -0
- package/dist/premiere-uxp/lib/markers.js +198 -0
- package/dist/premiere-uxp/lib/pairing.js +67 -0
- package/dist/premiere-uxp/lib/premiere.js +91 -0
- package/dist/premiere-uxp/lib/probe.js +241 -0
- package/dist/premiere-uxp/lib/protocol.js +165 -0
- package/dist/premiere-uxp/lib/render.js +45 -0
- package/dist/premiere-uxp/lib/session.js +85 -0
- package/dist/premiere-uxp/lib/sizing.js +325 -0
- package/dist/premiere-uxp/lib/time.js +88 -0
- package/dist/premiere-uxp/lib/timeline.js +336 -0
- package/dist/premiere-uxp/lib/verbs.js +21 -0
- package/dist/premiere-uxp/lib/write.js +97 -0
- package/dist/premiere-uxp/manifest.json +102 -0
- package/dist/probe-F7WQHMIA.js +3 -0
- package/dist/prores-RIG37OIH.js +526 -0
- package/dist/r3d-YTLOMC7C.js +3 -0
- package/dist/r3d-ZDJ3WURS.js +1025 -0
- package/dist/resolve-bridge.py +2286 -0
- package/dist/resolve-presets/conform.tools.xml +127 -0
- package/dist/source-BDJAUQVR.js +3 -0
- package/dist/statusline-GMMCFMOA.js +4 -0
- package/dist/statusline.js +3 -0
- package/dist/still-ZG2RUQAL.js +3 -0
- package/dist/store-ZHXLQCGN.js +3 -0
- package/dist/tiff-wasm-D2FJ3L56.js +3 -0
- package/dist/timeline-6DYFDVEH.js +3 -0
- package/dist/timeline_core-IOENXK4Z.js +3 -0
- package/dist/timeline_core_bg-JW42YM3G.js +3 -0
- package/dist/udf_bg-B37GKRIH.js +3 -0
- package/dist/wasm/media_core_bg.wasm +0 -0
- package/dist/wasm/udf_bg.wasm +0 -0
- package/dist/wasm-threads/media_core_bg.wasm +0 -0
- package/dist/wav-OWMUGQMM.js +3 -0
- package/package.json +6 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""CONFORM.TOOLS host plugin for Autodesk Flame.
|
|
2
|
+
|
|
3
|
+
`verbs.FlamePeer` answers the host-bridge capability verbs from Flame's Python
|
|
4
|
+
API; `hook.Controller` owns the bridge connection, the menu and the
|
|
5
|
+
preferences. `conformtools_flame_hook.py` (installed into a Flame Python hook
|
|
6
|
+
folder) is the only file Flame scans; it puts `conformtools_flame.zip` (this
|
|
7
|
+
package + the vendored `ctpeer` kit) on `sys.path` and forwards the hooks.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Timelines INTO Flame: `timeline_write.import_file` (decision D7's file
|
|
2
|
+
route - Flame gets ONE engine-written file, never a clip-by-clip build).
|
|
3
|
+
|
|
4
|
+
The app writes the timeline as FCPXML (`hosts/remote.py` NATIVE_FORMAT) with
|
|
5
|
+
the website's production engine, then asks this hook to import it:
|
|
6
|
+
|
|
7
|
+
1. `flame.import_clips(path, reel)` - Stefan's conform pipeline imports
|
|
8
|
+
AAF / FCPXML / OTIO this way (oracle/synth/runtime/flame/conform_pipeline.py).
|
|
9
|
+
The destination is a DESKTOP reel ("CONFORM.TOOLS" reel group, "Timelines"
|
|
10
|
+
reel): library sequences are locked for editing (his render oracle), and
|
|
11
|
+
the next step edits.
|
|
12
|
+
2. RELINK. An imported timeline's segments arrive UNLINKED (born offline,
|
|
13
|
+
source times relative to the media start). For every segment whose file is
|
|
14
|
+
on disk, the media is imported ONCE per path ("Sources" reel) and the
|
|
15
|
+
segment is pointed at it with `smart_replace_media` - in place first,
|
|
16
|
+
`duplicate_source()` + retry only on refusal - then SLIPPED so its source
|
|
17
|
+
in lands where the file says: `smart_replace_media` may re-seat the source
|
|
18
|
+
at the media's start timecode or keep the old offset (both measured by
|
|
19
|
+
Stefan, 2026-07-12/13), so the slip is computed from the state AFTER the
|
|
20
|
+
replace: wanted = clip start TC + relative in (or the in itself when it is
|
|
21
|
+
already a timecode frame inside the clip), `slip(-(wanted - got))`.
|
|
22
|
+
That is his `_relink_one`, the technique his oracle renders real pixels
|
|
23
|
+
with. A segment that will not relink is reported, never fatal.
|
|
24
|
+
3. A long relink must not hold Flame (or the 30 s call): segments past
|
|
25
|
+
`RELINK_BUDGET_S` continue in later idle events, `RELINK_CHUNK` at a time,
|
|
26
|
+
and the answer says how many are still pending.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
import os
|
|
32
|
+
import time
|
|
33
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
34
|
+
|
|
35
|
+
from ctpeer import PeerError
|
|
36
|
+
|
|
37
|
+
from .util import _s, _v
|
|
38
|
+
|
|
39
|
+
#: Timeline files Flame's `import_clips` reads.
|
|
40
|
+
IMPORTABLE = (".fcpxml", ".xml", ".aaf", ".edl", ".otio")
|
|
41
|
+
REEL_GROUP = "CONFORM.TOOLS"
|
|
42
|
+
TIMELINES_REEL = "Timelines"
|
|
43
|
+
SOURCES_REEL = "Sources"
|
|
44
|
+
#: Seconds of relinking inside the import call; the rest goes on idle events.
|
|
45
|
+
RELINK_BUDGET_S = 10.0
|
|
46
|
+
RELINK_CHUNK = 8
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class BuildVerbs:
|
|
50
|
+
"""Mixed into `verbs.FlamePeer`."""
|
|
51
|
+
|
|
52
|
+
# ── where imports land ──────────────────────────────────────────────
|
|
53
|
+
def _ct_reel(self, name: str) -> Any:
|
|
54
|
+
"""The desktop reel `REEL_GROUP / name`, made when missing."""
|
|
55
|
+
desktop = getattr(self._workspace(), "desktop", None)
|
|
56
|
+
if desktop is None:
|
|
57
|
+
raise PeerError("no_project", "No desktop in this workspace")
|
|
58
|
+
group = None
|
|
59
|
+
for rg in getattr(desktop, "reel_groups", None) or []:
|
|
60
|
+
if _s(getattr(rg, "name", "")) == REEL_GROUP:
|
|
61
|
+
group = rg
|
|
62
|
+
break
|
|
63
|
+
if group is None:
|
|
64
|
+
group = desktop.create_reel_group(REEL_GROUP)
|
|
65
|
+
for reel in getattr(group, "reels", None) or []:
|
|
66
|
+
if _s(getattr(reel, "name", "")) == name:
|
|
67
|
+
return reel
|
|
68
|
+
return group.create_reel(name)
|
|
69
|
+
|
|
70
|
+
# ── relink (Stefan's _relink_one) ───────────────────────────────────
|
|
71
|
+
def _tc_frame(self, t: Any, fps: float) -> int:
|
|
72
|
+
return self._abs(t, fps)
|
|
73
|
+
|
|
74
|
+
def _relink_segment(self, seg: Any, clips: Dict[str, Any], sources: Any) -> Optional[str]:
|
|
75
|
+
"""Point one unlinked segment at its file. None on success, else why not."""
|
|
76
|
+
path = _s(getattr(seg, "file_path", ""))
|
|
77
|
+
if not path or not os.path.exists(path):
|
|
78
|
+
return f"{_s(getattr(seg, 'name', '')) or '?'}: no file at {path or '(none)'}"
|
|
79
|
+
fps = self._rate_of(seg)
|
|
80
|
+
pre_in = self._tc_frame(getattr(seg, "source_in", None), fps)
|
|
81
|
+
clip = clips.get(path)
|
|
82
|
+
if clip is None:
|
|
83
|
+
got = self.flame.import_clips(path, sources) or []
|
|
84
|
+
clip = got[0] if got else None
|
|
85
|
+
if clip is None:
|
|
86
|
+
return f"{os.path.basename(path)}: Flame could not import the media"
|
|
87
|
+
clips[path] = clip
|
|
88
|
+
try:
|
|
89
|
+
seg.smart_replace_media(clip)
|
|
90
|
+
except Exception:
|
|
91
|
+
try:
|
|
92
|
+
seg.duplicate_source()
|
|
93
|
+
seg.smart_replace_media(clip)
|
|
94
|
+
except Exception as e:
|
|
95
|
+
return f"{os.path.basename(path)}: Flame refused the relink ({e})"
|
|
96
|
+
clip_tc = self._tc_frame(getattr(clip, "start_time", None), fps)
|
|
97
|
+
length = self._count(getattr(clip, "duration", None), fps)
|
|
98
|
+
post_in = self._tc_frame(getattr(seg, "source_in", None), fps)
|
|
99
|
+
inside = clip_tc <= pre_in < clip_tc + max(1, length)
|
|
100
|
+
wanted = pre_in if (clip_tc and inside) else clip_tc + pre_in
|
|
101
|
+
delta = wanted - post_in
|
|
102
|
+
if delta:
|
|
103
|
+
try:
|
|
104
|
+
seg.slip(-delta)
|
|
105
|
+
except Exception as e:
|
|
106
|
+
return f"{os.path.basename(path)}: relinked, but the source could not be slipped {delta} frame(s) ({e})"
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
def _rate_of(self, seg: Any) -> float:
|
|
110
|
+
from .util import parse_rate
|
|
111
|
+
|
|
112
|
+
rate = _s(getattr(seg, "source_frame_rate", ""))
|
|
113
|
+
return parse_rate(rate)[0] if rate else 24.0
|
|
114
|
+
|
|
115
|
+
def _unlinked_segments(self, seq: Any) -> List[Any]:
|
|
116
|
+
out = []
|
|
117
|
+
for track in self._video_tracks(seq) + self._audio_tracks(seq):
|
|
118
|
+
for seg in self._track_segments(track):
|
|
119
|
+
unlinked = _v(getattr(seg, "source_unlinked", None))
|
|
120
|
+
if unlinked is None or bool(unlinked):
|
|
121
|
+
out.append(seg)
|
|
122
|
+
return out
|
|
123
|
+
|
|
124
|
+
def _relink_some(self, todo: List[Any], clips: Dict[str, Any], sources: Any, issues: List[str],
|
|
125
|
+
budget_s: Optional[float]) -> Tuple[int, List[Any]]:
|
|
126
|
+
done, t0 = 0, time.monotonic()
|
|
127
|
+
while todo:
|
|
128
|
+
if budget_s is not None and time.monotonic() - t0 > budget_s:
|
|
129
|
+
break
|
|
130
|
+
seg = todo.pop(0)
|
|
131
|
+
why = self._relink_segment(seg, clips, sources)
|
|
132
|
+
if why:
|
|
133
|
+
issues.append(why)
|
|
134
|
+
else:
|
|
135
|
+
done += 1
|
|
136
|
+
return done, todo
|
|
137
|
+
|
|
138
|
+
def _relink_later(self, todo: List[Any], clips: Dict[str, Any], sources: Any, label: str) -> None:
|
|
139
|
+
"""Continue a relink on idle events, a chunk at a time."""
|
|
140
|
+
state = {"done": 0, "issues": []}
|
|
141
|
+
|
|
142
|
+
def step() -> None:
|
|
143
|
+
chunk, rest = todo[:RELINK_CHUNK], todo[RELINK_CHUNK:]
|
|
144
|
+
done, _ = self._relink_some(chunk, clips, sources, state["issues"], None)
|
|
145
|
+
state["done"] += done
|
|
146
|
+
todo[:] = rest
|
|
147
|
+
if todo:
|
|
148
|
+
self.flame.schedule_idle_event(step)
|
|
149
|
+
else:
|
|
150
|
+
msg = f"{label}: relinked {state['done']} more segment(s)"
|
|
151
|
+
if state["issues"]:
|
|
152
|
+
msg += f", {len(state['issues'])} could not be relinked"
|
|
153
|
+
log = getattr(self, "_log_console", None)
|
|
154
|
+
if callable(log):
|
|
155
|
+
log(msg)
|
|
156
|
+
|
|
157
|
+
self.flame.schedule_idle_event(step)
|
|
158
|
+
|
|
159
|
+
# ── the capability ──────────────────────────────────────────────────
|
|
160
|
+
def v_timeline_write__import_file(self, project: Any = None, path: str = "", sequences: Any = None) -> Dict[str, Any]:
|
|
161
|
+
path = str(path or "")
|
|
162
|
+
ext = os.path.splitext(path)[1].lower()
|
|
163
|
+
if ext not in IMPORTABLE:
|
|
164
|
+
raise PeerError("unsupported_format", f"Flame imports FCPXML, XML, AAF, EDL and OTIO timelines, not {ext or 'this file'}")
|
|
165
|
+
if not os.path.isfile(path):
|
|
166
|
+
raise PeerError("not_found", f"no file at {path}")
|
|
167
|
+
reel = self._ct_reel(TIMELINES_REEL)
|
|
168
|
+
imported = [o for o in (self.flame.import_clips(path, reel) or []) if self._is_sequence(o)]
|
|
169
|
+
self._invalidate_pool()
|
|
170
|
+
if not imported:
|
|
171
|
+
return {"ok": False, "imported": [], "issues": [f"Flame imported no sequence from {os.path.basename(path)}"]}
|
|
172
|
+
issues: List[str] = []
|
|
173
|
+
sources = None
|
|
174
|
+
clips: Dict[str, Any] = {}
|
|
175
|
+
relinked = pending = 0
|
|
176
|
+
for seq in imported:
|
|
177
|
+
todo = self._unlinked_segments(seq)
|
|
178
|
+
if not todo:
|
|
179
|
+
continue
|
|
180
|
+
if sources is None:
|
|
181
|
+
sources = self._ct_reel(SOURCES_REEL)
|
|
182
|
+
done, rest = self._relink_some(todo, clips, sources, issues, RELINK_BUDGET_S)
|
|
183
|
+
relinked += done
|
|
184
|
+
if rest:
|
|
185
|
+
pending += len(rest)
|
|
186
|
+
self._relink_later(rest, clips, sources, _s(getattr(seq, "name", "")))
|
|
187
|
+
if pending:
|
|
188
|
+
issues.append(f"{pending} segment(s) are still relinking in Flame (watch the message bar)")
|
|
189
|
+
self._invalidate_pool()
|
|
190
|
+
return {"ok": True, "imported": [{"name": _s(getattr(s, "name", "")), "handle": self._wrap("seq", s)} for s in imported],
|
|
191
|
+
"issues": issues, "relinked": relinked, "relink_pending": pending}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""The hook's controller: the bridge connection, Flame's main menu entry, and
|
|
2
|
+
the one preference (connect automatically when a project opens).
|
|
3
|
+
|
|
4
|
+
All Flame API calls go through `flame.schedule_idle_event` (Autodesk: an idle
|
|
5
|
+
event runs "in the main application thread" and must be quick); the bridge
|
|
6
|
+
client's own threads only wait. Nothing here runs a command, opens a path or
|
|
7
|
+
evaluates anything the app sends: requests reach `verbs.FlamePeer` methods by
|
|
8
|
+
exact name through `ctpeer.Dispatcher`, and nothing else.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
17
|
+
|
|
18
|
+
from ctpeer import BridgeClient, idle_marshaller
|
|
19
|
+
|
|
20
|
+
from . import __version__
|
|
21
|
+
from .verbs import CAPABILITIES, OPTIONAL_VERBS, FlamePeer
|
|
22
|
+
|
|
23
|
+
MENU = "CONFORM.TOOLS"
|
|
24
|
+
PREFS_ENV = "CONFORM_TOOLS_FLAME_PREFS"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def prefs_path() -> str:
|
|
28
|
+
return os.environ.get(PREFS_ENV) or os.path.join(os.path.expanduser("~"), ".conformtools", "flame_hook.json")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load_prefs(path: Optional[str] = None) -> Dict[str, Any]:
|
|
32
|
+
try:
|
|
33
|
+
with open(path or prefs_path(), "r", encoding="utf-8") as f:
|
|
34
|
+
data = json.load(f)
|
|
35
|
+
return data if isinstance(data, dict) else {}
|
|
36
|
+
except (OSError, ValueError):
|
|
37
|
+
return {}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def save_prefs(prefs: Dict[str, Any], path: Optional[str] = None) -> None:
|
|
41
|
+
path = path or prefs_path()
|
|
42
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
43
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
44
|
+
json.dump(prefs, f, indent=2)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Controller:
|
|
48
|
+
def __init__(self, flame: Any, client_factory: Callable[..., BridgeClient] = BridgeClient,
|
|
49
|
+
prefs_file: Optional[str] = None, read_pairing: Optional[Callable[[], Dict[str, Any]]] = None):
|
|
50
|
+
self.flame = flame
|
|
51
|
+
self.client_factory = client_factory
|
|
52
|
+
self.prefs_file = prefs_file
|
|
53
|
+
self.read_pairing = read_pairing
|
|
54
|
+
self.client: Optional[BridgeClient] = None
|
|
55
|
+
self.peer: Optional[FlamePeer] = None
|
|
56
|
+
self.lines: List[str] = []
|
|
57
|
+
|
|
58
|
+
# -- preferences ---------------------------------------------------------
|
|
59
|
+
@property
|
|
60
|
+
def auto_connect(self) -> bool:
|
|
61
|
+
return bool(load_prefs(self.prefs_file).get("auto_connect", False))
|
|
62
|
+
|
|
63
|
+
def set_auto_connect(self, on: bool) -> None:
|
|
64
|
+
prefs = load_prefs(self.prefs_file)
|
|
65
|
+
prefs["auto_connect"] = bool(on)
|
|
66
|
+
save_prefs(prefs, self.prefs_file)
|
|
67
|
+
|
|
68
|
+
# -- logging -------------------------------------------------------------
|
|
69
|
+
def log(self, line: str) -> None:
|
|
70
|
+
self.lines = (self.lines + [line])[-200:]
|
|
71
|
+
print(f"[{MENU}] {line}", file=sys.stderr)
|
|
72
|
+
|
|
73
|
+
def _console(self, message: str, kind: str = "info") -> None:
|
|
74
|
+
"""Flame's message bar, on the main thread."""
|
|
75
|
+
def show() -> None:
|
|
76
|
+
try:
|
|
77
|
+
self.flame.messages.show_in_console(f"{MENU}: {message}", kind, 6)
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
try:
|
|
81
|
+
self.flame.schedule_idle_event(show)
|
|
82
|
+
except Exception:
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
def _on_state(self, state: str, detail: str) -> None:
|
|
86
|
+
if state == "connected":
|
|
87
|
+
self._console("connected to the app")
|
|
88
|
+
elif state == "refused":
|
|
89
|
+
self._console(f"the app refused the connection ({detail})", "warning")
|
|
90
|
+
elif state == "unpaired" and self.client is not None and self.client.attempt == 0:
|
|
91
|
+
self._console("turn on the Host Bridge in CONFORM.TOOLS (Settings)", "warning")
|
|
92
|
+
|
|
93
|
+
# -- connection ----------------------------------------------------------
|
|
94
|
+
@property
|
|
95
|
+
def running(self) -> bool:
|
|
96
|
+
return self.client is not None
|
|
97
|
+
|
|
98
|
+
def host_info(self) -> Dict[str, Any]:
|
|
99
|
+
try:
|
|
100
|
+
version = str(self.flame.get_version())
|
|
101
|
+
except Exception:
|
|
102
|
+
version = ""
|
|
103
|
+
return {"id": "flame", "name": "Flame", "version": version, "platform": sys.platform, "plugin_version": __version__}
|
|
104
|
+
|
|
105
|
+
def connect(self) -> BridgeClient:
|
|
106
|
+
if self.client is not None:
|
|
107
|
+
return self.client
|
|
108
|
+
self.peer = FlamePeer(self.flame)
|
|
109
|
+
kwargs: Dict[str, Any] = {}
|
|
110
|
+
if self.read_pairing is not None:
|
|
111
|
+
kwargs["read_pairing"] = self.read_pairing
|
|
112
|
+
self.client = self.client_factory(
|
|
113
|
+
host=self.host_info(), capabilities=CAPABILITIES, optional_verbs=OPTIONAL_VERBS, verbs=self.peer.verbs(),
|
|
114
|
+
run_on_main=idle_marshaller(lambda fn: self.flame.schedule_idle_event(fn)),
|
|
115
|
+
log=self.log, on_state=self._on_state, **kwargs)
|
|
116
|
+
self.client.start()
|
|
117
|
+
return self.client
|
|
118
|
+
|
|
119
|
+
def disconnect(self) -> None:
|
|
120
|
+
client, self.client = self.client, None
|
|
121
|
+
if client is not None:
|
|
122
|
+
client.stop()
|
|
123
|
+
self._console("disconnected")
|
|
124
|
+
|
|
125
|
+
def status(self) -> str:
|
|
126
|
+
if self.client is None:
|
|
127
|
+
return "Not connected (the bridge connection is off)"
|
|
128
|
+
return {"connected": "Connected to CONFORM.TOOLS", "unpaired": "Waiting for the app (turn on its Host Bridge)",
|
|
129
|
+
"connecting": "Connecting...", "hello": "Connecting...", "refused": f"Refused by the app ({self.client.detail})",
|
|
130
|
+
"closed": "Waiting for the app"}.get(self.client.state, self.client.state)
|
|
131
|
+
|
|
132
|
+
def project_changed(self, project_name: Any = None) -> None:
|
|
133
|
+
"""Flame calls `app_initialized` whenever the project changes: handles
|
|
134
|
+
minted for the old project mean nothing now, so the peer starts over;
|
|
135
|
+
the app hears it as an inert event."""
|
|
136
|
+
if self.peer is not None:
|
|
137
|
+
self.peer.handles.clear()
|
|
138
|
+
if self.client is not None:
|
|
139
|
+
self.client.event("project_changed", {"project": str(project_name or "")})
|
|
140
|
+
elif self.auto_connect:
|
|
141
|
+
self.connect()
|
|
142
|
+
|
|
143
|
+
# -- the main menu ---------------------------------------------------------
|
|
144
|
+
def _show_status(self, selection: Any = None) -> None:
|
|
145
|
+
try:
|
|
146
|
+
self.flame.messages.show_in_dialog(title=MENU, message=self.status(), type="info", buttons=["OK"])
|
|
147
|
+
except Exception:
|
|
148
|
+
self.log(self.status())
|
|
149
|
+
|
|
150
|
+
def menu(self) -> List[Dict[str, Any]]:
|
|
151
|
+
return [{
|
|
152
|
+
"name": MENU,
|
|
153
|
+
"actions": [
|
|
154
|
+
{"name": "Connect to CONFORM.TOOLS", "execute": lambda sel=None: self.connect(), "isVisible": lambda sel=None: not self.running,
|
|
155
|
+
"minimumVersion": "2025"},
|
|
156
|
+
{"name": "Disconnect from CONFORM.TOOLS", "execute": lambda sel=None: self.disconnect(), "isVisible": lambda sel=None: self.running,
|
|
157
|
+
"minimumVersion": "2025"},
|
|
158
|
+
{"name": "Connection Status", "execute": self._show_status, "minimumVersion": "2025"},
|
|
159
|
+
{"name": "Connect Automatically: Turn On", "execute": lambda sel=None: self.set_auto_connect(True),
|
|
160
|
+
"isVisible": lambda sel=None: not self.auto_connect, "minimumVersion": "2025"},
|
|
161
|
+
{"name": "Connect Automatically: Turn Off", "execute": lambda sel=None: self.set_auto_connect(False),
|
|
162
|
+
"isVisible": lambda sel=None: self.auto_connect, "minimumVersion": "2025"},
|
|
163
|
+
],
|
|
164
|
+
}]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
_controller: Optional[Controller] = None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def controller(flame: Any = None) -> Controller:
|
|
171
|
+
"""The one controller of this Flame session."""
|
|
172
|
+
global _controller
|
|
173
|
+
if _controller is None:
|
|
174
|
+
if flame is None:
|
|
175
|
+
import flame # type: ignore # the real module, inside Flame only
|
|
176
|
+
_controller = Controller(flame)
|
|
177
|
+
return _controller
|