Gtk3 context menu
- From: Daniel Kasak <d j kasak dk gmail com>
- To: GTK-Perl List <gtk-perl-list gnome org>
- Subject: Gtk3 context menu
- Date: Mon, 25 Aug 2014 16:16:43 +1000
Hi all. Some code I had that used to work ( I think anyway ) in Gtk2 no longer works:
---
in the constructor, I do:
$treeview->signal_connect( button_press_event => sub { $self->on_tree_click( @_ ) } );
then ...
sub on_tree_click {
  Â
   my ( $self, $widget, $event ) = @_;
  Â
   my $type   = $event->type;
   my $button = $event->button;
  Â
   print "caught: type [$type] button [$button]\nobj: " . Dumper( $button ) . "\n";
  Â
   if ( $type eq '2button-press' ) {
      Â
       $self->handle_double_click( $widget, $event );
      Â
   } elsif ( $button == 3 ) {
      Â
       $self->build_context_menu( $widget, $event );
      Â
   }
  Â
}
sub build_context_menu {
  Â
   my ( $self, $widget, $event ) = @_;
  Â
   my $menu = Gtk3::Menu->new;
  Â
   foreach my $context_action ( 'refresh', 'edit' ) {
      my $item = Gtk3::MenuItem->new( $context_action );
      $menu->append( $item );
      $item->show;
      $item->signal_connect( activate => sub { $self->$context_action ; } );
   }
  Â
   $menu->popup( undef, undef, undef, undef, $event->button, $event->time );
  Â
}
---
Everything in on_tree_click appears to be working, and it's calling handle_double_click() and build_context_menu() at the appropriate times. However building the context menu is not working. If right-click once, nothing happens. If I double-right-click, then I get a grey box appearing where the menu should be, but then handle_double_click() is called, and when it's done, the grey box disappears. Lastly, my $button is receiving a HASH instead of a number when I double-click:
caught: type [button-press] button [3]
obj: $VAR1 = 3;
caught: type [button-press] button [3]
obj: $VAR1 = 3;
caught: type [2button-press] button [HASH(0x480e228)]
obj: $VAR1 = {
         'x_root' => '86.7047119140625',
         'y_root' => '199.390365600586',
         'window' => bless( {}, 'Glib::Object::_Unregistered::GdkX11Window' ),
         'time' => 95324125,
         'x' => '80.7047119140625',
         'send_event' => 0,
         'device' => bless( {}, 'Glib::Object::_Unregistered::GdkX11DeviceXI2' ),
         'axes' => '3.73453945125965e-316',
         'state' => bless( do{\(my $o = 0)}, 'Gtk3::Gdk::ModifierType' ),
         'y' => '13.3903656005859',
         'button' => 3,
         'type' => '2button-press'
       };
What's going on? Why is $button sometimes a hash? And why doesn't my menu render properly?
Dan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]