WgpuCanvasBase

class wgpu.gui.WgpuCanvasBase(*args, max_fps=30, vsync=True, **kwargs)

Bases: WgpuCanvasInterface

A convenient base canvas class.

This class provides a uniform API and implements common functionality, to increase consistency and reduce code duplication. It is convenient (but not strictly necessary) for canvas classes to inherit from this class (but all builtin canvases do).

This class provides an API for scheduling draws (request_draw()) and implements a mechanism to call the provided draw function (draw_frame()) and then present the result to the canvas.

This class also implements draw rate limiting, which can be set with the max_fps attribute (default 30). For benchmarks you may also want to set vsync to False.

close()

Close the window.

draw_frame()

The function that gets called at each draw.

You can implement this method in a subclass, or set it via a call to request_draw().

get_logical_size()

Get the logical size in float pixels.

get_physical_size()

Get the physical size in integer pixels.

get_pixel_ratio()

Get the float ratio between logical and physical pixels.

is_closed()

Get whether the window is closed.

request_draw(draw_function=None)

Schedule a new draw event.

This function does not perform a draw directly, but schedules a draw event at a suitable moment in time. In the draw event the draw function is called, and the resulting rendered image is presented to screen.

Parameters:

draw_function (callable or None) – The function to set as the new draw function. If not given or None, the last set draw function is used.

set_logical_size(width, height)

Set the window size (in logical pixels).