Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / pudding-console-1.pyOpen in CoCalc
Author: William A. Stein
1
#!/usr/bin/env python
2
3
import sys, os
4
5
import soya
6
import soya.pudding as pudding
7
import soya.pudding.sysfont
8
9
soya.init()
10
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
11
12
# initialise pudding
13
pudding.init()
14
15
# with a little code borred from pygame we can get a decent list of the system fonts
16
print "Available fonts are :", pudding.sysfont.get_fonts()
17
18
myfont = soya.Font(pudding.sysfont.SysFont('serif, freeserif'), 15, 15 )
19
print "Choosen font :", myfont
20
21
scene = soya.World()
22
23
sword_model = soya.Shape.get("sword")
24
sword = soya.Volume(scene, sword_model)
25
sword.x = 1
26
sword.rotate_lateral(90.)
27
28
# one line rotation :)
29
sword.advance_time = lambda p: sword.rotate_lateral(5.*p)
30
31
camera = soya.Camera(scene)
32
camera.z = 2
33
34
# we use a special root widget as a small compatability layer
35
root = pudding.core.RootWidget(width = 640, height = 480)
36
soya.set_root_widget(root)
37
38
panel = pudding.control.Panel(root, left = 10, top = 10, label = "console")
39
panel.right = 10
40
panel.bottom = 100
41
panel.anchors = pudding.ANCHOR_ALL
42
43
msg = """pudding version : %s
44
---------------------------------
45
most of layout of this page is done using anchors.
46
type text and press enter to "send"
47
see how you can only type when the mouse is over the console window?
48
49
we also use the wrap flag to wrap really long lines.. you know that reminds me of a time when my great great grandmother was showing my uncle how to suck eggs...
50
51
also checkout pudding.sysfont as it can query available system fonts.
52
53
now go make a soya pudding :)
54
55
""" % pudding.__revision__
56
57
console = pudding.control.Console(panel, left=10, top=30, initial = msg)
58
console.right=10
59
console.bottom=10
60
console.anchors = pudding.ANCHOR_ALL
61
console.output.font = myfont
62
63
root.add_child(camera)
64
65
# we need to do this to force the layout to refresh
66
root.on_resize()
67
68
pudding.idler.Idler(scene).idle()
69
70