~vcs-imports/pygoocanvas/trunk

« back to all changes in this revision

Viewing changes to demo/misc/gradient-demo.py

  • Committer: gmtagliaretti
  • Date: 2008-05-18 17:12:38 UTC
  • Revision ID: svn-v4:aa6569b5-ad15-0410-a989-d4888eb19b46:trunk:211
Add a gradient example

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
import gobject
 
3
import gtk
 
4
import goocanvas
 
5
import cairo
 
6
 
 
7
def main(argv):
 
8
    window = gtk.Window()
 
9
    window.set_default_size(700, 350)
 
10
    window.show()
 
11
    window.connect("delete_event", on_delete_event)
 
12
    
 
13
    scrolled_win = gtk.ScrolledWindow()
 
14
    scrolled_win.set_shadow_type(gtk.SHADOW_IN)
 
15
    scrolled_win.show()
 
16
    window.add(scrolled_win)
 
17
    
 
18
    canvas = goocanvas.Canvas()
 
19
    canvas.set_size_request(700, 350)
 
20
    canvas.set_bounds(0, 0, 1000, 1000)
 
21
    canvas.show()
 
22
    scrolled_win.add(canvas)
 
23
 
 
24
    root = canvas.get_root_item()
 
25
 
 
26
    # Create a Linear Patter with cairo 
 
27
    linear = cairo.LinearGradient(50, 50, 300, 300)
 
28
    linear.add_color_stop_rgba(0.0,  1, 1, 1, 0)
 
29
    linear.add_color_stop_rgba(0.25,  0, 1, 0, 0.5)
 
30
    linear.add_color_stop_rgba(0.50,  1, 1, 1, 0)
 
31
    linear.add_color_stop_rgba(0.75,  0, 0, 1, 0.5)
 
32
    linear.add_color_stop_rgba(1.0,  1, 1, 1, 0)
 
33
 
 
34
   # Create a rect to be filled with the linear gradient
 
35
    item = goocanvas.Rect(x=50, y=50, width=250, height=250,
 
36
                          line_width=10.0,
 
37
                          radius_x=20.0,
 
38
                          radius_y=10.0,
 
39
                          fill_pattern=linear)
 
40
    root.add_child(item, 0)
 
41
 
 
42
    item.connect("button-press-event", on_rect_button_press)
 
43
 
 
44
    item = goocanvas.Text(parent=root,
 
45
                          text="Linear Gradient",
 
46
                          x=175, y=175,
 
47
                          anchor=gtk.ANCHOR_CENTER,
 
48
                          font="Sans 24")
 
49
    item.rotate(315, 175, 175)
 
50
    
 
51
    # Create a Radial Patter with cairo 
 
52
    radial = cairo.RadialGradient(450, 150, 15, 600, 250, 55)
 
53
    radial.add_color_stop_rgb(0,  1.0, 0.8, 0.8)
 
54
    radial.add_color_stop_rgb(0.50,  0.9, 0.5, 0.0)
 
55
    radial.add_color_stop_rgb(1,  0.9, 0.0, 0.0)
 
56
 
 
57
 
 
58
   # Create a rect to be filled with the radial gradient
 
59
    item = goocanvas.Rect(parent=root,
 
60
                          x=400, y=50, width=250, height=250,
 
61
                          line_width=10.0,
 
62
                          radius_x=20.0,
 
63
                          radius_y=10.0,
 
64
                          fill_pattern=radial)
 
65
 
 
66
    item.connect("button-press-event", on_rect_button_press)
 
67
 
 
68
    item = goocanvas.Text(parent=root,
 
69
                          text="Radial Gradient",
 
70
                          x=525, y=175,
 
71
                          anchor=gtk.ANCHOR_CENTER,
 
72
                          font="Sans 24")
 
73
    item.rotate(315, 525, 175)
 
74
 
 
75
    gtk.main()
 
76
 
 
77
## This handles button presses in item views. We simply output a message to
 
78
##   the console.
 
79
def on_rect_button_press (view, target, event):
 
80
    target.set_simple_transform(50, 50 , 1, 0)
 
81
    print "rect item received button press event"
 
82
    return True
 
83
 
 
84
 
 
85
## This is our handler for the "delete-event" signal of the window, which
 
86
##   is emitted when the 'x' close button is clicked. We just exit here. */
 
87
def on_delete_event(window, event):
 
88
    raise SystemExit
 
89
 
 
90
if __name__ == "__main__":
 
91
    main(sys.argv)
 
92