Re: I want popup menus :(
- From: muppet <scott asofyet org>
- To: gtk-perl mailing list <gtk-perl-list gnome org>
- Subject: Re: I want popup menus :(
- Date: Mon, 19 Jul 2004 20:37:23 -0400
On Jul 19, 2004, at 6:25 AM, ArtÅras Ålajus wrote:
$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);
passing user_selected() there does nothing, as the menu_pos callback is
undef.
return TRUE;
}
else {
return FALSE;
}
} );
if i connect after it doesn't seem to work (conn doesn't appear).
interesting; i guess something in the treeview returns TRUE and stops
the after handlers from running. the workaround is to force the
selection manually. see below.
other way popup appears and disappears quickly.
that's because it's a context menu; you're supposed to press the mouse
button to pop up the menu, track to the thing you want, and then let
go.
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..
er, just like it says: $event->time or Gtk2->get_current_event_time.
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 { # {{{
...
} # }}}
like i said earlier, the problem is that if you connect to
button-press-event to get normal context menu behavior, the handler
happens before the treeview's handler which selects the clicked row.
so you would need to trigger the selection before it will reflect the
row on which you've clicked.
an example:
#!/usr/bin/perl -w
use strict;
use Glib qw(TRUE FALSE);
use Gtk2 -init;
use Gtk2::SimpleList;
my $window = Gtk2::Window->new;
my $list = Gtk2::SimpleList->new ('Some stuff' => 'text');
@{$list->{data}} = qw(one two three four five six seven eight nine);
my $scroller = Gtk2::ScrolledWindow->new;
$window->add ($scroller);
$scroller->add ($list);
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->show_all;
$list->signal_connect (button_press_event => sub {
my ($widget, $event) = @_;
# handle only right button clicks.
return FALSE unless $event->button == 3;
# we're preempting row selection since we're running first,
# so the selected row does not necessarily correspond to the
# one which has been clicked. find out which one *has* been
# clicked.
my ($path, $column) = $widget->get_path_at_pos ($event->coords);
# this bit isn't entirely necessary, but can remove the surprise
# for some users who wouldn't expect a right click *not* to select
# the row.
$widget->get_selection->select_path ($path);
my $model = $widget->get_model;
my $text = $model->get ($model->get_iter ($path), 0);
my $menu = Gtk2::Menu->new;
foreach (qw(left right up down)) {
my $item = Gtk2::MenuItem->new ($_." ".$text);
$menu->append ($item);
$item->show;
}
$menu->popup (undef, undef, undef, undef, $event->button,
$event->time);
return TRUE;
});
Gtk2->main;
--
Walk softly, and carry a BFG-9000.
-- unknown
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]