WgpuAutoGui

class wgpu.gui.WgpuAutoGui(*args, **kwargs)

Bases: object

Mixin class for canvases implementing autogui.

This class provides a common API for handling events and registering event handlers. It adds to WgpuCanvasBase that interactive examples and applications can be written in a generic way (no-GUI specific code).

add_event_handler(*args)

Register an event handler to receive events.

Parameters:
  • callback (callable) – The event handler. Must accept a single event argument.

  • *types (list of strings) – A list of event types.

For the available events, see https://jupyter-rfb.readthedocs.io/en/stable/events.html.

The callback is stored, so it can be a lambda or closure. This also means that if a method is given, a reference to the object is held, which may cause circular references or prevent the Python GC from destroying that object.

Example:

def my_handler(event):
    print(event)

canvas.add_event_handler(my_handler, "pointer_up", "pointer_down")

Can also be used as a decorator:

@canvas.add_event_handler("pointer_up", "pointer_down")
def my_handler(event):
    print(event)

Catch ‘m all:

canvas.add_event_handler(my_handler, "*")
handle_event(event)

Handle an incoming event.

Subclasses can overload this method. Events include widget resize, mouse/touch interaction, key events, and more. An event is a dict with at least the key event_type. For details, see https://jupyter-rfb.readthedocs.io/en/stable/events.html

The default implementation dispatches the event to the registered event handlers.

Parameters:

event (dict) – the event to handle.

remove_event_handler(callback, *types)

Unregister an event handler.

Parameters:
  • callback (callable) – The event handler.

  • *types (list of strings) – A list of event types.