Re: How to Add a Keyboard Accelarator to a Button



Shlomi Fish wrote:
[...]
user presses Alt+[Letter] or whatever is the GNOME convention, it will be
pressed automagically.

my $button = Gtk::Button->new('_Whatever');

... and this makes W as shortcut ...


I tried it. It does not work. All I get is a button that displays the
string "_Whatever", with an underscore at the beginning.

Regards,

        Shlomi Fish

Liviu

 Here is a demo programm ...

#! /usr/bin/perl -w

use strict;
use Gtk;

Gtk->init();

my $win = new Gtk::Window 'toplevel';
$win->signal_connect('delete_event', sub {Gtk->main_quit(); return
0;});

my $accel_group = Gtk::AccelGroup->new();
$accel_group->attach($win);

my $vbox = Gtk::VBox->new();

my $butt = Gtk::Button->new('_Whatever');
## the following line does the underlining and get the shortcut
letter.
my $acc = $butt->child->parse_uline('_Whatever');
## i define the accelerator
$butt->add_accelerator('clicked', $accel_group, $acc, 'mod1_mask',
['visible', 'locked']);


$butt->signal_connect('clicked', \&button_clicked);
$vbox->add($butt);
$win->add($vbox);

$win->show_all();

Gtk->main();

exit(0);

sub button_clicked {
    warn "I was clicked";
}

## end of script


Liviu




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