The app module defines three classes: Application, Canvas, and Timer. On loading, vispy creates a default Application instance which can be used via functions in the module’s namespace.
vispy.app.
use_app
(backend_name=None, call_reuse=True)[source]¶Get/create the default Application object
It is safe to call this function multiple times, as long as backend_name is None or matches the already selected backend.
Parameters: | backend_name : str | None
call_reuse : bool
|
---|
vispy.app.
process_events
()[source]¶Process all pending GUI events
If the mainloop is not running, this should be done regularly to keep the visualization interactive and to keep the event system going.
vispy.app.
Application
(backend_name=None)[source]¶Representation of the vispy application
This wraps a native GUI application instance. Vispy has a default instance of this class that can be created/obtained via vispy.app.use_app().
Parameters: | backend_name : str | None
|
---|
Notes
Upon creating an Application object, a backend is selected, but the native backend application object is only created when create() is called or native is used. The Canvas and Timer do this automatically.
backend_module
¶The module object that defines the backend.
backend_name
¶The name of the GUI backend that this app wraps.
native
¶The native GUI application instance.
process_events
()[source]¶Process all pending GUI events. If the mainloop is not running, this should be done regularly to keep the visualization interactive and to keep the event system going.
reuse
()[source]¶Called when the application is reused in an interactive session. This allow the backend to do stuff in the client when use_app() is called multiple times by the user. For example, the notebook backends need to inject JavaScript code as soon as use_app() is called.
run
(allow_interactive=True)[source]¶Enter the native GUI event loop.
Parameters: | allow_interactive : bool
|
---|
vispy.app.
Canvas
(title='VisPy canvas', size=(800, 600), position=None, show=False, autoswap=True, app=None, create_native=True, vsync=False, resizable=True, decorate=True, fullscreen=False, config=None, shared=None, keys=None, parent=None, dpi=None, always_on_top=False, px_scale=1)[source]¶Representation of a GUI element with an OpenGL context
Parameters: | title : str
size : (width, height)
position : (x, y)
show : bool
autoswap : bool
app : Application | str
create_native : bool
vsync : bool
resizable : bool
decorate : bool
fullscreen : bool | int
config : dict
shared : Canvas | GLContext | None
keys : str | dict | None
parent : widget-object
dpi : float | None
always_on_top : bool
px_scale : int > 0
|
---|
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
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.
app
¶The vispy Application instance on which this Canvas is based.
close
()[source]¶Close the canvas
Notes
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
(fun)[source]¶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.
Parameters: | fun : callable
|
---|
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
()[source]¶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
measure_fps
(window=1, callback='%1.1f FPS')[source]¶Measure the current FPS
Sets the update window, connects the draw event to update_fps and sets the callback function.
Parameters: | window : float
callback : function | str
|
---|
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
()[source]¶Render the canvas to an offscreen buffer and return the image array.
Returns: | image : array
|
---|
show
(visible=True, run=False)[source]¶Show or hide the canvas
Parameters: | visible : bool
run : bool
|
---|
size
¶The size of canvas/window
swap_buffers
(event=None)[source]¶Swap GL buffers such that the offscreen buffer becomes visible
Parameters: | event : None
|
---|
title
¶The title of canvas/window
vispy.app.
Timer
(interval='auto', connect=None, iterations=-1, start=False, app=None)[source]¶Timer used to schedule events in the future or on a repeating schedule
Parameters: | interval : float | ‘auto’
connect : function | None
iterations : int
start : bool
app : instance of vispy.app.Application
|
---|
app
¶The vispy Application instance on which this Timer is based.
native
¶The native timer on which this Timer is based.
start
(interval=None, iterations=None)[source]¶Start the timer.
A timeout event will be generated every interval seconds. If interval is None, then self.interval will be used.
If iterations is specified, the timer will stop after emitting that number of events. If unspecified, then the previous value of self.iterations will be used. If the value is negative, then the timer will continue running until stop() is called.
If the timer is already running when this function is called, nothing happens (timer continues running as it did previously, without changing the interval, number of iterations, or emitting a timer start event).