displaydev.jndisplay

displaydev.jndisplay

class displaydev.jndisplay.JNDevices(display_drv)[source]

Bases: object

Unified input for Jupyter Notebook, registered as an appdev HOST device.

Creates the interactive ipywidgets Image that mirrors the display buffer and watches it (via ipyevents) for all available input, turning it into events objects (matching the desktop SDL2 / PyGame event stream), drained through read:

  • Mouse: MOUSEMOTION on every move, MOUSEBUTTONDOWN / MOUSEBUTTONUP for any button.

  • Wheel: MOUSEWHEEL (also consumed by encoder devices).

  • Keyboard: KEYDOWN / KEYUP with SDL-style key codes, names and modifier masks (left/right modifier variants via key location).

Quit chord handling is configured on JNDisplay via quit_chord (default (keys.K_AC_BACK, 0)). HostEvents applies the chord when constructed with display=.

This class also owns the display widget: JNDisplay pushes frames to it via update_buffer.

Note

The Image widget must be focused (e.g. clicked) to receive key events, and some keys may be consumed by the notebook front end (JupyterLab / classic Notebook / VS Code) before they reach the widget.

Parameters:

display_drv (JNDisplay) – Display whose buffer is shown on the Image widget.

read()[source]

Returns queued input events for an appdev device.

Returns:

list or None – The events received since the last call, or None.

update_buffer(pil_image)[source]

Push a PIL image to the interactive widget.

class displaydev.jndisplay.JNDisplay(width, height, *, quiet=False)[source]

Bases: DesktopDisplay

Emulate a display in a Jupyter Notebook output cell.

Supports ILI9341-style vertical scroll emulation (same band compositing as SDL/PG/PS). Interactive output uses JNDevices; static notebooks can call show without a device.

Parameters:
  • width (int) – Panel width in pixels.

  • height (int) – Panel height in pixels.

  • quiet (bool) – Suppress init chatter when True.

color_depth

Bits per pixel (16).

Type:

int

touch_scale

Pointer scale for QueueDevice (always 1.0).

Type:

float

quit_chord

Keyboard chord for quit (default browser Back); None disables.

needs_refresh

True — appdev.App drives periodic show().

Type:

bool

get_events()[source]

Drain Jupyter input; lazily create JNDevices on first use.

Static notebooks that only call show never touch this and keep the non-interactive path.

init()[source]

Initializes the display instance. Called by __init__ and rotation setter.

fill_rect(x, y, w, h, c)[source]

Fills a rectangle with the given color.

Parameters:
  • x (int) – The x-coordinate of the top-left corner of the rectangle.

  • y (int) – The y-coordinate of the top-left corner of the rectangle.

  • w (int) – The width of the rectangle.

  • h (int) – The height of the rectangle.

  • c (int) – The color to fill the rectangle with.

Returns:

(tuple) – A tuple containing the x, y, w, h values

blit_rect(buf, x, y, w, h)[source]

Blits a buffer to the display at the given coordinates.

Parameters:
  • buf (bytearray) – The buffer to blit to the display.

  • x (int) – The x-coordinate of the top-left corner of the buffer.

  • y (int) – The y-coordinate of the top-left corner of the buffer.

  • w (int) – The width of the buffer.

  • h (int) – The height of the buffer.

Returns:

(tuple) – A tuple containing the x, y, w, h values.

pixel(x, y, c)[source]

Sets a pixel to the given color.

Parameters:
  • x (int) – The x-coordinate of the pixel.

  • y (int) – The y-coordinate of the pixel.

  • c (int) – The color to set the pixel to.

Returns:

(tuple) – A tuple containing the x, y, w and h values.

render(render_rect=None)[source]

Composite offscreen buffer to visible frame, applying vertical scroll.

show(_timer=None)[source]

Updates the display with the current buffer.