Re: Sticky pop-up menus
- From: Emmanuele Bassi <ebassi gmail com>
- To: gtk-perl-list gnome org
- Subject: Re: Sticky pop-up menus
- Date: Mon, 13 Nov 2006 16:27:27 +0000
On Mon, 2006-11-13 at 16:32 +0100, Ratcliffe, Jeffrey (Peters) wrote:
The pop-up menus in my little scanning application work fine in themselves, but they are only
visible whilst the right mouse button is pressed.
A user has requested that they should work ala Nautilus, i.e. in addition to the current
behaviour, on a single right click, the pop-up stays visible and the item can then be
selected with left or right clicks.
I've had a search around, but can't find a standard solution to this.
attach the menu popup call to the button-release-event instead of
button-press-event, and be sure to return TRUE from the event handler
callback to stop the chain.
use Glib ':constants';
use Gtk2 'init';
my $w = Gtk2::Window->new('toplevel');
$w->signal_connect(destroy => sub { Gtk2->main_quit() });
$w->set_border_width(12);
$w->show();
my $b = Gtk2::Button->new_from_stock('gtk-ok');
$w->add($b);
$b->set_size_request(300, 200);
$b->signal_connect(clicked => sub { $w->destroy() });
$b->signal_connect(button_release_event => sub {
my ($button, $event) = @_;
return FALSE if $event->button != 3;
my $item;
my $menu = Gtk2::Menu->new();
$item = Gtk2::MenuItem->new_with_mnemonic('Item _1');
$menu->append($item);
$item->show();
$item = Gtk2::MenuItem->new_with_mnemonic('Item _2');
$menu->append($item);
$item->show();
$item = Gtk2::SeparatorMenuItem->new();
$menu->append($item);
$item->show();
$item = Gtk2::MenuItem->new_with_mnemonic('Item _3');
$menu->append($item);
$item->show();
$menu->popup(undef, undef,
undef, undef,
$event->button,
$event->time);
return TRUE;
});
$b->show();
Gtk2->main();
0;
ciao,
Emmanuele.
--
Emmanuele Bassi, E: ebassi gmail com
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]