vispy.app.canvas.
Canvas
Bases: object
object
Representation of a GUI element with an OpenGL context
The widget title
The size of the window.
The position of the window in screen coordinates.
Whether to show the widget immediately. Default False.
Whether to swap the buffers automatically after a draw event. Default True. If True, the swap_buffers Canvas method will be called last (by default) by the canvas.draw event handler.
swap_buffers
canvas.draw
Give vispy Application instance to use as a backend. (vispy.app is used by default.) If str, then an application using the chosen backend (e.g., ‘pyglet’) will be created. Note the canvas application can be accessed at canvas.app.
canvas.app
Whether to create the widget immediately. Default True.
Enable vertical synchronization.
Allow the window to be resized.
Decorate the window. Default True.
If False, windowed mode is used (default). If True, the default monitor is used. If int, the given monitor number is used.
A dict with OpenGL configuration options, which is combined with the default configuration options and used to initialize the context. See canvas.context.config for possible options.
canvas.context.config
An existing canvas or context to share OpenGL objects with.
Default key mapping to use. If ‘interactive’, escape and F11 will close the canvas and toggle full-screen mode, respectively. If dict, maps keys to functions. If dict values are strings, they are assumed to be Canvas methods, otherwise they should be callable.
The parent widget if this makes sense for the used backend.
Resolution in dots-per-inch to use for the canvas. If dpi is None, then the value will be determined by querying the global config first, and then the operating system.
If True, try to create the window in always-on-top mode.
A scale factor to apply between logical and physical pixels in addition to the actual scale factor determined by the backend. This option allows the scale factor to be adjusted for testing.
Keyword arguments to be supplied to the backend canvas object.
Notes
The Canvas receives the following events:
initialize resize draw mouse_press mouse_release mouse_double_click mouse_move mouse_wheel key_press key_release stylus touch close
initialize
resize
draw
mouse_press
mouse_release
mouse_double_click
mouse_move
mouse_wheel
key_press
key_release
stylus
touch
close
The ordering of the mouse_double_click, mouse_press, and mouse_release events are not guaranteed to be consistent between backends. Only certain backends natively support double-clicking (currently Qt and WX); on other backends, they are detected manually with a fixed time delay. This can cause problems with accessibility, as increasing the OS detection time or using a dedicated double-click button will not be respected.
Backend-specific arguments can be given through the backend_kwargs argument. Currently this can be used to control the webGL context requested by the ipynb_webgl backend, for example:
canvas = Canvas(backend_kwargs={'webgl': dict(preserveDrawingBuffer=True)})
app
The vispy Application instance on which this Canvas is based.
Close the canvas
This will usually destroy the GL context. For Qt, the context (and widget) will be destroyed only if the widget is top-level. To avoid having the widget destroyed (more like standard Qt behavior), consider making the widget a sub-widget.
connect
Connect a function to an event
The name of the function should be on_X, with X the name of the event (e.g. ‘on_draw’).
This method is typically used as a decorator on a function definition for an event handler.
The function.
context
The OpenGL context of the native widget
It gives access to OpenGL functions to call on this canvas object, and to the shared context namespace.
create_native
Create the native widget if not already done so. If the widget is already created, this function does nothing.
dpi
The physical resolution of the canvas in dots per inch.
fps
The fps of canvas/window, as the rate that events.draw is emitted
fullscreen
measure_fps
Measure the current FPS
Sets the update window, connects the draw event to update_fps and sets the callback function.
The time-window (in seconds) to calculate FPS. Default 1.0.
The function to call with the float FPS value, or the string to be formatted with the fps value and then printed. The default is '%1.1f FPS'. If callback evaluates to False, the FPS measurement is stopped.
'%1.1f FPS'
native
The native widget object on which this Canvas is based.
physical_size
The physical size of the canvas/window, which may differ from the size property on backends that expose HiDPI
pixel_scale
The ratio between the number of logical pixels, or ‘points’, and the physical pixels on the device. In most cases this will be 1.0, but on certain backends this will be greater than 1. This should be used as a scaling factor when writing your own visualisations with gloo (make a copy and multiply all your logical pixel values by it). When writing Visuals or SceneGraph visualisations, this value is exposed as TransformSystem.px_scale.
position
The position of canvas/window relative to screen
render
Render the canvas to an offscreen buffer and return the image array.
Numpy array of type ubyte and shape (h, w, 4). Index [0, 0] is the upper-left corner of the rendered region.
set_current
Make this the active GL canvas
Not used.
show
Show or hide the canvas
Make the canvas visible.
Run the backend event loop.
size
The size of canvas/window
Swap GL buffers such that the offscreen buffer becomes visible
title
The title of canvas/window
update
Inform the backend that the Canvas needs to be redrawn
DrawEvent
Bases: vispy.util.event.Event
vispy.util.event.Event
Draw event class
This type of event is sent to Canvas.events.draw when a redraw is required.
Note that each event object has an attribute for each of the input arguments listed below.
String indicating the event type (e.g. mouse_press, key_release)
The region of the canvas which needs to be redrawn (x, y, w, h). If None, the entire canvas must be redrawn.
The native GUI event object
All extra keyword arguments become attributes of the event object.
region
KeyEvent
Key event class
The Key object for this event. Can be compared to string names.
The text representation of the key (can be an empty string).
Tuple that specifies which modifier keys were pressed down at the time of the event (shift, control, alt, meta).
key
modifiers
text
MouseEvent
Mouse event class
Note that each event object has an attribute for each of the input arguments listed below, as well as a “time” attribute with the event’s precision start time.
The position of the mouse (in screen coordinates).
The button that generated this event (can be None). Left=1, right=2, middle=3. During a mouse drag, this will return the button that started the drag (same thing as event.press_event.button).
event.press_event.button
The list of buttons depressed during this event.
The amount of scrolling in horizontal and vertical direction. One “tick” corresponds to a delta of 1.0.
The press event that was generated at the start of the current drag, if any.
The MouseEvent immediately preceding the current event. During drag operations, all generated events retain their last_event properties, allowing the entire drag to be reconstructed.
button
buttons
delta
drag_events
Return a list of all mouse events in the current drag operation.
Returns None if there is no current drag operation.
is_dragging
Indicates whether this event is part of a mouse drag operation.
last_event
pos
press_event
time
trail
Return an (N, 2) array of mouse coordinates for every event in the current mouse drag operation.
ResizeEvent
Resize event class
The new size of the Canvas, in points (logical pixels).
The new physical size of the Canvas, in pixels.