Node Attributes

libavg gives you full access to all nodes you defined using attributes. The syntax will appear very familiar to people who have done some html/javascript scripting.

Attribute Example

If you modify minimal.py from the Hello World page to change the attribute of a node, the display will change as well:

attributes.py:

 1#!/usr/bin/env python
 2# -*- coding: utf-8 -*-
 3
 4from libavg import avg
 5
 6player = avg.Player.get()
 7
 8canvas = player.createMainCanvas(size=(640,480))
 9rootNode = canvas.getRootNode()
10node = avg.WordsNode(pos=(10,10), font="arial", 
11        text="Hello World", parent=rootNode)
12print node.x
13node.x = 200
14player.play()

If you run this script, the x position of the node will be output on the console and the text will be moved 190 pixels to the right. You can change almost all attributes of all node types in this way. We're moving the text before starting playback, so there is no movement visible on the display. To make things happen during playback, you need to react to events as described under Events.

Common Attributes

There are several attribute types which are common to all or almost all nodes. For instance, the x and y attributes determine the position of a node. Width and height attributes can be used to specify a size (if none are given, the native size of the medium is used instead). Alternatively, the pos and size attributes can be used. opacity is a number between 0 and 1 that determines how transparently the node is rendered: 0 is completely transparent, 1 completely opaque. Nodes can also have a rotation attribute that rotates the medium. The id attribute of a node can be used to access it from python by using the Player.getElementByID() function.

One warning: python allows you to add any attributes you want to objects. This includes libavg nodes. That means that if you misspell a name when setting an attribute, you will not get an error. Instead, there will be a new attribute with a strange name - in effect, your code will be silently ignored.

The properties defined for the various node types are descibed in the libavg reference.

Image Nodes

Image nodes are used to put a bitmap on the screen. The href attribute of an image node contains the filename of a bitmap to load on start. This file can be in a variety of formats, including png, tiff, bmp and jpeg. Alpha channels are fully supported, so images with transparency are displayed with elements below them visible according to the transparency information in the image.

Words Nodes

Words nodes support simple text as well as formatted text. UTF-8 and right-to-left languages are fully supported, so text in Japanese, Russian and Arabic should pose no problems. Formatted text supports full paragraph layout and is authored like this:

Words Formatting

1avg.WordsNode(pos=(10,10), width=70, text="Text in <i>italics</i>",
2        parent=rootNode)

All text attributes - font, size, bold, italic, super- and subscripting, as well as some others - can be changed in mid-paragraph. A full description of the formatting language is at http://developer.gnome.org/pango/stable/PangoMarkupFormat.html.