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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
try:
import cccanvas
except:
import sys
sys.path.insert(0,"./../.libs/")
import cccanvas
import page
import gtk
from math import pi
from math import sin
from math import cos
class Crossing(page.Page):
def __init__(self):
self.title = 'Crossing'
self.colors = [ cccanvas.color_new_rgb(0.0,0.0,0.0),
cccanvas.color_new_rgb(1.0,0.0,0.0) ]
self.brushs = []
self.brushs.append(cccanvas.BrushColor(self.colors[0]))
self.brushs.append(cccanvas.BrushColor(self.colors[1]))
#self.brushs = [ cccanvas.BrushColor(self.colors[0]),
# cccanvas.BrushColor(self.colors[1]) ]
# main widget
self.widget = gtk.VBox(False, 6)
self.widget.set_border_width(6)
# Scroll
#swin = gtk.ScrolledWindow()
#self.widget.pack_start(swin)
# Create CCCanvas item and widget with this item as root
self.root = cccanvas.Item()
self.view = cccanvas.view_widget_new_root(self.root)
self.view.show()
self.widget.pack_start(self.view)
# Label
self.label = gtk.Label('Move the mouse over a circle')
self.label.show()
self.widget.pack_start(self.label)
n_circles = 12
center = 130.0
radius = 125.0
r = [ 25.5,
15.0,
9.0,
5.4,
3.24 ]
r.append( r[4]*0.6 )
r.append( r[5]*0.6 )
r.append( r[6]*0.6 )
for i in range(n_circles):
out = 0
for r_el in r:
circle = cccanvas.Circle()
out += r_el
circle.set_anchor( center + (radius - out) * sin(2.0*pi*i/n_circles),
center - (radius - out) * cos(2.0*pi*i/n_circles))
circle.set_radius( r_el );
circle.set_brush_border (self.brushs[0])
circle.connect("enter-notify-event", self.enter_callback)
circle.connect("leave-notify-event", self.leave_callback)
self.root.append(circle)
self.widget.show()
def enter_callback(self, shape, view, event):
shape.set_brush_border (self.brushs[1])
return False
def leave_callback(self, shape, view, event):
shape.set_brush_border (self.brushs[0])
return False
|