The app module

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(backend_name=None)

Select a backend by name. If the backend name is omitted, will chose a suitable backend automatically. It is an error to try to select a particular backend if one is already selected. Available backends: ‘PySide’, ‘PyQt4’, ‘Glut’, ‘Pyglet’, ‘qt’. The latter will use PySide or PyQt4, whichever works.

If a backend name is provided, and that backend could not be loaded, an error is raised.

If no backend name is provided, this function will first check if the GUI toolkit corresponding to each backend is already imported, and try that backend first. If this is unsuccessful, it will try the ‘default_backend’ provided in the vispy config. If still not succesful, it will try each backend in a predetermined order.

vispy.app.create()

Create the native application.

vispy.app.run()

Enter the native GUI event loop.

vispy.app.quit()

Quit the native GUI event loop.

vispy.app.process_events()

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.


class vispy.app.Application

Representation of the vispy application. This wraps a native GUI application instance. Vispy has a default instance of this class at vispy.app.default_app.

There are multiple stages for an Application object:
  • Backend-less - the state when it is just initialized
  • Backend selected - use() has been successfully called. Note that the Canvas calls use() without arguments reight before creating its backend widget.
  • Native application is created - the Canvas probes the Application,native property to ensure that there is a native application right before a native widget is created.
backend_module

The module object that defines the backend.

backend_name

The name of the GUI backend that this app wraps.

create()

Create the native application.

native

The native GUI application instance.

process_events()

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.

quit()

Quit the native GUI event loop.

run()

Enter the native GUI event loop.

use(backend_name=None)

Select a backend by name. If the backend name is omitted, will chose a suitable backend automatically. It is an error to try to select a particular backend if one is already selected. Available backends: ‘PySide’, ‘PyQt4’, ‘Glut’, ‘Pyglet’, ‘qt’. The latter will use PySide or PyQt4, whichever works.

If a backend name is provided, and that backend could not be loaded, an error is raised.

If no backend name is provided, this function will first check if the GUI toolkit corresponding to each backend is already imported, and try that backend first. If this is unsuccessful, it will try the ‘default_backend’ provided in the vispy config. If still not succesful, it will try each backend in a predetermined order.


class vispy.app.Canvas(*args, **kwargs)

Representation of a GUI element that can be rendered to by an OpenGL context. The args and kwargs are used to instantiate the native widget.

Receives the following events: initialize, resize, paint, mouse_press, mouse_release, mouse_move, mouse_wheel, key_press, key_release, stylus, touch, close

app

The vispy Application instance on which this Canvas is based.

close()

Close the canvas

connect(fun)

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_paint’).

This method is typically used as a decorater on a function definition for an event handler.

create_native()

Create the native widget if not already done so. If the widget is already created, this function does nothing.

move(x, y)

Move the widget or window to the given position

native

The native widget object on which this Canvas is based.

position

The position of canvas/window relative to screen

resize(w, h)

Resize the canvas givan size

show(visible=True)

Show (or hide) the canvas

size

The size of canvas/window

swap_buffers()

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 repainted


class vispy.app.Timer(interval=0.0, connect=None, iterations=-1, start=False, app=None)

Timer used to schedule events in the future or on a repeating schedule.

app

The vispy Application instance on which this Timer is based.

connect(callback)

Alias for self.events.timeout.connect()

disconnect(callback=None)

Alias for self.events.timeout.disconnect()

native

The native timer on which this Timer is based.

start(interval=None, iterations=None)

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.

stop()

Stop the timer.