Re: signals for canvas items



Hi Daniel,

It should work. You can also do something like:

    my $card_group = 
        Gnome::CanvasItem->new($W{root},
                               "Gnome::CanvasGroup",
                               "x", $cx-50,
                               "y", $cy-50,
                               "signal::event" => [\&move_card_cb]
                              );

(Taken from my abc-blocks program. See:

    http://imagic.weizmann.ac.il/~dov/freesw/gtk/abc-blocks/abc-blocks.html
). 

In the callback you then have to test the type of the event and act 
according to it. The following is also from abc-blocks:

    sub move_card_cb {
        my($item, $event) = @_;

        if ($event->{type} eq "button_press") {
            if ($event->{button} eq '1') {
                $item->raise_to_top();
                $last_cx = $event->{x};
                $last_cy = $event->{y};

                $dragging++;
            } elsif ($event->{button} eq '3') {
                $item->destroy();
            }
        }
        elsif ($event->{type} eq "motion_notify") {
            if ($dragging) {
                my $new_x = $event->{x};
                my $new_y = $event->{y};

                $item->move($new_x-$last_cx,$new_y-$last_cy);

                $last_cx = $new_x;
                $last_cy = $new_y;
            }
        }
        elsif ($event->{type} eq "button_release") {
            if ($event->{button} eq '1') {
                $dragging=0;
            }
        }
    }

I hope this helps.

Regards,
Dov


On Sat, Apr 27, 2002 at 11:11:31PM -0400, Daniel Carrera wrote:
Hello,

I wish to signal_connect() events for canvas items.  However that doesn't
work.  I have looked all over the documentation for something like this
but without success.

What I would like to do is essentially:

$rectangle = $group->new($Group,"Gnome::CanvasRect",...);

$rectangle->signal_connect(...);


But this doesn't work.


Does anyone know how you would achieve this effect?

Thanks a lot,
Daniel.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list




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