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

Re: Gtk2::DrawingArea



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

I just noticed that if I modified this code
> 
> Here is a simple example:
> 
> ----------drawingarea.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
>                                  /]);
>  $draw->signal_connect (motion_notify_event => \&motion_notify_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";
> my $keyval= $event->keyval;
> if ($keyval == $Gtk2::Gdk::KeySyms{Up}) {
> print "we got an up arrow yay!!! \n";
> 
> }
> 
> }
> 
> 
> 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;
> 
> -----------------
>

to this:

 
#!/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);

sub key_press_event {
my $widget=shift ;
my $event=shift;
print "we got called \n";
my $keyval= $event->keyval;
if ($keyval == $Gtk2::Gdk::KeySyms{Up}) {
print "we got an up arrow yay!!! \n";

}

}


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;

****************

then it works
(i get 

Name "Gtk2::Gdk::KeySyms" used only once: possible typo at ./toggle2.pl line 27.
we got called
Use of uninitialized value in numeric eq (==) at ./toggle2.pl line 27.
we got called
Use of uninitialized value in numeric eq (==) at ./toggle2.pl line 27.
we got called
Use of uninitialized value in numeric eq (==) at ./toggle2.pl line 27.
we got called
Use of uninitialized value in numeric eq (==) at ./toggle2.pl line 27.
we got called
Use of uninitialized value in numeric eq (==) at ./toggle2.pl line 27.
                                

because I did not use Gtk2::Gdk::Keysyms;

but why is this only setup-able for the enclosing window and not for the
drawingarea window itself?

Thanks,

Mitchell


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