YAD - Tips

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
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

YAD - Tips

#1 Post 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.

User avatar
rg66
Posts: 1158
Joined: Mon 23 Jul 2012, 05:53
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

#2 Post 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
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
[url=http://smokey01.com/rg66/]X-series repo[/url]

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#3 Post by smokey01 »

Thanks, added.

User avatar
rg66
Posts: 1158
Joined: Mon 23 Jul 2012, 05:53
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

#4 Post 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
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
[url=http://smokey01.com/rg66/]X-series repo[/url]

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#5 Post 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

User avatar
rg66
Posts: 1158
Joined: Mon 23 Jul 2012, 05:53
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

#6 Post 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
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
[url=http://smokey01.com/rg66/]X-series repo[/url]

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#7 Post 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.

User avatar
rg66
Posts: 1158
Joined: Mon 23 Jul 2012, 05:53
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

#8 Post 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

Code: Select all

yad --form --field=""
or with text

Code: Select all

yad --form --field="Test"
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
[url=http://smokey01.com/rg66/]X-series repo[/url]

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#9 Post 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" \

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#10 Post 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>" \
Attachments
Screenshot.png
(15.01 KiB) Downloaded 6781 times
Last edited by Geoffrey on Tue 03 Feb 2015, 13:00, edited 1 time in total.
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#11 Post 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>" \
Attachments
Screenshot2.png
(27.2 KiB) Downloaded 6817 times
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#12 Post 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 :wink:

kjdixo
Posts: 153
Joined: Sun 13 Sep 2009, 21:13

#13 Post 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,
Attachments
ytd-yad.jpg
(21.25 KiB) Downloaded 6665 times

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#14 Post 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.

B.K. Johnson
Posts: 807
Joined: Mon 12 Oct 2009, 17:11

#15 Post 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?

kjdixo
Posts: 153
Joined: Sun 13 Sep 2009, 21:13

#16 Post 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.

kjdixo
Posts: 153
Joined: Sun 13 Sep 2009, 21:13

#17 Post 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.
Attachments
dir1.jpg
(18.57 KiB) Downloaded 2653 times

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#18 Post 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

kjdixo
Posts: 153
Joined: Sun 13 Sep 2009, 21:13

#19 Post 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.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#20 Post 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

Post Reply