Previous topic

Effect Nodes

Next topic

Misc. Classes

This Page

User Interface Classes

The namespace libavg.ui contains python modules that expose higher-level user interface functionality

class libavg.ui.Keyboard(bgHref, ovlHref, keyDefs, shiftKeyCode[, altGrKeyCode, stickyShift])

Bases: libavg.avg.DivNode

Implements an onscreen keyboard that turns mouse clicks or touches into key presses. The keyboard is completely configurable. Keyboard graphics are determined by the two image files in bgHref and ovlHref. Keys can be defined as rectangles anywhere on these images. Works for both single-touch and multitouch devices. When a key is pressed, a callback function is invoked.

Needs offscreen rendering support on the machine.

param string bgHref:
 

Filename of an image that contains the keyboard with unpressed keys.

param string ovlHref:
 

Filename of an image that contains the keyboard with pressed keys.

param list keyDefs:
 

List of key definitions. Keys can be either character keys:

[(<keycode>, <shift keycode>, <altgr keycode>), <pos>, <size>]

or command keys:

[<keycode>, <pos>, <size>]

For character keys, the shift and altgr keycodes are optional. To define entire rows of evenly-spaced keys, use makeRowKeyDefs().

param shiftKeyCode:
 

One of the command keycodes. When the key with this code is pressed, pressing other keys causes them to return the shifted keycode.

param altGrKeyCode:
 

One of the command keycodes. When the key with this code is pressed, pressing other keys causes them to return the altgr keycode.

param bool stickyShift:
 

For single-touch devices, the shift key must stay in the pressed state until the next normal key is pressed to have any effect. This is the behaviour if stickyShift is True. If it is False (the default), a multitouch device is assumed and shift works like on a physical keyboard.

reset():

Resets any sticky keys (shift, altgr) to their default state.

setKeyHandler(self, downHandler, [upHandler]):

Set callbacks to invoke on key press and -release. Handlers take three paramters: (event, char, cmd)

Parameters:
  • downHandler – Callable to invoke on key down event or None.
  • upHandler – Callable to invoke on key up event or None.
classmethod makeRowKeyDefs(startPos, keySize, spacing, keyStr, shiftKeyStr[, altGrKeyStr])

Creates key definitions for a row of uniform keys. Useful for creating the keyDefs parameter of the Keyboard constructor.

Parameters:
  • startPos (avg.Point2D) – Top left position of the row.
  • keySize (avg.Point2D) – Size of each key.
  • spacing (int) – Number of empty pixels between two keys.
  • keyStr (string) – Unicode string containing the unshifted keycodes (i.e. u"qwertzuiopżś")
  • shiftKeyStr (string) – Unicode string containing the shifted keycodes (i.e. u"QWERTZUIOPńć")
  • altGrKeyStr (string) – Unicode string containing the keycodes when altgr is pressed.
class libavg.ui.DragProcessor(node[, eventSource=avg.TOUCH | avg.MOUSE, startHandler=None, moveHandler=None, upHandler=None, stopHandler=None, friction=-1])

Bases: libavg.ui.manipulation.ManipulationProcessor

A DragProcessor attaches itself to a node’s cursor events and delivers higher-level callbacks that can be used to implement dragging or drag-like functionality. For multitouch devices, only one drag can happen at a time; subsequent drags are ignored until the first one is released. The dragging cursor is captured during the drag.

DragProcessor supports inertia after the node is released.

param avg.Node node:
 The node to attach to.
param eventSource:
 One of the standard event sources (TRACK, TOUCH etc.).
param float friction:
 If set, this parameter enables inertia processing. It describes how quickly the drag comes to a stop after the cursor is released.

The callbacks are:

startHandler(event):

Called when a drag begins.

Parameters:event – The corresponding cursor down event.
moveHandler(event, offset):

Called when the drag should cause a position change. This usually happens in response to a CURSORMOTION event, but may also happen because of inertia.

Parameters:
  • event – The corresponding cursor motion event. If there was no event, this parameter is None.
  • offset (avg.Point2D) – The current offset from the start of the drag in global coordinates.
upHandler(event, offset):

Called when the cursor is released. If inertia is enabled, there may be move events after the up event.

Parameters:
  • event – The corresponding CURSORUP event.
  • offset (avg.Point2D) – The current offset from the start of the drag in global coordinates.
stopHandler():

Called when movement stops. This is either directly after the up event or when inertia has run its course.

abortInertia():

Causes inertia processing to end immediately.

class libavg.ui.ManipulationProcessor(node, eventSource)

Bases: object

Base class for event processors that attach to a node’s cursor events and emit higher-level events.

param Node node:
 Node to attach to.
param eventSource:
 One of the standard event sources (TRACK, TOUCH etc.).
enable(isEnabled)

Enables or disables the ManipulationProcessor.