Re: Space Bar Issue




On May 23, 2006, at 11:53 PM, developer wrote:

Sooo much trouble with setting the focus on a widget. However, I did find one technique that 'almost' works. That is: $window- >set_focus_child($widget); It still does not (on it's own) make the widget have the focus. But after the screen loads, if I press the 'TAB' key, I see the dotted rectangle appear, and now the widget has the focus. That is a step in the right direction, but it still doesn't solve the problem.

Here's a simple example that may illuminate things for you.

#!/usr/bin/perl -w
use strict;
use Gtk2 -init;

my $window = Gtk2::Window->new;
my $vbox = Gtk2::VBox->new;
my $button1 = Gtk2::Button->new ('one');
my $button2 = Gtk2::Button->new ('two');
my $entry = Gtk2::Entry->new;

$window->add ($vbox);
$vbox->add ($button1);
$vbox->add ($entry);
$vbox->add ($button2);

# Now that all of the widgets have been added to the widget tree and are
# attached to a toplevel, we can set the initially-focused widget.
#
# If we do nothing, gtk+ will give keyboard focus to the first widget in
# $window's widget tree. By calling set_focus() here, we tell the window to
# give focus to the $entry.
$window->set_focus ($entry);
# Try commenting out that line, and note how $button1 takes the initial
# focus.  (You'll also need to comment out the set_focus_chain() line,
# or move this one after set_focus_chain()...)

# Another way to control the focus is the container's focus chain. By default, # the tab key cycles through a container's child widgets in order from top-left # to bottom-right. You can alter this by manually setting the "focus chain". # You can alter the order and even remove widgets from the chain. Note that it # doesn't make sense to call this on $window, because $window is a Gtk2::Bin, # which can have only one child. Instead, we call it on the $vbox. Here,
# we'll remove $button2 from the focus chain.
$vbox->set_focus_chain ($entry, $button1);
# Try commenting out that line, and note how the tab key cycles in the other
# direction, and also hits $button2.


# Because $window->set_focus($child) has visibility to all children in the
# window, it is preferrable to set_focus_chain().


$window->signal_connect (destroy => sub { Gtk2->main_quit });
$window->show_all;
Gtk2->main;




--
In some newer operating systems, time_t has been widened to 64 bits. In the negative direction, this goes back more than twenty times the age of the universe, and so suffices. In the positive direction, whether this range is sufficient to represent all possible times depends on the ultimate fate of the universe, but it can be expected to postpone overflow long enough for such implementation limits to be abolished.
  -- Wikipedia, on UNIX time.




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