Skip to main content

A utility library for interacting with JAnim GUI via standard input/output

Project description

JAnim Stdio Interact

MIT License PyPI Latest Release

> English < | 简体中文

A utility library for interacting with JAnim GUI and managing windows via standard input/output

Basic Usage

Interact with the JAnim GUI by passing JSON commands via stdio to open and close specific instances.

First, start the janim-stdio-i program:

janim-stdio-i host

For example, to compile a code snippet and build the Timeline within it for display in a preview window, send the following to stdin:

{"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(HelloJAnimExample): pass"}

You will see a preview window open displaying the classic HelloJAnimExample.

[!WARNING] All commands sent to stdin must be on a single line. Multi-line commands will be truncated.

Here, "key": "id1" is used for window reuse. If you send an execute command with the same key, the Timeline in the existing window will be replaced without opening a new window.

{"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(RotatingPieExample): ..."}

Sending the command above replaces the HelloJAnimExample in the original window with RotatingPieExample.

[!NOTE] If a code snippet contains multiple Timelines, the first one is used for the initial build.

On subsequent rebuilds (replacements), it attempts to find a Timeline with the same name as the previous one; if not found, it defaults to the first one.

If we use a different key, for example:

{"type": "execute", "key": "id2", "source": "from janim.examples import *\nclass A(ArrowPointingExample): ..."}

A new window will open. Essentially, one key corresponds to one window.

In addition to compiling and building Timelines via stdin, information generated by the GUI is returned via stdout. See below for details.

API Reference

stdin

  • "type": "execute"

    Required parameters:

    • "key": Unique identifier for the window.
    • "source": Source code for compilation.

    Compiles and builds the Timeline to display in the preview window.

    If the window corresponding to key already exists, the original Timeline in that window is replaced with the new one.

    Example:

    {"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(HelloJAnimExample): pass"}
    
  • "type": "close"

    Required parameters:

    • "key": Unique identifier for the window.

    Closes the window corresponding to key.

    Example:

    {"type": "close", "key": "id1"}
    

stdout

{"type": "viewer-msg", "key": "...", "from": "...", "janim": { ... }}
Field Type Description
type string Fixed as "viewer-msg", identifying the message category
key string Corresponds to the identifier key used during creation
from string Sender source. Possible values: "execute", "close", "gui"
janim object The specific event payload, containing the event type and data

When "from": "execute", it represents the result of the execute command sent to stdin:

  • When source code compilation fails, the payload is

    "janim": {"type": "error", "reason": "compile-failed"}
    
  • When the source code contains no usable Timeline, the payload is:

    "janim": {"type": "error", "reason": "no-timeline"}
    
  • When the Timeline build fails, the payload is:

    "janim": {"type": "error", "reason": "build-failed"}
    
  • When execution is successful, the payload is:

    "janim": {"type": "success"}
    

When "from": "close", it represents the result of the close command sent to stdin:

  • When no preview interface is found for the identifier, the payload is:

    "janim": {"type": "error", "reason": "not-found"}
    
  • When executed successfully, the payload is:

    "janim": {"type": "success"}
    

When "from": "gui", it represents information generated by the GUI:

  • When the interface is created, the payload is:

    "janim": {"type": "created"}
    
  • When the interface content is replaced, the payload is:

    "janim": {"type": "rebuilt"}
    
  • When the preview progress changes, the payload is:

    "janim": {"type": "lineno", "data": <current_line_number>}
    
  • When the interface is closed, the payload is:

    "janim": {"type": "close_event"}
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

janim_stdio_interact-0.1.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

janim_stdio_interact-0.1.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file janim_stdio_interact-0.1.2.tar.gz.

File metadata

  • Download URL: janim_stdio_interact-0.1.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for janim_stdio_interact-0.1.2.tar.gz
Algorithm Hash digest
SHA256 98d826803621f003c5c596c47126305831ef14207c5ab60e289ae3cf6e0d51c1
MD5 9d63b0ee261930869f7ebd5c6a7f9be2
BLAKE2b-256 f5bdf0d86f8e472bf835e8e9183ede738465ad9db71cefffc72faaf0f0afaad8

See more details on using hashes here.

File details

Details for the file janim_stdio_interact-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for janim_stdio_interact-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be165cdc4997a0c87303bb0e9a6bfd89e1147e1284d29d108a9ffe0228f403f3
MD5 f5004203552786987d3b6b4dd5a1c6ff
BLAKE2b-256 c9f98d52ee9277c4a65521f158aed4f5dfa5af330cce4515419194adefc135f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page