displaydev.psdisplay

displaydev.psdisplay

class displaydev.psdisplay.PSDevices(id, display=None)[source]

Bases: WebInput

Unified input for a PyScript canvas, registered as an appdev HOST device.

Captures all available browser input on a single HTML element and turns it into events objects (matching the desktop SDL2 / PyGame event stream), drained through read:

  • Pointer (mouse via Pointer Events): MOUSEMOTION / MOUSEBUTTONDOWN / MOUSEBUTTONUP.

  • Touch / pen (Pointer Events with pointerType other than mouse): FINGERDOWN / FINGERUP / FINGERMOTION with pointerId as finger_id, so LVGL gesture recognizers see multipoint contacts (same contract as SDL/pygame fingers). A finger move also gives MOUSEMOTION with touch=True, and a finger down or up a Button with touch=True, so drag code written for the mouse works.

  • 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).

  • Gamepad (Gamepad API, polled on each read): JOYAXISMOTION, JOYBUTTONDOWN / JOYBUTTONUP.

Quit chord handling is configured on PSDisplay via quit_chord (default (keys.K_AC_BACK, 0) for browser/TV Back). HostEvents applies the chord when constructed with display=.

Note

The element must be focused to receive key events. The constructor sets tabindex and calls _focus_canvas so keyboard input goes to the game; pointer down on the canvas refocuses it.

Parameters:
  • id (str) – The id of the element to watch (usually the canvas).

  • display (PSDisplay, optional) – Pass the same PSDisplay used as QueueDevice data (for touch_scale pointer mapping).

deinit()[source]

Detach DOM event listeners and destroy Pyodide proxies.

class displaydev.psdisplay.PSDisplay(id, width=None, height=None, *, quiet=False)[source]

Bases: CanvasDisplay

Emulate a display on a PyScript HTML canvas.

Parameters:
  • id (str) – DOM id of the canvas element.

  • width (int, optional) – Panel width; defaults to the canvas width.

  • height (int, optional) – Panel height; defaults to the canvas height.

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

needs_refresh

True — appdev.App drives periodic show().

Type:

bool

property touch_scale

CSS layout pixels per framebuffer pixel, read live.

HostEventsDevice divides mouse coordinates by this, the same contract as SDLDisplay’s window scale. It is the inverse of _pointer_scale, and it is read at each event because the page can resize the canvas (a max-width rule, a window resize) after init has run.

map_pointer(local_x, local_y)[source]

Map element-local pointer coordinates to framebuffer (x, y).

PSDevices maps touch/pen to panel pixels at capture (FINGER*); mouse coords stay CSS-local and HostEventsDevice applies touch_scale.

map_pointer_rel(dx, dy)[source]

Map a DOM pointer delta (movementX/movementY) to framebuffer pixels.