7 class Canvas(GtkWindow
):
8 def __init__(self
, view
, node
):
9 from gnome
.ui
import GnomeCanvas
10 GtkWindow
.__init
__(self
)
12 self
.display_root
= node
14 self
.canvas
= GnomeCanvas()
20 s
= self
.canvas
.get_style().copy()
21 s
.bg
[STATE_NORMAL
] = self
.canvas
.get_color('LemonChiffon')
22 self
.canvas
.set_style(s
)
24 self
.set_title(self
.display_root
.nodeName
)
25 self
.view
.add_display(self
)
27 self
.connect('destroy', self
.destroyed
)
29 def destroyed(self
, widget
):
31 self
.view
.remove_display(self
)
33 def update_all(self
, node
= None):
35 if not self
.view
.has_ancestor(self
.display_root
, self
.view
.root
):
36 print "Display node lost - killing canvas!"
41 self
.group
= self
.build(self
.canvas
.root(), self
.display_root
)
47 min_x
, min_y
, max_x
, max_y
= self
.canvas
.root().get_bounds()
52 self
.canvas
.set_scroll_region(min_x
, min_y
, max_x
, max_y
)
53 self
.canvas
.root().move(0, 0) # Magic!
54 self
.canvas
.set_usize(max_x
- min_x
, max_y
- min_y
)
56 def build(self
, group
, node
):
59 for a
in node
.attributes
:
61 attrs
[str(a
.localName
)] = eval(str(a
.value
))
65 type, val
, tb
= sys
.exc_info()
66 list = traceback
.extract_tb(tb
)
67 stack
= traceback
.format_list(list[-2:])
68 ex
= traceback
.format_exception_only(type, val
) + ['\n\n'] + stack
69 traceback
.print_exception(type, val
, tb
)
71 if attrs
.has_key('onClick'):
72 onClick
= attrs
['onClick']
77 name
= str(node
.localName
)
78 if name
not in ('rect', 'line', 'text', 'ellipse'):
81 item
= apply(group
.add
, [name
], attrs
)
83 type, val
, tb
= sys
.exc_info()
84 list = traceback
.extract_tb(tb
)
85 stack
= traceback
.format_list(list[-2:])
86 ex
= traceback
.format_exception_only(type, val
) + ['\n\n'] + stack
87 traceback
.print_exception(type, val
, tb
)
89 item
= group
.add('ellipse',
91 outline_color
= 'black',
97 item
.connect('event', self
.button_event
, node
, onClick
)
99 for k
in node
.childNodes
:
104 def button_event(self
, item
, event
, node
, prog
):
105 if event
.type == BUTTON_PRESS
and event
.button
== 1:
107 self
.view
.move_to(node
)
108 self
.view
.do_action(['play', prog
])
110 def move_from(self
, old_nodes
):