YAD - Tips
What command would you like to see . Same result yad first or last
- Attachments
-
- capture27172.png
- (52.86 KiB) Downloaded 98 times
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
Hi April, and thanks. What I'm asking for is an example for having YAD handle the exchange. Then, maybe it's not YAD I'm after but GtkDialog. There's a nice example here, several here, and an intro by zigbert here. As not to spend much time trying to reinvent the wheel, and considering the amount of user input remains the same, I assigned an icon to my script and placed it on the launch bar for easy-peasy access.
- Attachments
-
- cel2fah-launch.jpg
- (8.19 KiB) Downloaded 839 times
Hi matchpoint, something like this maybe ?
EDIT: Removed "--text-align=center" from above script for compatibility with older yad version
Fred
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
Fred
Last edited by fredx181 on Sat 10 Feb 2018, 16:54, edited 2 times in total.
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
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
The esac in not yad code, it's builtin bash code, "case ... in", should be finished with esac, just like if ....; fi
Only where it shows "yad ......." is yad code.
edit: hopefully you have higher yad version than 0.12 (which is included in some Puppies), probably works only with version higher than 0.12 (or maybe needs some adjustments to make it work with 0.12)
edit2: edited the script above slightly so there's better chance it works with older yad.
Fred
- Attachments
-
- 2018-02-10-171517_402x176_scrot.png
- Convert temperature
- (26.13 KiB) Downloaded 831 times
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
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.
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.
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.
Let me understand, you want to run the script in terminal, type 1 or 2 and the rest by YAD gui, or do you want to type the temperature also in terminal and use YAD only for the final output ?
Fred
Last edited by fredx181 on Sat 10 Feb 2018, 17:31, edited 1 time in total.
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
Hi matchpoint, I think I sort of get it now what you'd like, anyway here's another with 2 boxes where you can type in the choices, ok, I'll relax now
Fred
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
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
Fred, I'd like the dialog to run and read like my script, except with one line spacings between each entry and not yet requesting temperature input until a choice has been made. Once made however, the dialog should then switch to an "Enter temperature (C/F)" sequence, rest for 3 or so seconds after user input, then exit, effectively removing the need to "Press any key to exit."
Can do?
You know, even this script I have should sign off like how I've described.
And how do I get spacing between lines when dumping to stdout?
Like between these opening echos?
Can do?
You know, even this script I have should sign off like how I've described.
And how do I get spacing between lines when dumping to stdout?
Like between these opening echos?
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
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
matchpoint wrote: Can do?
Hi matchpoint, sorry, I keep misunderstanding what you'd like to accomplish, maybe someone else understands.
Perhaps best to try make script yourself with gui dialog commands included and show that (even if doesn't work as you like, anyway then it's clear where the gui dialog part should be)
Fred
-
- Posts: 168
- Joined: Fri 26 Jan 2018, 20:54
- misko_2083
- Posts: 114
- Joined: Tue 08 Nov 2016, 13:42
matchpoint, there is this script
https://www.gnome-look.org/content/show ... ent=174312
I've had a quick look and it does what you need. Plus, it checks if you enter the temerature bellow the absolute zero.
https://www.gnome-look.org/content/show ... ent=174312
I've had a quick look and it does what you need. Plus, it checks if you enter the temerature bellow the absolute zero.
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.
I wonder how this will work in the tabbed version?
clears all data. No the same as updating existing data. Empty and refill.[/code]
I wonder how this will work in the tabbed version?
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
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]
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. .
Thanks,
Fred
Thanks step! I haven't had a chance to try that out yet.
Here is yad 40.3 with html (webkit) 64bit compiled on fatdog 721
https://drive.google.com/open?id=11DrgG ... iJogqlHS8A
Hi Fred
A lot of your yad GUIs like the ones for gdrive need to refresh update the data in the list field, normally you close the dialog gui and open a new one ... now you don't have to, as the fields are emptied and then refilled by using --list --listen <pipe to receive new data. One advantage as in wifi-scanner is that the gui can be placed and resized only once without fear of it re-opening somewhere differen on your desktop (manageability).
Here is what I needed it for (demo). Victor Ananjetsky kindly posted an answer to me!
In this example if you select with checkboxes on 'OK' gui closes and all checked rows are printed to stdout. Note '--dclick-action' I set to output to /tmp/net only one row which is double clicked, meaning the gui stays open with fresh scan results updated every 8 seconds in my while true loop.
Hope it helps.
Here is yad 40.3 with html (webkit) 64bit compiled on fatdog 721
https://drive.google.com/open?id=11DrgG ... iJogqlHS8A
Hi Fred
A lot of your yad GUIs like the ones for gdrive need to refresh update the data in the list field, normally you close the dialog gui and open a new one ... now you don't have to, as the fields are emptied and then refilled by using --list --listen <pipe to receive new data. One advantage as in wifi-scanner is that the gui can be placed and resized only once without fear of it re-opening somewhere differen on your desktop (manageability).
Here is what I needed it for (demo). Victor Ananjetsky kindly posted an answer to me!
In this example if you select with checkboxes on 'OK' gui closes and all checked rows are printed to stdout. Note '--dclick-action' I set to output to /tmp/net only one row which is double clicked, meaning the gui stays open with fresh scan results updated every 8 seconds in my while true loop.
Hope it helps.
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[@]}
Thanks Stemsee !
Nice, refresh while window stays open.
What I actually would like is a button to process an item (instead double click action) while the window stays open.
Do you know if that's possible ? (tried some things, but couldn't manage).
EDIT: Found this, which works similar (window stays open), but it also has only option double-click action.
https://sourceforge.net/p/yad-dialog/wi ... /?limit=50
Fred
Nice, refresh while window stays open.
What I actually would like is a button to process an item (instead double click action) while the window stays open.
Do you know if that's possible ? (tried some things, but couldn't manage).
EDIT: Found this, which works similar (window stays open), but it also has only option double-click action.
https://sourceforge.net/p/yad-dialog/wi ... /?limit=50
Fred
Maybe you need to use --select-action
fromhttps://groups.google.com/forum/#!topic ... FYTLhtccd4
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