HelloWorld

Version 2 (coder, 27/03/2012 16:02)

1 1 admin
h1. Hello World
2 1 admin
3 1 admin
{{>toc}}
4 1 admin
5 1 admin
To continue long-standing programming traditions, we'll start with a simple program that outputs 'Hello World' on the screen:
6 1 admin
7 1 admin
_minimal.py_:
8 1 admin
9 1 admin
<pre><code class="python">
10 1 admin
#!/usr/bin/env python
11 1 admin
# -*- coding: utf-8 -*-
12 1 admin
13 1 admin
from libavg import avg
14 1 admin
15 1 admin
player = avg.Player.get()
16 1 admin
canvas = player.createMainCanvas(size=(640,480))
17 1 admin
rootNode = canvas.getRootNode()
18 1 admin
avg.WordsNode(pos=(10,10), font="arial", 
19 1 admin
        text="Hello World", parent=rootNode)
20 1 admin
player.play()
21 1 admin
</code></pre>
22 1 admin
23 1 admin
You can start the program by opening a console, changing into the sample directory and typing
24 1 admin
25 1 admin
<pre><code class="shell">
26 1 admin
./minimal.py
27 1 admin
</code></pre>
28 1 admin
29 1 admin
You can stop the program by pressing the Esc key.
30 1 admin
31 1 admin
The first two lines of code tell the system that this is a python file and that it's encoded in utf-8. This encoding is standard for all libavg programs. The following lines create a window to draw in (@createMainCanvas()@) and put some text in that window (the WordsNode line). After this scene is initialized, it is shown (@player.play()@).
32 1 admin
33 1 admin
h1. Development Environment
34 1 admin
35 1 admin
This tutorial assumes you'll be working with a text editor and the command line. That doesn't mean that's the only way to work with libavg. For instance, "Eclipse":http://www.eclipse.org/ together with the "PyDev Plugin":http://pydev.org/ works very well as an IDE for libavg.
36 1 admin
37 1 admin
h1. 'No module named avg' error
38 1 admin
39 2 coder
If you get an '@ImportError: No module named avg@', Make sure Python can find libavg. You can change the environment variable PYTHONPATH to point to the directory the library is in. On Mac and Windows, the standard installer should have taken care of setting this up correctly. Under Linux, the place where libavg was installed isn't completely standardized. Possible places are:
40 1 admin
41 1 admin
_libavg install paths_
42 1 admin
43 1 admin
<pre>
44 1 admin
/usr/local/lib/pythonX.Y/site-packages/libavg
45 1 admin
/usr/lib/pythonX.Y/site-packages/libavg
46 1 admin
/usr/local/lib/pythonX.Y/dist-packages/libavg
47 1 admin
/usr/lib/pythonX.Y/dist-packages/libavg
48 1 admin
</pre>
49 1 admin
50 1 admin
If some other error appears, feel free to ask on the libavg-user [[MailingLists|mailing list]], preferrably with a concise description of what went wrong.