Page 1 of 42
YAD - Tips
Posted: Sun 25 Jan 2015, 07:51
by smokey01
As there is not a lot of information/documentation about YAD I thought this might be a good place to help create some.
Zigbert started a thread called gtkdialog - tips on Thu Feb 12, 2009 3:32 am.
This has been a great resource to many and the contributions have been outstanding. I personally have visited that thread many times.
I know there are many people using YAD as it's quite easy to use albeit the lack of documentation.
I have been working on a YAD document for quite some time so I thought I would share it here and maybe some of you may be able and willing to help me complete it. I have used Notecase to capture the information.
You can obtain a copy of my efforts here:
http://smokey01.com/help/yad-tips-0.0.1.ncd.tar.xz
I hope you find it useful.
Enjoy.
Posted: Sun 25 Jan 2015, 08:59
by rg66
This page has a little better explanation of help and has a notebook example as well.
http://rpm.pbone.net/index.php3/stat/45 ... /nazwa/yad
Posted: Sun 25 Jan 2015, 10:55
by smokey01
Thanks, added.
Posted: Sun 25 Jan 2015, 14:15
by rg66
Here's a tip for drag and drop
Code: Select all
# yad --dnd
file:///root/Desktop/tmp
pipe it to sed 's/^.......//' to get a proper path
Code: Select all
yad --dnd | sed 's/^.......//'
/root/Desktop/tmp
Posted: Sat 31 Jan 2015, 05:15
by smokey01
rg66, are you able to solve this puzzle for me.
I want to be able to use the value of the selected items in the following script and use the variables with an external application.
Code: Select all
#!/bin/sh
names=$(echo "Bill,George,Jack,Joe")
occupation=$(echo "Doctor,Dentist,Butcher,Baker,Candlestick Maker,Other")
yad --title="Names" \
--form --separator="," --item-separator="," \
--field="Names:":CB \
--field="Occupation:":CBE \
--field="Comments:":TXT \
"$names" "$occupation" "Type your comments here"
echo
echo "(The selected name) (Selected occupation) (Comments)"
echo
echo
echo $name,$occupation,$comments
How do I assign variables so the last echo statement at the bottom of the script works?
Thanks
Posted: Sat 31 Jan 2015, 09:32
by rg66
Not quite sure what you're after but maybe you can use something from these scripts to get what you want.
Code: Select all
#!/bin/sh
names=$(echo "Bill,George,Jack,Joe")
occupation=$(echo "Doctor,Dentist,Butcher,Baker,Candlestick Maker,Other")
yad --title="Names" \
--form --separator="," --item-separator="," \
--field="Names:CB" \
--field="Occupation:CBE" \
--field="Comments:TXT" \
"$names" "$occupation" "Type your comments here" | while read line; do
NAME=`echo $line | awk -F',' '{print $1}'`
OCCUPATION=`echo $line | awk -F',' '{print $2}'`
COMMENT=`echo $line | awk -F',' '{print $3}'`
echo "(The selected name) (Selected occupation) (Comments)"
echo
echo
echo $NAME $OCCUPATION $COMMENT
done
Or
Code: Select all
#!/bin/sh
names=$(echo "Bill,George,Jack,Joe")
occupation=$(echo "Doctor,Dentist,Butcher,Baker,Candlestick Maker,Other")
yad --title="Names" \
--form --separator="," --item-separator="," \
--field="Names:CB" \
--field="Occupation:CBE" \
--field="Comments:TXT" \
"$names" "$occupation" "Type your comments here" > /tmp/config
NAME=`cat /tmp/config | awk -F',' '{print $1}'`
OCCUPATION=`cat /tmp/config | awk -F',' '{print $2}'`
COMMENT=`cat /tmp/config | awk -F',' '{print $3}'`
#echo $NAME $OCCUPATION $COMMENT #this would have to be run first to work properly with copy/paste into term, in a script it works ok
echo "(The selected name) (Selected occupation) (Comments)"
echo
echo
echo $NAME $OCCUPATION $COMMENT
Or
Code: Select all
#!/bin/sh
names=$(echo "Bill,George,Jack,Joe")
occupation=$(echo "Doctor,Dentist,Butcher,Baker,Candlestick Maker,Other")
yad --title="Names" \
--form --separator="," --item-separator="," \
--field="Names:CB" \
--field="Occupation:CBE" \
--field="Comments:TXT" \
"$names" "$occupation" "Type your comments here" | while read line; do
echo "NAME='`echo $line | awk -F',' '{print $1}'`'" > /tmp/config
echo "OCCUPATION='`echo $line | awk -F',' '{print $2}'`'" >> /tmp/config
echo "COMMENT='`echo $line | awk -F',' '{print $3}'`'" >> /tmp/config
done
Code: Select all
# other script
#!/bin/sh
. /tmp/config
echo "(The selected name) (Selected occupation) (Comments)"
echo
echo
echo $NAME $OCCUPATION $COMMENT
Posted: Sat 31 Jan 2015, 11:19
by smokey01
Thanks rg66.
Your first example does exactly what I want.
I will include all of your examples in my tutorial as they are all very useful.
I have already included the other tips you suggested earlier.
After a bit more editing I will release the next version.
It sure has been a challenge locating information on the usage of YAD.
I'm surprised more people haven't chimed in.
Thanks again.
Posted: Sat 31 Jan 2015, 12:13
by rg66
A few more tips:
When using --form and variables, you need a variable for each field
Code: Select all
VAR1="test1"
VAR2="test2"
yad --form --field=":CBE" --field=":CB" $VAR1 --field="Test:CBE" $VAR2
This will make the variables out of order, VAR1 will show up in the first box instead of the second.
Using double quotes "" will keep them in the right order if there is no variable for the first box
Code: Select all
VAR1="test1"
VAR2="test2"
yad --form --field=":CBE" "" --field=":CB" $VAR1 --field="Test:CBE" $VAR2
If you want an just an entrybox with no dropdown arrow just use a blank field
or with text
Posted: Tue 03 Feb 2015, 08:07
by smokey01
I have an interesting situation. The following gui with two --entry fields is what I want. The problem is, when data is entered into the Golflink field and the enter button is pressed, the gui closed before data can be entered into the Score/second field.
The tab key works fine but many people will automatically press enter which will mess up the data, creating multiple entries.
Is there a way to make the [enter] key behave like the [tab] key?
Also is it possible to make the gui and text larger with this gui?
Code: Select all
yad --title="Golf Club" --text="Please enter your details:" \
--form \
--field="Golflink Number" \
--field="Score" \
Posted: Tue 03 Feb 2015, 12:26
by Geoffrey
smokey01 wrote:Also is it possible to make the gui and text larger with this gui?
The text accepts markup the GUI height and width
Code: Select all
yad --title="Golf Club" --height=200 --width=400 --text="<span foreground='blue'><b><big><big>Please enter your details:</big></big></b></span>" \
--form \
--field="<b><big><big>Golflink Number</big></big></b>" \
--field="<b><big><big>Score</big></big></b>" \
Posted: Tue 03 Feb 2015, 12:58
by Geoffrey
A few more pango markup options for font size to make text larger,
Code: Select all
yad --title="Golf Club" --height=200 --width=400 \
--text="<span foreground='blue' font='48' font_style='italic' underline='single'><b>Please enter your details:</b></span>" \
--form \
--field="<b><big><big><big><big>Golflink Number</big></big></big></big></b>" \
--field="<b><big><big>Score</big></big></b>" \
Posted: Tue 03 Feb 2015, 16:30
by L18L
smokey01 wrote:The tab key works fine but many people will automatically press enter which will mess up the data, creating multiple entries.
Usually I would set score to -1 and loop untile greater than -1.
But - is buggy in yad.
You might like this, second dialog if score =0
Code: Select all
#!/bin/sh
data="$(yad --title="Golf Club" --text="Please enter your details:" \
--form --field="Golflink Number":NUM !1..23 \
--field="score":NUM !0..99 )"
link_number="`echo $data | cut -d'|' -f1`"
link_number="`echo $link_number | cut -d'.' -f1`"
link_number="`echo $link_number | cut -d',' -f1`"
score="`echo $data | cut -d'|' -f2`"
score="`echo $score | cut -d'.' -f1`"
score="`echo $score | cut -d',' -f1`"
if [ $score -eq 0 ]; then
score="$(yad --title="Golf Club" --text="Please enter your score for Number ${link_number}:" \
--button=OK --form --field="score":NUM !0..99 )"
score="`echo $score | cut -d'.' -f1`"
score="`echo $score | cut -d',' -f1`"
fi
echo data="link_number=${link_number}|score=${score}"
Adjust ranges for linknumber and scores
Posted: Sat 21 Mar 2015, 20:28
by kjdixo
Use YAD to implement an easy gui interface for 'Youtube Download'
http://rg3.github.io/youtube-dl/
youtube-dl is a small command-line program to download videos from YouTube.com and a few more sites
I installed the following in Quirky Puppy Tahr 6.05
1. youtube-dl
2. yad
The following code will trigger the youtube-dl program.
Code: Select all
#!/bin/bash
dialog=$(yad --title "You Tube Download" --form --field="Paste address")
address=$(echo $dialog)
youtube-dl "$address" | yad --title "Download" --progress --pulsate
I was 'inspired' by this blog post:
http://www.linux-magazine.com/Online/Bl ... s-with-YAD
I added a simple progress indicator that indicates whether the program is running or has completed,
Posted: Sat 21 Mar 2015, 23:48
by slavvo67
Does anyone have a simple script to choose a directory via pop-up box? I've been using Zenity but Slacko doesn't have that built in.
Posted: Sun 22 Mar 2015, 02:18
by B.K. Johnson
kjdixo wrote:
#!/bin/bash
dialog=$(yad --title "You Tube Download" --form --field="Paste address")
address=$(echo $dialog)
youtube-dl "$address" | yad --title "Download" --progress --pulsate
1. What is the default download directory?
2. Can it be changed/ If yes, how?
Posted: Sun 22 Mar 2015, 09:23
by kjdixo
Hi
B.K.Johnsohn wrote
1. What is the default download directory?
2. Can it be changed/ If yes, how?
As it stands my code downloads videos to the root folder.
To find out how to change that, we need to delve into the youtube-dl documentation
https://github.com/rg3/youtube-dl/blob/ ... fic-folder
FAQ
How do I put downloads into a specific folder?
Use the -o to specify an output template, for example -o "/home/user/videos/%(title)s-%(id)s.%(ext)s".
If you want this for all of your downloads, put the option into your configuration file.
https://github.com/rg3/youtube-dl/blob/ ... figuration
For our example:
Make sure you first create a Videos folder (that you can write to) in root
Code: Select all
#!/bin/bash
dialog=$(yad --title "You Tube Download" --form --field="Paste address")
address=$(echo $dialog)
youtube-dl "$address" -o "/root/Videos/%(title)s-%(id)s.%(ext)s" | yad --title "Download" --progress --pulsate
You can easily write extra YAD dialogs to control the parameters and download location.
Posted: Sun 22 Mar 2015, 10:19
by kjdixo
@ slavvo67
Does anyone have a simple script to choose a directory via pop-up box?
I've been using Zenity but Slacko doesn't have that built in.
see YAD manual 'form options'
http://rpm.pbone.net/index.php3/stat/45 ... /nazwa/yad
This method works
Code: Select all
#!/bin/bash
dialog=$(yad --title "Select Directory" --form --field=Choose:DIR)
echo $dialog
If you run in console mode it will echo the directory path.
Posted: Sun 22 Mar 2015, 15:43
by slavvo67
Thank you. I think all recent Puppies have YAD but not all have Zenity (i.e. Slacko), so it's time for me to switch my scripts that use Zenity over to YAD. However, your example adds "|" at the end of the directory, so if I try to cd to $directory1 or whatever variable I choose, it will not work as it will create $directory1 as /mnt/sda2/directoryname|
Instead, $directory1 should reflect: /mnt/sda2/directoryname
You still put me on the right track, with the following example from Smokey01 working:
cd /
directory1=$(yad --file --directory --width=600 --height=400)
cd $directory1
Thanks,
Slavvo67
Posted: Sun 22 Mar 2015, 19:01
by kjdixo
Thanks for your solution inspired by Smokey01
http://smokey01.com/help/yad-tips-0.0.1.ncd.tar.xz
I missed the "|" because I was in too much hurry to post an answer and did not see it..
Remove the "|" easily with this code.
Code: Select all
#!/bin/bash
dialog=$(yad --title "Select Directory" --form --field=Choose:DIR)
echo $dialog | awk 'BEGIN {FS="|" } { print $1 }'
Inspired by
http://www.linux-magazine.com/Online/Bl ... s-with-YAD
I recommend your dialog example slavvo67.
It is quicker and easier to use.
Posted: Sun 22 Mar 2015, 19:25
by mikeb
yad --file --directory --width=600 --height=400
ah neat...was looking for that some time ago
I must be testing an older yad..it wants --file-selection .....
great thread...
mike