Goo::Canvas, how to delete an item
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: Goo::Canvas, how to delete an item
- Date: Sun, 3 Aug 2008 11:48:22 -0400
Hi,
I can't figure out how to delete an item from a Goo::Canvas.
In the Gnome2::Canvas and the Goo::Canvas, items are
based on Glib::Object.
In Gnome2::Canvas, you can say $item->destroy, and it works.
In Goo::Canvas, an error is generated:
"Can't locate object method "destroy" via package "Goo::Canvas::Ellipse"
even though it is based on a Glib::Object.
I admit, that a Gnome2::Canvas::Item inherits from Gtk2::Object, which
also contains a destroy method, but shouldn't the Glib::Object destroy
be found?
I realize that the Goo::Canvas is in beta, but is there a trick I must use
to get destroy to work?
Thanks,
zentara
#!/usr/bin/perl -w
use strict;
use warnings;
use Goo::Canvas;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
my $e1;
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(680, 600);
my $vbox = Gtk2::VBox->new;
$vbox->set_border_width(4);
$vbox->show;
my $hbox = Gtk2::HBox->new(FALSE, 4);
$vbox->pack_start($hbox, FALSE, FALSE, 0);
$hbox->show;
$window->add($vbox);
my $swin = Gtk2::ScrolledWindow->new;
$swin->set_shadow_type('in');
$vbox->pack_start($swin, 1, 1, 0);
my $cwidth = 1000;
my $cheight = 1000;
my $canvas = Goo::Canvas->new();
$canvas->set_size_request(600, 450); # minimum size on screen
$canvas->set_bounds(0, 0, $cwidth, $cheight); # scrollregion
$swin->add($canvas);
my $root = $canvas->get_root_item();
$canvas->signal_connect('button-press-event',
\&on_can_button_press);
my $button = Gtk2::Button->new ('Draw');
$button->signal_connect (clicked => \&clicked );
$hbox->pack_start($button, FALSE, FALSE, 10);
$button->show();
$window->show_all();
Gtk2->main;
sub clicked {
my $cur_lab = $button->get_label();
#print "$cur_lab\n";
if($cur_lab eq 'Draw'){
$button->set_label('Clear');
print "Starting action\n";
&draw();
}elsif($cur_lab eq 'Clear'){
$button->set_label('Draw');
print "Stopping action\n";
&clear;
}
}
sub draw{
# item = Goo::Canvas::Ellipse->new ($parent, $center_x, $center_y,
# $radius_x, $radius_y, ...)
$e1 = Goo::Canvas::Ellipse->new(
$root, 310, 300,300, 225,
'stroke-color' => 'black',
'line-width' => 2,
'fill-color-rgba' => 0x3cb3f111,
);
return 0;
}
sub clear{
$e1->destroy;
undef $e1;
return 0;
}
sub on_can_button_press {
my ( $widget, $event ) = @_;
# print $widget ,' ',$event->type,"\n";
my ($x,$y) = ($event->x,$event->y);
print "$x $y\n";
return TRUE;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]