26.08.2014, 04:12, "Daniel Kasak" <d.j.kasak...@gmail.com>:
> I've tried the above fix, but things are still not good. I've uploaded a 
> simple demo to:
> http://tesla.duckdns.org/downloads/menu.pl ( pasting stuff in gmail always 
> mangles things ).
>
> $event is still morphing from a Gtk3::Gdk::EventButton to a Gtk3::Gdk::Event, 
> which is giving:
>
> *** unhandled exception in callback:
> ***   Can't locate object method "time" via package "Gtk3::Gdk::Event" at 
> menu.pl line 66.
> ***  ignoring at /usr/local/lib64/perl5/5.16.3/Gtk3.pm line 318.
>
> Frankly, I can work around this. What's annoying me most at the moment is 
> that the menu doesn't pop up. Can anyone see why I can't get a menu?

Try attached version.

$menu is a local variable, it is destroyed in Gtk3 right after popup.
You can either use global "our $menu" or create "my $menu" outside subroutines 
and
pass it to 'button_press_event' callback:

$treeview->signal_connect( button_press_event => sub { on_tree_click( @_, $menu 
) } );

I don't know why $menu is not destroyed in Gtk2 :)
#!/usr/bin/perl

use strict;
use warnings;

use Gtk3 '-init';
use Glib 'TRUE', 'FALSE';

use Data::Dumper;

my $window = Gtk3::Window->new( 'toplevel' );
$window->set_default_size( 400, 300 );
$window->set_gravity( 'GDK_GRAVITY_CENTER' ); # ?
$window->set_title(' Menu' );
$window->set_border_width( 10 );
$window->signal_connect( destroy => sub { Gtk3->main_quit } );

my $sw = Gtk3::ScrolledWindow->new;
$window->add( $sw );

my $treeview = Gtk3::TreeView->new;
my $renderer = Gtk3::CellRendererText->new;
my $column = Gtk3::TreeViewColumn->new_with_attributes(
    "items",
    $renderer,
    'text'  => 0
);

my $menu = Gtk3::Menu->new();
    
foreach my $context_action ( 'refresh', 'edit' ) {
    my $item = Gtk3::MenuItem->new_with_label( $context_action );
    $menu->append( $item );
    $item->show();
    #$item->signal_connect( activate => sub { &$context_action() ; } );
}

$treeview->append_column( $column );
$treeview->signal_connect( button_press_event => sub { on_tree_click( @_, $menu ) } );
$sw->add( $treeview );

my $model = Gtk3::ListStore->new( qw/ Glib::String / );

for my $item ( qw/ one two three four five / ) {
    $model->set(
        $model->append
      , 0 , $item
    );
}

$treeview->set_model($model);
$window->show_all();
Gtk3->main();

sub on_tree_click {
    my ( $widget, $event, $menu ) = @_;
    bless $event, 'Gtk3::Gdk::EventButton';
    print "widget:\n" . Dumper( $widget ) . "\nevent:\n" . Dumper( $event ) . "\n";
    $menu->popup( undef, undef, undef, undef, $event->button(), $event->time());
}

sub refresh {
    
    print "refreshing ...\n";
    
}

sub edit {
    
    print "editing ...\n";
    
}
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to