The AVGApp Class¶
Note:
AVGApp is deprecated. We recommend using the new app module.
AVGApp is a class that makes application setup easier. It initializes a node tree at a resolution specified, makes keyboard handling easier and adds several debugging aids. It also allows multi-application setups where users can switch between applications without leaving libavg.
Example¶
In the easiest case, an AVGApp looks like this:
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from libavg import AVGApp
5
6class SimpleApp(AVGApp):
7 pass
8
9SimpleApp.start(resolution=(1280,720))
The above application displays an empty window. Since that is pretty useless, here is an example of an App showing a rotating image.
sampleapp.py
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from libavg import avg, AVGApp, AVGAppUtil, anim
5
6# Usually you need the Player in many places, so it's useful
7# to keep it in a global variable (it's a singleton anyway).
8g_player = avg.Player.get()
9
10class HelloWorld(AVGApp):
11 def init(self):
12 # Put all your nodes in the hierarchy below self._parentNode
13 self.node = avg.WordsNode(pos=(50,50), text="Hello World",
14 parent=self._parentNode)
15
16 def _enter(self):
17 # You should start and stop all animations, intervals etc.
18 # in _enter and _leave, so your application uses only
19 # minimal resources while it is not running.
20 self.anim = anim.ContinuousAnim(self.node, 'angle', 0, 3.14)
21 self.anim.start()
22
23 def _leave(self):
24 self.anim.abort()
25 self.anim = None
26
27HelloWorld.start(resolution=(640, 480))
Debugging Aids¶
AVGApp defines several keys that can be used for debugging.
? | Display the debugging keys as an overlay on the screen. |
e | Display the positions of multitouch events on an overlay. |
f | Display a graph that shows time spent per frame. |
m | Display a memory usage graph. |
o | Dump a list of allocated object counts to the console. Useful for finding memory leaks. |
s | Take screenshot. |
t | Activate multitouch emulation. |