how to set focus

View: New views
2 Messages — Rating Filter:   Alert me  

how to set focus

by Sreejith S :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi...

Im using Gtk2-Perl..Can i able to set the focus to different widgets according to the keys (like keyascii).??

I also need to clear the contents of all the widgets which are placed in a vbox,when i pressed a clear button...is that posiible??

I know the solution for the above qns are simple..but i am very nes to this concept...so can i get a useful documentation describing all these type hints...

Regards...
Sreejith



_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: how to set focus

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Aug 14, 2009, at 10:06 AM, Sreejith S wrote:

> Hi...
>
> Im using Gtk2-Perl..Can i able to set the focus to different widgets  
> according to the keys (like keyascii).??

Using the Tab key to cycle through focusable widgets works out of the  
box.  You can mangle the order if you need, but you shouldn't need to.

If you want to be able to hit alt+a to jump to the Address: input,  
then you want mnemonic labels:

http://library.gnome.org/devel/gtk/stable/GtkLabel.html
http://library.gnome.org/devel/gtk/stable/GtkLabel.html#gtk-label-new-with-mnemonic
http://library.gnome.org/devel/gtk/stable/GtkLabel.html#gtk-label-set-mnemonic-widget

Note that Gtk2::Label::new() is actually an alias for  
new_with_mnemonic, so the flow would look like this:

    $name_label = Gtk2::Label->new ("_Name:");
    $name_entry = Gtk2::Entry->new ();
    $name_label->set_mnemonic_for ($name_entry);

    $address_label = Gtk2::Label->new ("_Address:");
    $address_entry = Gtk2::Entry->new ();
    $address_label->set_mnemonic_for ($address_entry);

    # and then pack and show those...

In your window, hitting alt+n will put the cursor in the Name entry,  
and alt+a will put the cursor in the Address entry -- and it will  
select the current contents, since the user likely wants to replace it.


> I also need to clear the contents of all the widgets which are  
> placed in a vbox,when i pressed a clear button...is that posiible??

You'll have to keep a list of the entries you want to clear:

     foreach my $e (@{ $mybox->{entries} }) {
         $e->set_text ('');
     }




--
Santa ate all the cookies!
   -- Zella's first, indignant words on Christmas morning, '07.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list