Posted: Sat 10 Feb 2018, 06:44
What command would you like to see . Same result yad first or last
Code: Select all
#!/bin/bash
SETUP=`yad --title="Temperature scale conversion" --center --text=" <b>*** Temperature scale conversion ***</b>" \
--width=400 \
--window-icon="preferences-system" --form \
--field=" Select: :CB" "Convert Celsius to Fahrenheit!Convert Fahrenheit to Celsius" \
--field=" Set temperature: :NUM" "1!1..500!1" \
--button="gtk-cancel:1" --button="gtk-ok:0"`
[[ $? -ne 0 ]] && exit 1
export CHOICE=$(echo $SETUP | cut -d "|" -f 1)
export TEMP_=$(echo $SETUP | cut -d "|" -f 2 | cut -f1 -d".")
case $CHOICE in
"Convert Celsius to Fahrenheit")
tc=$TEMP_
# formula Tf=(9/5)*Tc+32
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
echo "$tc C = $tf F" | yad --title="Celsius to Fahrenheit" --center --text-info --width=300 --button="gtk-close:0"
;;
"Convert Fahrenheit to Celsius")
tf=$TEMP_
# formula Tc=(5/9)*(Tf-32)
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf F = $tc C" | yad --title="Fahrenheit to Celsius" --center --text-info --width=300 --button="gtk-close:0"
;;
esac
Yes, save it for example as "tempconv" and make excutable:matchpoint wrote:It looks like your intention was for me to save it as a script and have it open a kind of message box, correct?
What's the "esac" on the end? YAD lingo?
Code: Select all
chmod +x tempconv
Probably Zenity doesn't have "--text-align=center" , btw, I removed that from script above to be compatible with older yad versions. (see also edit in my previous post)matchpoint wrote:Ha! I forgot to save the paste before running.
That the console now complains with "--text-align=center" tells me we have a Zenity/YAD version difference, right?
I've come across these type messages before.
Ultimately though, I'd like the choice selection to be made like in the original, by keystroke, not mouse click.
Maybe one more example, Fred. Then I think I may be able to run with it.
Code: Select all
#!/bin/bash
SETUP=`yad --title="Temperature scale conversion" --center --text="<b>*** Temperature scale conversion ***</b> \n Type 1 to convert Celsius to Fahrenheit \n Type 2 to convert Fahrenheit to Celsius" \
--width=400 \
--window-icon="preferences-system" --form \
--field=" Type 1 or 2: : " "" \
--field=" Type temperature: : " "" \
--button="gtk-cancel:1" --button="gtk-ok:0"`
[[ $? -ne 0 ]] && exit 1
export CHOICE=$(echo $SETUP | cut -d "|" -f 1)
export TEMP_=$(echo $SETUP | cut -d "|" -f 2)
case $CHOICE in
1)
tc=$TEMP_
# formula Tf=(9/5)*Tc+32
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
echo "$tc C = $tf F" | yad --title="Celsius to Fahrenheit" --center --text-info --width=300 --button="gtk-close:0"
;;
2)
tf=$TEMP_
# formula Tc=(5/9)*(Tf-32)
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf F = $tc C" | yad --title="Fahrenheit to Celsius" --center --text-info --width=300 --button="gtk-close:0"
;;
esac
Code: Select all
#!/bin/bash
echo "*** Temperature scale conversion ***"
echo "Convert Celsius to Fahrenheit = 1"
echo "Convert Fahrenheit to Celsius = 2"
echo -n "Select 1 or 2, then Enter:"
read choice
if [ $choice -eq 1 ]
then
echo -n "Enter temperature (C) : "
read tc
# formula Tf=(9/5)*Tc+32
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
echo "$tc C = $tf F"
elif [ $choice -eq 2 ]
then
echo -n "Enter temperature (F) : "
read tf
# formula Tc=(5/9)*(Tf-32)
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf F = $tc C"
else
echo "Please select 1 or 2 only"
exit 1
fi
echo -n "
--> Press any key to exit "
read echoice
exit 0
Code: Select all
echo -e ' \t '
matchpoint wrote: Can do?
Code: Select all
echo -e '\f' > /tmp/pipe
Yes, it works for a tabbed dialog, as long as you write to the pipe of the contained yad --list process. When the container dialog exits, it outputs the current contents of the list widget having erased everything before the \f. In some cases involving multiple columns I had to use \f\n instead of \f.stemsee wrote: I wonder how this will work in the tabbed version?Code: Select all
echo -e '\f' > /tmp/pipe
Could you provide a simple example of why/how this can be useful ? (also, with tabbed dialog I'd like to understand also)stemsee wrote:I found the solution to my request, which was how to use yad --list --listen to receive data to replace existing data without closing and re-opening the yad gui. .
Code: Select all
#!/bin/bash
#Victor Ananjesky script adapted by stemsee for wifi scanning
#
test -e /tmp/yadpipe03 && rm -f /tmp/yadpipe03
# Named pipe initialization
export PIPE_03=/tmp/yadpipe03
mkfifo $PIPE_03
exec 3<> $PIPE_03
function clear_all
{
PATTERN='
s/^.*Address: ([0-9A-Z:]*)/\n\1/p
s/^.*Quality=([^ ]*).*Signal level=(.*)/\1 \2/p
s/^.*key:([onf]*)/~\1~/p
s/^.*ESSID://p'
while true
do
iwlist wlan4 scan | sed -rn "$PATTERN" | tac > $PIPE_03
sleep 8
echo -e '\f'
done
}
export -f clear_all
# Main Dialog
Record=($(yad --list --separator="|" --grid-lines=hor \
--width=300 --height=200 --center \
--title="Wifi-Scanner" \
--text="Example" \
--dclick-action=echo -e $1 > /tmp/net \
--column "AP ssid" --column "Encryption" --column "qualiy/strength" --column "bssid" --column "Check:CHK"\
--button="Start Scannning!gtk-clear":'bash -c "clear_all > $PIPE_03"' \
--button="OK!gtk-ok":0 \
--listen --print-all < $PIPE_03))
Action=$?
echo ${Record[@]}
Code: Select all
#!/bin/bash -a
mkfifo ${fifo=$(mktemp -u)}
exec {fd}<>${fifo}
dbl () {
echo double event - $1
printf '\f\n' > $fifo
printf "1\n2\n3\n4\n5\n" > $fifo
}
sel () {
echo select event - $1
}
yad \
--list \
--listen \
--dclick-action 'bash -c "dbl %s"' \
--select-action 'bash -c "sel %s"' \
--column 'A' 1 2 3 4 5 < $fifo