Re: I want popup menus :(



muppet wrote:


1. connect to the "button-press-event" on the treeview. if you want right-clicking to select the row before popping up the menu, use signal_connect_after() to connect to the button-press-event, so that the default handlers run first.
$usertree->signal_connect('button-press-event' => sub {
    my $event = $_[1];
    if ($event->button == 3) {
        $gladexml->get_widget('pmUsers')->popup(undef, undef, undef,
            user_selected(), $event->button, 0);
        return TRUE;
    }
    else {
        return FALSE;
    }
} );

if i connect after it doesn't seem to work (conn doesn't appear).
other way popup appears and disappears quickly. i think it has with 0, which should be

activate_time :  the time at which the activation event occurred.
The activate_time parameter should be the time stamp of the event that initiated the popup. If such an event is not available, use gtk_get_current_event_time() instead.

i don't really understand from where i should get that activation time..

2. in the handler:
a) if $event->button==3 (the right mouse button), create your menu and call $menu->popup. the menu pos func can be undef unless you want to do something fancy. pass $event->button to popup() so that the menu tracks the correct mouse button.

b) if you need to know which row the user clicked on: ($x, $y) = $event->coords tells you where the user clicked, and you can pass those to $treeview->get_path_at_pos to find the path, column, and cell coords of the click.
Currently i'm using this to get name of selected user. My treeview has 2 columns: Pixbuf and label, so i get second column out of it.

my $usertree = $gladexml->get_widget('UserTree');
$usertree->signal_connect_after('row-activated' => sub {
    compose_msg(user_selected());
} );

sub user_selected { # {{{
    my $selection = $usertree->get_selection;
    my $row = $selection->get_selected_rows;

    my $treestore = $usertree->get_model;
    my $iter = $treestore->get_iter($row);

    return $treestore->get($iter, 1);
} # }}}

Attachment: x11.vcf
Description: Vcard



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