Re: Entry / TextBuffer that does not listen to accelerators?

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 ***

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";
  <menubar name='Menu'>
    <menu action='File'>
    <menuitem action='u_action'/>

# Actions
$Menu{actions} = [
     [ 'File', undef, 'File' ], 
     [ "u_action",  undef,    "Do nothing", "u", undef, \&u_action ]
$Menu{action_group} = Gtk2::ActionGroup->new('Menu');

# UIManager
$Menu{manager} = Gtk2::UIManager->new();

# Actions -> UIManager
$Menu{manager}->insert_action_group($Menu{action_group}, 0);

# Menu{string} -> UIManager

# Accelerators -> Top{window}

# VBox -> Top{window}
$Top{vbox} = Gtk2::VBox->new();

# 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

# the action
        my $count;
        sub u_action {
                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?


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