Re: Gtk2::DrawingArea



On 02:56 Tue 05 Feb     , Mitchell Laks wrote:

Put another way, in terms of my rereading of earlier message from
muppet on ToggleButton.

Why is the Gtk2::Window eating the 
key-press events,
but not eating the 
pointer-motion events or 
button-press events
which seem to propagate nicely to the child Gtk2::DrawingArea.

Thus if I try the following code, 
returning 0 (or even 1, I tried both) from the 
signal handler at 
at the Window level, I still only get one "print line" per key press.
ie it does not propogate  up to the child Gdkwindow ie the Gtk2::DrawingArea

Thanks,
Mitchell

******************
sample.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
                                 key-press-mask
                                
/]);

$window->add_events ([qw/
                                  key-press-mask
                                 /]);


$draw->signal_connect (motion_notify_event => \&motion_notify_event);
$window->signal_connect (key_press_event => \&key_press_event);
$draw->signal_connect (key_press_event => \&key_press_event);

sub key_press_event {
my $widget=shift ;
my $event=shift;
print "we got called \n";
return 0;
}


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;



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