Re: Goo::Canvas, how to delete an item



Hello,
I havent worked on this for a while but I was able to get my program to remove a waypoint by using this scheme, it may help you some:

#remove waypoints
    if ($event->type eq "button-press" && $event->button == 3){
        my ($x,$y) = ($event->x,$event->y);
        print "right click\n";
        my $items = $canvas->get_item_at($x,$y,TRUE);
        my $parent = $items->get_parent;
        print "$parent\n";
        $parent->remove;
    }

Looking at the goocanvas H files I noticed that destroy is not in there. hopefully it will be added :)



On Sun, Aug 3, 2008 at 10:48 AM, zentara <zentara1 sbcglobal net> wrote:
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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list



--
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
402.304.0766
jlahowe2 bigred unl edu


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]