Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / pudding-buttonbar-2.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
8
soya.init(width = 1024, height = 768)
9
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
10
11
# initialise pudding
12
pudding.init()
13
14
scene = soya.World()
15
16
sword_model = soya.Shape.get("sword")
17
sword = soya.Volume(scene, sword_model)
18
sword.x = 1
19
sword.rotate_lateral(90.)
20
21
# one line rotation :)
22
sword.advance_time = lambda p: sword.rotate_lateral(5.*p)
23
24
light = soya.Light(scene)
25
light.set_xyz( .5, 0., 2.)
26
27
camera = soya.Camera(scene)
28
camera.z = 3.
29
30
class PuddingVolume(pudding.core.Control):
31
def __set_left__(self, left):
32
pudding.core.Control.__set_left__(self, left)
33
self.move_shape()
34
35
def __set_top__(self, top):
36
pudding.core.Control.__set_top(self, top)
37
self.move_shape()
38
39
def __init__(self, *args, **kwargs):
40
pudding.core.Control.__init__(self, *args, **kwargs)
41
self.shape = soya.Volume(scene, sword_model)
42
self.shape.rotate_lateral(90)
43
self.shape.scale(.5, .5, .5)
44
self.move_shape()
45
46
def on_resize(self):
47
self.move_shape()
48
49
def move_shape(self):
50
self.shape.move(camera.coord2d_to_3d(self.left, self.top))
51
52
w = pudding.core.RootWidget(width = 1024,height = 768)
53
54
d = PuddingVolume(w, 200, 100, 100, 100)
55
56
button_bar = pudding.container.HorizontalContainer( w, left = 10, width= 164, height=64)
57
button_bar.set_pos_bottom_right(bottom = 10)
58
button_bar.anchors = pudding.ANCHOR_BOTTOM
59
60
d = button_bar.add_child(pudding.control.Button(label = 'Button1'), pudding.EXPAND_BOTH)
61
f = button_bar.add_child(pudding.control.Button(label = 'Button2'), pudding.EXPAND_BOTH)
62
f.right = 130
63
64
#logo = pudding.control.Logo(w, 'little-dunk.png')
65
66
w.add_child(camera)
67
68
soya.set_root_widget(w)
69
70
pudding.idler.Idler(scene).idle()
71
72