ToggleButton seems to suppress pointer-motion-mask events
- From: Mitchell Laks <mlaks post harvard edu>
- To: gtk-perl-list gnome org
- Subject: ToggleButton seems to suppress pointer-motion-mask events
- Date: Sun, 3 Feb 2008 15:26:43 -0500
Hi,
I was trying to capture events such as button1-motion-mask or
button2-motion-mask or pointer-motion-mask with pointer-motion-hint-mask
on an OpenGL widget. This is to be able to use window and level and pan and
zoom for display of medical CT and MRI images
I noticed that initially I could not seem to capture the events.
I am a beginner so I was modifying the examples I found in the
distribution files; Thus I
was using a widget that a modification of the default
example in the Gtk2-GLext package which is composed of a
OpenGL endowed DrawingArea that was placed into vbox, (together with a
label) and then placed into a ToggleButton.
When I tried to add motion-mask or motion-hint-masks
via set_events or add_events to the DrawingArea, it never reported the
events.
I could only get the events when I thought to get rid of the ToggleButton.
Now it naively 'makes sense' to me that the togglebutton would not report
pointer-motion stuff, but I would have thought that the inheritance
goes in teh other direction;
ie that the propogation of events is from the child to the parent
and since the DrawingArea is in the vbox in the ToggleButton in the Window
how is the ToggleButton preventing the pointer-motion-event from
manifesting itself?
Here are two examples I concocted. One with a togglebox and one with a vbox.
toggle.pl
#!/usr/bin/perl -w
use strict;
use Gtk2 '-init';
my $window = Gtk2::Window->new ('toplevel');
my $button= Gtk2::ToggleButton->new;
my $draw = Gtk2::DrawingArea->new;
$draw->add_events ([qw/exposure-mask
leave-notify-mask
button-press-mask
pointer-motion-mask
pointer-motion-hint-mask
/]);
$draw->signal_connect (motion_notify_event => \&motion_notify_event);
sub motion_notify_event {
my $widget=shift;
my $event=shift;
my ($x, $y, $state);
if ($event->is_hint) {
(undef, $x, $y, $state) = $event->window->get_pointer;
} else {
$x = $event->x;
$y = $event->y;
$state = $event->state;
}
if ($state >= "button1-mask" ) {
print "value of x and y and button1 are $x and $y \n" ;
}
if ($state >= "button2-mask" ) {
print "value of x and y and button2 are $x and $y \n" ;
}
return 1; #was TRUE in source (was scribble.pl)
}
$button->add($draw);
$window->add($button);
$window->signal_connect (delete_event => sub {Gtk2->main_quit; 1});
$window->show_all;
Gtk2->main;
and here is
nontoggle.pl
#!/usr/bin/perl -w
use strict;
use Gtk2 '-init';
my $window = Gtk2::Window->new ('toplevel');
my $button= Gtk2::VBox->new;
my $draw = Gtk2::DrawingArea->new;
$draw->add_events ([qw/exposure-mask
leave-notify-mask
button-press-mask
pointer-motion-mask
pointer-motion-hint-mask
/]);
$draw->signal_connect (motion_notify_event => \&motion_notify_event);
sub motion_notify_event {
my $widget=shift;
my $event=shift;
my ($x, $y, $state);
if ($event->is_hint) {
(undef, $x, $y, $state) = $event->window->get_pointer;
} else {
$x = $event->x;
$y = $event->y;
$state = $event->state;
}
if ($state >= "button1-mask" ) {
print "value of x and y and button1 are $x and $y \n" ;
}
if ($state >= "button2-mask" ) {
print "value of x and y and button2 are $x and $y \n" ;
}
return 1; #was TRUE in source (was scribble.pl)
}
$button->add($draw);
$window->add($button);
$window->signal_connect (delete_event => sub {Gtk2->main_quit; 1});
$window->show_all;
Gtk2->main;
**************
So that is how it works. The second works and I get the output.
What is the mechanism behind it?
Thanks,
Mitchell
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]