Bash/gtkdialog: function is stealing focus? [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

Bash/gtkdialog: function is stealing focus? [SOLVED]

#1 Post by zigbert »

This test script shows my issue:
The function is run as a background process, but still it prevents the code to reach the end (gxmessage).
How can I get the Exit-value from the main gui while the function-gui shows? I can not use the launch/close commands in gtkdialog.

Thanks for any help

Code: Select all

#!/bin/bash

myfunc(){
	echo '<vbox><button ok></button></vbox>' | gtkdialog -s
}
export -f myfunc

export XML='
<vbox>
  <text><label>Exit value is correct if pressing the button below. Opening another window corrupts the Exit value</label></text>
  <button>
    <label>My exit value is: Button1</label>
    <action type="exit">Button1</action>
  </button>
  <button>
    <label>Open another window corrupts the exit value</label>
    <action>myfunc &</action>
  </button>
</vbox>
'
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog -p XML); do
	eval $STATEMENTS
done
IFS=$I

gxmessage "Exit value is: $EXIT"
Last edited by zigbert on Thu 29 Dec 2016, 09:02, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#2 Post by MochiMoppel »

Code: Select all

<action>myfunc > /dev/null &</action> 
This will let the code proceed to the gxmessage command, showing the EXIT value of the main window, even if the child window is still alive.

If you also need the EXIT value of the child window you can add an eval loop to the function:

Code: Select all

myfunc(){ 
for STATEMENTS in $(echo '<button></button>' | gtkdialog -s );do
	eval $STATEMENTS
done
gxmessage "Exit value of child is: $EXIT"
} 
export -f myfunc

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#3 Post by zigbert »

Thanks a lot! :D

Post Reply