Re: Sticky pop-up menus

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() });

my $b = Gtk2::Button->new_from_stock('gtk-ok');
$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');

        $item = Gtk2::MenuItem->new_with_mnemonic('Item _2');

        $item = Gtk2::SeparatorMenuItem->new();
        $item = Gtk2::MenuItem->new_with_mnemonic('Item _3');

        $menu->popup(undef, undef,
                     undef, undef,

        return TRUE;




Emmanuele Bassi,  E: ebassi gmail com

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