Implement fixes from GlowScript - #108
Merged
Merged
Conversation
sspickle
added a commit
that referenced
this pull request
Aug 15, 2026
Third transport beside with_notebook (Jupyter Comm) and no_notebook (http.server + autobahn in threads). In a Web Worker none of that exists — no Jupyter, no servers, no threads — but the host JS environment has postMessage. So the contract is two functions on the JS global scope: * the host defines __trinket_vpython_send(jsonString) BEFORE importing vpython; every outbound update package (and the 'trigger' handshake) goes through it * this module sets __trinket_vpython_dispatch(jsonArrayOfEvents); the host calls it as browser events arrive, and every call — including a bare trigger — is answered with a flush, the same request/reply rhythm the websocket transport uses, paced by the browser's ~33 ms canvas_update timer Selection is sys.platform == 'emscripten' in baseObj.__init__, tried after _isnotebook so a notebook running under Pyodide (JupyterLite) still gets its Comm. Importing the module IS the setup, exactly like the other two: GlowWidget() first (it nulls the module-global sender outside a notebook), then install ours, then an initial trigger() so the scene canvas buffered during `import vpython` flushes and baseObj.sent unblocks appendcmd. Verified end-to-end in trinket's real #108 worker (Pyodide 3.13.2, this branch's pure wheel, deps=False), with send captured on the Python side: MSG 0: {"cmds": [{"cmd": "canvas", ...}, {"cmd": "distant_light", ...} x2]} MSG 1: {"cmds": [{"cmd": "sphere", "idx": 4, "color": [1,0,0], ...}], "attrs": ["a4a1,2,3"]} MSG 1's attrs entry is ball.pos = vector(1,2,3) in the protocol's compact per-attribute wire coding — constructors, attribute updates and the browser-driven flush all cross the seam. What remains is the OTHER half of the pipe: a browser-side consumer of this stream (glowcomm.js reads the identical format from a Comm), which lives in the embedding host, not here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.