forked from tstriker/hamster-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
executable file
·41 lines (30 loc) · 1.29 KB
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# - coding: utf-8 -
# Copyright (C) 2010 Toms Bauģis <toms.baugis at gmail.com>
# Last example from the turorial
# http://wiki.github.com/tbaugis/hamster_experiments/tutorial
import gtk
from lib import graphics
from lib.pytweener import Easing
class Scene(graphics.Scene):
def __init__(self):
graphics.Scene.__init__(self)
for i in range(14):
self.add_child(graphics.Rectangle(40, 40, 3,
y = 420, x = i * 45 + 6,
fill = "#999", stroke="#444", interactive = True))
self.connect("on-mouse-over", self.on_mouse_over)
def on_mouse_over(self, scene, sprite):
if not sprite: return #ignore blank clicks
if self.tweener.get_tweens(sprite): #must be busy
return
def bring_back(sprite):
self.animate(sprite, y = 420, scale_x = 1, scale_y = 1, x = sprite.original_x, easing = Easing.Bounce.ease_out)
sprite.original_x = sprite.x
self.animate(sprite, y = 150, scale_x = 2, x = sprite.x - 20, scale_y = 2, on_complete = bring_back)
window = gtk.Window()
window.set_size_request(640, 480)
window.connect("delete_event", lambda *args: gtk.main_quit())
window.add(Scene())
window.show_all()
gtk.main()