Skip to content

Implement fixes from GlowScript - #108

Merged
BruceSherwood merged 1 commit into
masterfrom
Implement_fixes_from_GlowScript
Jul 30, 2020
Merged

Implement fixes from GlowScript#108
BruceSherwood merged 1 commit into
masterfrom
Implement_fixes_from_GlowScript

Conversation

@BruceSherwood

Copy link
Copy Markdown
Member

No description provided.

@BruceSherwood
BruceSherwood merged commit 3d419ce into master Jul 30, 2020
@BruceSherwood
BruceSherwood deleted the Implement_fixes_from_GlowScript branch July 30, 2020 03:22
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant