app module


Bases: object

This class handles global application affairs. Among these are setting up a root node along with window size (and possibly screen resolution) and screen rotation, and creating an environment for the user’s MainDiv. Global user interface items such as a debug panel and keyboard manager are also set up. Additionally, App handles configuration settings and command line argument support.

App usually does not need to be subclassed. Instead, subclass MainDiv and pass an instance of the derived class to run().


An instance of debugpanel.DebugPanel.


The instance passed as first argument of the run() method.


DivNode that stands always on top of the MainDiv.


An instance of settings.Settings.


Dumps on the console the current number of initialized objects. Normally bound to the keypress CTRL-b.


Called just before starting the main loop ( Useful only for subclassing. The display hasn’t been initialized at this point.

run(mainDiv, **kargs)

Starts the application using the provided mainDiv (an instance of MainDiv).

The optional additional kargs are used to set default settings - see settings.Settings.


Takes a screenshot of what is currently visible on the screen. Normally bound to the keypress CTRL-p. Screenshots are saved to the disk under the name ‘App-nnn.png’, where nnn is a sequence number.


Bases: libavg.avg.DivNode

This abstract class must be subclassed to write a libavg application. It is the main application entry point and should be the parent node for all application-created nodes. All the public methods are empty and don’t do anything if not overridden.


A version string. This is shown using the -v or --version command-line option.

onArgvParsed(options, args, parser)

This method is called after command-line arguments have been parsed and should be used to retrieve any application-specific options. The arguments options and args are the result of calling options, args = parser.parse_args(), where parser is an instance of optparse.OptionParser configured by calling onArgvParserCreated().


Called with an empty optparse.OptionParser instance. Allows the application to add additional command line options. App adds it’s own parameters as well. If this is overridden, onArgvParsed() should probably be overridden as well.


Called after the main loop exits. Release resources and run cleanups here.


onExit() doesn’t get called if an exception is raised on the main thread.


Called every frame.


Called by a libavg timer as soon as the main loop starts. At this point in time, the window has been created and all render functions are available. Build the application node tree here.


Called before libavg has been setup, just after the App().run() call. The window has not been created at this time.


A TouchVisualization gives the user visual feedback whenever a touch event is registered. This call switches the feedback on or off.

keyboardmanager Module

This module makes it possible to attach event handlers to individual keypresses. Keys that are bound through the keyboard manager are also be shown in the debug panel via the keyboard bindings widget along with their help string. defines a range of keyboard bindings by default. The keyboardmanager is usually set up by also reserves all keys modified by CTRL.

The binding methods accept one of scancode, a keyname, or text to match. These are compared to the corresponding fields of libavg.avg.Keyevent when a key is pressed. The modifiers are described under libavg.avg.KeyEvent.modifiers, with the additional modifiers KEYMOD_SHIFT, KEYMOD_CTRL and KEYMOD_ALT available to simplify checking for left and right modifier keys at one time., keyname=None, text=None, handler=None, help=None, modifiers=avg.KEYMOD_NONE)

Sets up a key handler so that handler is called whenever the selected key is pressed., keyname=None, handler=None, help=None, modifiers=avg.KEYMOD_NONE)

Sets up a key handler so that handler is called whenever the selected key is released.

Companion to enable(), disables all handlers.

Companion to disable(), enables all handlers.

Returns the currently assigned bindings as a list of named tuples.

Called by App. Should not be called by user programs.

Companion to push(), restores the non-modified key bindings previously pushed onto the stack via push().

Pushes all the non-modified key bindings onto a stack and clears them all. Useful when the application flow branches to a state where a different key bindings set is needed. The bindings can be then restored with pop().

Removes all the defined key bindings at once., keyname=None, text=None, modifiers=avg.KEYMOD_NONE)

Removes a previously defined key binding for a KEY_DOWN event., keyname=None, modifiers=avg.KEYMOD_NONE)

Removes a previously defined key binding for a KEY_UP event.

flashmessage Module

Simple user notification API to report information to the user

class, timeout=DEFAULT_TIMEOUT, parent=None, isError=False, acknowledge=False)

Bases: object

A FlashMessage is an easy way to show debug notification and similar text in the libavg window. The message can have an optional timeout or stay visible until clicked on by the user. It inserts itself into node tree at the top. Multiple FlashMessage instances are shown in the order they get created.

  • timeout – The time in milliseconds the message should persist on screen before it gets removed. Only valid if acknowledge is False.
  • parent – When specified, the parent node the message should be appending itself to.
  • isError – A boolean flag to mark the message as error. Error-flagged messages are shown in a different color and are routed to the logger as well.
  • acknowledge – A flag to indicate whether the message should remove itself automatically (after timeout has elapsed) or needs to be acknowledged by the user (by clicking / touching on it).