Am 27.04.2009, 01:12 Uhr, schrieb Marcos Duarte <[email protected]>:

The children are not part of the canvas node, they are part of the group
node. Simple solution for your problem:

group.removeAllChildren()

or with the code you gave above

for child in group.children:
    group.removeChild(child)

-Matthias

P.S.: Note that groups without (renderable) children are not allowed right
now.

Thanks Mathias but I must be doing something wrong.

I created my group with ( after frame =  wx.Frame(...); canvas =
floatcanvas.NavCanvas(frame,...) ):
group = canvas.create( 'Group', name = 'test' )
And I add objects like that:
line = canvas.create('Line', (0,0), (200,200), name='Line1',
look=('blue', ''), parent = group)
arc = canvas.create('Arc', 100, 0, 45*3.14/180, False,(0,0),
name='Arc1', look=('red', ''), parent = group)
Then, I use the mouse to select a group and delete it.
The event.node seems to return the group node, but I am only able to
delete the children of the group if I do the following:
for child in event.node.children:
    canvas.removeChild(child)
The command event.node.removeAllChildren() does not work

In fact, I am ok with that, but the only problem is that although I
removed all children from the canvas, the group itself seems to be
still there (when I pass the mouse over the former area of the group,
my function still shows the object with the name of the group even if
there is nothing there).
I think I probably would like to delete any remains of the group in my canvas.

Is there a way of doing that with the event.node object?

Hello Marcos,

I found a bug in the bounded node unregistering code. Attached is a modified version of the "Groups" demo tutorial which seems to work here. Click the group to delete it. First update SVN though.
I also added a convenience function to the node class. You can now call

node.remove()

to remove a node from its parent. It's the same as doing node.parent = None.

So your event handler will now look like

    def on_left_down(evt):
        evt.node.remove()
    group.subscribe( on_left_down, 'left_down' )

which should suffice to remove the group and its children from the canvas.

-Matthias

P.S.: A thing which might be useful if you need to deal with groups and their children differently.

- evt.node is only the top-most node under the cursor. You can use evt.nodes to get all nodes under the cursor.
   This code here prints all affected nodes for example:

    def on_left_down(evt):
        print 'Topmost node  : ', evt.node.name
        print 'All hit nodes : ', [node.name for node in evt.nodes]

The current bounding box calculation/bounded node (un)registration code is a bit wonky. If you encounter any problems, let me know.

Attachment: Groups.py
Description: Binary data

_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to