Using the motion-notify-event



Hello,

I'm learning gtk-perl and have a hard time with signals and events.

Last month here was a discussion on using the motion-notify-event in TreeView, in that example the event handling code is executed every time the mouse moves over the widget. I tested it, that is what I want.

I have a window, where I have a ScrolledWindow, where I have an EventBox, where I have an image. I get the motion-notify-event only when I move the mouse with button pressed. How do I get the event without having to press the button?

I need the press-button-move event also for panning the image, but I expected it to be the drag-begin drag-end events, which I did not yet get fired in any case.

Ari

--
Prof. Ari Jolma
Kartografia ja Geoinformatiikka / Cartography and Geoinformatics
Teknillinen Korkeakoulu / Helsinki University of Technology
POBox 1200, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://www.tkk.fi/~jolma

use strict;
use POSIX;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

my $window = Gtk2::Window->new;

my @window_size = (0,0);

$window->set_position('center');

my $image = Gtk2::Image->new_from_file("../ari.jpg");

$image->set_size_request(0,0);

$window->signal_connect ("destroy", sub { exit(0); });
$window->signal_connect(key_press_event => \&key_press_event);

my $event_box = Gtk2::EventBox->new;

$event_box->add($image);

$event_box->signal_connect(motion_notify_event => \&motion_notify);

my $scrolled = Gtk2::ScrolledWindow->new;

$scrolled->add_with_viewport($event_box);

$window->add($scrolled);

$window->set_default_size(200,200);

$window->show_all;

Gtk2->main;

sub motion_notify {
    my $widget = shift; # GtkWidget         *widget
    my $event = shift;  # GdkEventButton    *event

    my $x = $event->x;
    my $y = $event->y;

    print "motion_notify $x,$y\n";

}



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