Code: Select all
#!/bin/sh -a
# -a option exports all variables and functions
RIGHT=14 DOWN=36 WIDTH=80 HEIGHT=150 # define variables with defaults
DRIVE= # export this variable now so the script can use it after gtkdialog3
# has assigned it a value
#probepart |grep -v none |sed 's#^/dev/##' |sed 's/|.*$//' |sed 's/$/||/' > /tmp/drvinfo # make tablebox input file
# Do we need a temp file?
# Stick it in a function and you can refresh it from the gui.
pp(){ probepart|sed '/\(none\|swap\)/d;s|/dev/||;s/|.*//'; }
display(){ echo "drive selected: ${!1}"; }
GUI=$(cat <<EOV|sed 's/#.*//'|tee /tmp/gui1 /tmp/gui3 # interpolate and allow comments in gui
#<window title="GUI" default_width="$WIDTH" default_height="$HEIGHT"> # comment
<window title="GUI"> # let the geometry option control the size and placement
<vbox>
<table>
#<label>Drive|M|B</label>
<label>Drive</label>
<variable>DRIVE</variable>
<input>pp</input>
</table>
<button use-underline="true" label="_Refresh">
#<action>echo \$DRIVE</action> # must escape variable. Do you understand why?
<action>display DRIVE</action> # call display use DRIVE indirectly
<action type="clear">DRIVE</action>
<action type="refresh">DRIVE</action>
</button>
<button cancel></button>
</vbox>
</window>
EOV)
# run gui 3 times (peruse files /tmp/gui1 /tmp/gui2 /tmp/gui3)
gtkdialog3 -d -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --program
gtkdialog3 -d -f /tmp/gui1 -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}} # --file
# prepare files to run --event-driven (/tmp/gui2 & /tmp/gui3)
# N.B. --geometry not effective when used in this context
# so use width/height request instead
sed '/^GUI/,$d' $0 >/tmp/gui2
sed -i '$a\gtkdialog3 -e /tmp/gui3' /tmp/gui2
sed -i -e "1i\export MAIN_DIALOG='" -e "\$a\'" /tmp/gui3
sed -i 's/GUI"/& width-request="'$WIDTH'" height-request="'$HEIGHT'"/' /tmp/gui3
chmod +x /tmp/gui2
/tmp/gui2