6 class Canvas(g
.Window
):
7 def __init__(self
, view
, node
):
8 from gnome
import canvas
9 g
.Window
.__init
__(self
)
11 self
.display_root
= node
13 self
.canvas
= canvas
.Canvas()
17 self
.pict_group
= None
19 s
= self
.canvas
.get_style().copy()
20 s
.bg
[g
.STATE_NORMAL
] = g
.gdk
.color_parse('LemonChiffon')
21 self
.canvas
.set_style(s
)
23 self
.set_title(self
.display_root
.nodeName
)
24 self
.view
.add_display(self
)
26 self
.connect('destroy', self
.destroyed
)
28 def destroyed(self
, widget
):
30 self
.view
.remove_display(self
)
32 def update_all(self
, node
= None):
34 if not self
.view
.has_ancestor(self
.display_root
, self
.view
.root
):
35 print "Display node lost - killing canvas!"
39 self
.pict_group
.destroy()
40 self
.pict_group
= self
.build(self
.canvas
.root(), self
.display_root
)
46 min_x
, min_y
, max_x
, max_y
= self
.canvas
.root().get_bounds()
51 self
.canvas
.set_scroll_region(min_x
, min_y
, max_x
, max_y
)
52 self
.canvas
.root().move(0, 0) # Magic!
53 self
.canvas
.set_usize(max_x
- min_x
, max_y
- min_y
)
55 def build(self
, group
, node
):
58 for a
in node
.attributes
:
60 attrs
[str(a
.localName
)] = eval(str(a
.value
))
64 type, val
, tb
= sys
.exc_info()
65 list = traceback
.extract_tb(tb
)
66 stack
= traceback
.format_list(list[-2:])
67 ex
= traceback
.format_exception_only(type, val
) + ['\n\n'] + stack
68 traceback
.print_exception(type, val
, tb
)
70 if attrs
.has_key('onClick'):
71 onClick
= attrs
['onClick']
76 name
= str(node
.localName
)
77 if name
not in ('rect', 'line', 'text', 'ellipse'):
80 item
= apply(group
.add
, [name
], attrs
)
82 type, val
, tb
= sys
.exc_info()
83 list = traceback
.extract_tb(tb
)
84 stack
= traceback
.format_list(list[-2:])
85 ex
= traceback
.format_exception_only(type, val
) + ['\n\n'] + stack
86 traceback
.print_exception(type, val
, tb
)
88 item
= group
.add('ellipse',
90 outline_color
= 'black',
96 item
.connect('event', self
.button_event
, node
, onClick
)
98 for k
in node
.childNodes
:
103 def button_event(self
, item
, event
, node
, prog
):
104 if event
.type == BUTTON_PRESS
and event
.button
== 1:
106 self
.view
.move_to(node
)
107 self
.view
.do_action(['play', prog
])
109 def move_from(self
, old_nodes
):