I've never used gtk2 or anything like that, but this is just screaming out for closures. :-) It'd help people like me help you if you showed the code you had, though. I'm stealing code from Gnome2::Canvas's docs.
my $box = Gnome2::Canvas::Item->new ($root, 'Gnome2::Canvas::Rect', x1 => 10, y1 => 5, x2 => 150, y2 => 135, fill_color => 'red', outline_color => 'black'); $box->lower_to_bottom; $box->signal_connect (event => sub { my ($item, $event) = @_; warn "event ".$event->type." on $box\n"; });
The key is to simply use $box, or whatever, in the anonymous subroutine, and it will be forever linked to that instantiation. Even if you create a bunch of different $box's in a loop or in another subroutine, the $box it refers to will always be the correct one.
In reply to Re: unique identifiers for gtk2 canvas objects?
by Tanktalus
in thread unique identifiers for gtk2 canvas objects?
by marksz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |