Page 1 of 1

How to use Focus and Enter keys? (Solved)

Posted: Thu 02 May 2013, 01:05
by arivas_2005
greetings
excuse my english

i have a little example in gtk

Code: Select all

#! /bin/bash
export DIALOG='
<window title="PERSONAL UNIT OR FOLDER" resizable="true" icon-name="computer">
 <vbox>
    <checkbox>
      <variable>CHECKBOX</variable>
      <label>FOLDER COMMON</label>
    </checkbox>
    <text use-markup="true" width-chars="40">
       <label>INPUT PERSONAL UNIT</label>
    </text>
    <entry xalign="0.5" is-focus="true">  
      <default>User Input</default>
      <variable>NAME1</variable>
      <action signal="activate">command</action>            
   </entry>
   <entry>
     <default>Password Input</default>
     <variable>NAME2</variable>
   </entry>   
   <hbox>
    <button ok></button>
    <button cancel></button>
   </hbox>
  </vbox>
 </window>
'
I=$IFS; IFS=""
for DECLARNAME in  $(gtkdialog --center --program DIALOG); do
  eval $DECLARARNOMBRE
done
IFS=$I
=============
How i can to pass focus of "User Input" to "Password Input" texbox using enter key?

or
fill textbox "User Input" and press [enter] then
... the focus should move to the second box, then newly I fill textbox "Passworod Input", then
I press to enter key.... pass the focus to button OK, and finally press to enter key for end

newlly, excuse my english.
(I used google traslate)
thanks

focus

Posted: Thu 02 May 2013, 06:48
by L18L
I am afraid you cannot...

But old users (like me) are used to take the TAB key for jumping to next input field. That works :wink:

Posted: Thu 02 May 2013, 10:19
by SFR
Hmm, actually it's possible, but only in Gtkdialog >= 0.8.1:

Code: Select all

<action signal="activate">grabfocus:NAME2</action>
Ref.: http://code.google.com/p/gtkdialog/wiki/entry

However I'm accustomed to use TAB key as well. :wink:

Greetings!

Posted: Thu 02 May 2013, 17:13
by thunor

Code: Select all

#! /bin/bash
export DIALOG='
<window title="PERSONAL UNIT OR FOLDER" resizable="true" icon-name="computer">
 <vbox>
    <checkbox>
      <variable>CHECKBOX</variable>
      <label>FOLDER COMMON</label>
    </checkbox>
    <text use-markup="true" width-chars="40">
       <label>INPUT PERSONAL UNIT</label>
    </text>
    <entry xalign="0.5" is-focus="true"> 
      <default>User Input</default>
      <variable>NAME1</variable>
      <action signal="activate">grabfocus:NAME2</action>    #<<< Just as SFR stated above.
      <action signal="activate">command</action>           
   </entry>
   <entry activates-default="true">              #<<< This will activate the OK button on Enter.
     <default>Password Input</default>
     <variable>NAME2</variable>
   </entry>   
   <hbox>
    <button use-stock="true" label="gtk-ok" can-default="true" has-default="true">    #<<< Is now the default button.
    </button>
    <button cancel></button>
   </hbox>
  </vbox>
 </window>
'
I=$IFS; IFS=""
for DECLARNAME in  $(gtkdialog --center --program DIALOG); do
  eval $DECLARARNOMBRE
done
IFS=$I
Also be aware that you will be evaluating everything gtkdialog, gtk and any executed programs output with this command:

Code: Select all

for DECLARNAME in  $(gtkdialog --center --program DIALOG); do
At the least you should change it to this:

Code: Select all

for DECLARNAME in  $(gtkdialog --center --program DIALOG 2>/dev/null); do
although I quite like this:

Code: Select all

for DECLARNAME in  $(gtkdialog --center --program DIALOG | grep "^[A-Za-z0-9]*="); do
because it additionally prevents evaluating anything sent to stdout by executed programs.

Anyway, you get the idea right.

Regards,
Thunor

P.S. Don't forget to remove the "#<<<" comments from the code above.

Posted: Thu 02 May 2013, 18:22
by arivas_2005
Solved my problem
Thanks and greetings !