[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Entry / TextBuffer that does not listen to accelerators?
- From: Stephan Brunner <stephan brunner gmx de>
- To: Jan Hudec <bulb ucw cz>
- Cc: gtk-perl-list gnome org
- Subject: Re: Entry / TextBuffer that does not listen to accelerators?
- Date: Fri, 30 Sep 2005 16:10:33 +0200
Am Freitag 30 September 2005 15:14 schrieb Jan Hudec:
> On Fri, Sep 30, 2005 at 14:51:40 +0200, Stephan Brunner wrote:
> > Hi all,
> >
> > I'd thought this is a common problem, but didn't find a solution in the
> > docs or via google:
> >
> > In my application, I would like to have some "fast and simple"
> > accelerators like <u> or <delete>. On the other hand, I have some
> > Gtk2::Entry and Gtk2::TextBuffer for text editing. Of course, I still do
> > want to be able to insert 'u' in those...
>
> It should work. Out of the box. Have you _tried_ it?
I tried it - see the following short example:
*** snip ***
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';
my %Top;
$Top{window} = Gtk2::Window->new;
$Top{window}->signal_connect (destroy => sub { Gtk2->main_quit; });
$Top{window}->set_default_size(300, 100);
my %Menu;
$Menu{string} = <<"EOS";
<ui>
<menubar name='Menu'>
<menu action='File'>
<menuitem action='u_action'/>
</menu>
</menubar>
</ui>
EOS
# Actions
$Menu{actions} = [
[ 'File', undef, 'File' ],
[ "u_action", undef, "Do nothing", "u", undef, \&u_action ]
];
$Menu{action_group} = Gtk2::ActionGroup->new('Menu');
$Menu{action_group}->add_actions($Menu{actions});
# UIManager
$Menu{manager} = Gtk2::UIManager->new();
# Actions -> UIManager
$Menu{manager}->insert_action_group($Menu{action_group}, 0);
# Menu{string} -> UIManager
$Menu{manager}->add_ui_from_string($Menu{string});
# Accelerators -> Top{window}
$Top{window}->add_accel_group($Menu{manager}->get_accel_group());
# VBox -> Top{window}
$Top{vbox} = Gtk2::VBox->new();
$Top{window}->add($Top{vbox});
# Menu -> VBox
$Top{vbox}->pack_start($Menu{manager}->get_widget('/Menu'), 0, 0, 0);
# Entry -> VBox
my $Entry = Gtk2::Entry->new();
$Entry->set_text("Enter some text (try 'u'!)");
$Top{vbox}->pack_start($Entry, 0, 0, 0);
# Run
$Top{window}->show_all;
Gtk2->main;
# the action
{
my $count;
sub u_action {
$count++;
print "$count: This is sub u_action...\n";
}
}
*** snap ***
I am not able to enter any 'u' into the Entry.
> The reason this should work is, that the active widget gets the input.
> If the widget does not handle it, it passes it on to it's parent. And so
> on up to the window, which handles the accels.
Reading this, I wonder even more why I can't get it to work the way I want to.
Is there some subtle mistake or usage-error in my code?
Stephan
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]