YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
kjdixo
Posts: 153
Joined: Sun 13 Sep 2009, 21:13

#31 Post by kjdixo »

Try this ... execute in console mode or copy and paste to a terminal to check the outputs

Code: Select all

yad --title="Test" --text="Test buttons" --form --field="1" --field="2" --field="3" --field="4" --button="gtk-ok:0" --button="gtk-cancel:1"

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

#32 Post by slavvo67 »

Seems to work but the true test will be in a program I'm writing. - Thanks.

Slavvo67

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

#33 Post by mikeb »

I applied that yad folder chooser to pburn and it works a treat because you can specify the start directory and can specify the size...gtkdialogs choosers tend to be large.

I yadded pburn last year for an excersise... was quite pleased with the result.

Don't ask...its not like the pburn you know and wait for to boot :D...I forked from version one to get on the fly audio burning.

Mike

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

#34 Post by slavvo67 »

The choose directory option seems to go through all the subs, as well. I found that a bit strange. For example, listing all pdf files after choosing a directory will list all the pdf's in all the subs, as well. Is it just a user issue again? LOL


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

#36 Post by slavvo67 »

What I was looking for in my above posts was a way to have the OK and Exit buttons actually work in a script. So for those non-pro's like myself, here's a partial to show how I did it.

choice2=$(yad --title='Title1' --text='Travel Items' --form --field='Show:CB' '1.Airline Tickets!2.Cars' --button="Exit:1" --button="OK:0")
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0 # This exits if you hit the exit instead of OK button.
fi
numb777=${choice2:0:2}
# The above takes the first 2 characters like # 1. and allows it to # be a choice in an if .. then statement.
# For example...
if [ $numb777 = '1.' ]
then
echo "Perhaps you should go to Priceline.com"
fi

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

#37 Post by kjdixo »

Thanks.
An excellent example.

It is frustrating and time consuming when there are not many examples available.
Your snippet will be very useful.

Here is YAD being used to selectively display language verb tables in an openbox menu.
This method could be used to display any images.
Clicking on a menu item opens the required image in a yad window.
Verb tables are complex and often need to be referred to.
Open and close and compare any number of images. It is nice and fast.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="http://openbox.org/3.4/menu">
<menu id="root-menu" label="MENU 5">
<item label="" icon="/usr/share/icons/Tango/32x32/actions/go-home.png"><action name="Execute"><command>sh -c "cp /root/.config/openbox/menu1.xml /root/.config/openbox/menu.xml && openbox --reconfigure;xdotool mousemove_relative --polar 280 80; xdotool click 3;xdotool mousemove_relative  --polar 100 80"</command></action></item>
<item label="XFE" icon="/usr/share/icons/Tango/32x32/apps/file-manager.png"><action name="Execute"><command>xfe</command></action></item>
<item label="dar" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=dar__to-give --image /root/Verbs/ar/dar__to-give.png</command></action></item>
<item label="deitar" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=deitar__to-lay_to-put-(down)_to-put-to-bed_to-throw --image /root/Verbs/ar/deitar__to-lay_to-put-(down)_to-put-to-bed_to-throw.png</command></action></item>
<item label="deixar" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=deixar__to-let_allow_to-leave-(behind) --image /root/Verbs/ar/deixar__to-let_allow_to-leave-(behind).png</command></action></item>
<item label="dizer" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=dizer__to-say_tell --image /root/Verbs/er/dizer__to-say_tell.png</command></action></item>
<item label="estar" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=estar__to-be_temporary --image /root/Verbs/ar/estar__to-be_temporary.png</command></action></item>
<item label="falar" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=falar__to-speak --image /root/Verbs/ar/falar__to-speak.png</command></action></item>
<item label="haver" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=haver__to-be_impersonal__to-have_auxilliary --image /root/Verbs/er/haver__to-be_impersonal__to-have_auxilliary.png</command></action></item>
<item label="ir" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=ir__to-go --image /root/Verbs/ir/ir__to-go.png</command></action></item>
<item label="pedir" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=pedir__to-ask-for_to-beg --image /root/Verbs/ir/pedir__to-ask-for_to-beg.png</command></action></item>
<item label="poder" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=poder__to-be-able_can --image /root/Verbs/er/poder__to-be-able_can.png</command></action></item>
<item label="ser" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=ser__to-be_permanent --image /root/Verbs/er/ser__to-be_permanent.png</command></action></item>
<item label="ter" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=ter__to-have --image /root/Verbs/er/ter__to-have.png</command></action></item>
<item label="trazer" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=trazer__to-bring --image /root/Verbs/er/trazer__to-bring.png</command></action></item>
<item label="ver" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=ver__to-see --image /root/Verbs/er/ver__to-see.png</command></action></item>
<item label="vestir" icon="/root/.portugal.png"><action name="Execute"><command>yad --button='gtk-quit:1' --title=vestir__to-dress_wear_put-on --image /root/Verbs/ir/vestir__to-dress_wear_put-on.png</command></action></item>
</menu>
</openbox_menu>
The 'right click multiple menu' is described fully on the lxde forum . . .
xdotool is not an essential requirement, it only enhances operation of the menu.
http://forum.lxde.org/viewtopic.php?f=24&t=31525
Attachments
yad-obmenu.png
(52.48 KiB) Downloaded 1989 times

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

#38 Post by slavvo67 »

Hi kjdixo:

I was just starting to explore the icons so thank you for that. It looks like a lot of work / writing, though. That is the issue with adding a graphic interface, I guess. I'll let you know if I find any shortcuts.

Best,

Slavvo67

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

#39 Post by kjdixo »

Really happy ... got the above 'yad openbox right-click menu - verb tables' and my earlier post's 'Language Learning - Audio Flashcards with YAD' all working on an old ASUS EeePC 2G Surf (the first model with 2GB storage).
I began by installing LXPUP 14:10 and then installed xfe (removed rox and pcmanfm) and did many more minimalist tweaks (installed earlier pmount - from quirky tahr 6.05 and tweaked pmount code to replace 'rox' with 'xfe').
I have left lxde installed for experimentation purposes and I run an openbox session (with feh [wallpaper] and stalonetray) - my choice.
So now I have a very portable, highly configurable 'language laboratory'.
The eeepc has a small screen with speakers placed either side of the screen.
I tweaked xrandr to give me 2000px x 2000px panning mode, so the small screen is not so much of a problem.
Yad is great for speed and minimalism because it will display images and ... play audio (using mpg123) without the need for big programs that take 'vital and agonising milliseconds' to startup.

@slavvo67 "It looks like a lot of work / writing, though"
10% inspiration 90% perspiration . . . as the saying goes.

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

#40 Post by kjdixo »

Very slightly different from previous combo box examples

Code: Select all

#! /bin/bash
title=$(echo "Select")

combo()
{  
choice=$(yad --title="$title" --text='Travel Items' --form --field='Show:CB' '1.Airline Tickets!2.Cars' --button="Exit:1" --button="OK:0")

ret=$?
if [[ $ret -ge 1 ]]; then
exit 0
fi

choice=$(echo $choice | awk 'BEGIN {FS="|" }{print $1}')
echo $choice
title=$(echo "$choice")
}

while true ; do
combo
done

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

#41 Post by kjdixo »

Combo box retains selection

Code: Select all

#! /bin/bash
title=$(echo "Select")
item='1.Airline Tickets!2.Cars!3.Folding Bike!4.Linux Netbook!5.Lightweight Clothes'

combo()
{ 	
choice=$(yad --title="$title" --text='Travel Items' --form --field='Show:CB' "$item" --button="Exit:1" --button="OK:0")

ret=$?
if [[ $ret -ge 1 ]]; then
exit 0
fi

choice=$(echo $choice | awk 'BEGIN {FS="|" }{print $1}')
echo $item
echo $choice
title=$(echo "$choice")
item=$(echo $item | sed "s/$choice"!"//g" | sed "s/"!"$choice//g")
echo $item
item=$choice"!"$item
}

while true ; do
combo
done 

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

#42 Post by slavvo67 »

Probably a pretty easy question but how to I have the fsck command run in an open terminal from this script? I can't just pass fsck to YAD because fsck requires possible interaction via terminal.

#!/bin/bash

cd /
choice2=$(yad --title='Drives' --text='Choose Drive Prefix for Possible Defrag' --form --field='Show:CB' '0.Exit!1. SDA!2. SDB!3. SDC!4. SDD!5. SDE!6. SDF!7. SDG!8. SDH' --button="Exit:1" --button="OK:0")
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
numb666=${choice2:0:2}
if [[ $numb666 = "1." ]]
then
name1="/dev/sda"
elif [[ $numb666 = "2." ]]
then
name1="/dev/sdb"
elif [[ $numb666 = "3." ]]
then
name1="/dev/sdc"
elif [[ $numb666 = "4." ]]
then
name1="/dev/sdd"
elif [[ $numb666 = "5." ]]
then
name1="/dev/sde"
elif [[ $numb666 = "6." ]]
then
name1="/dev/sdf"
elif [[ $numb666 = "7." ]]
then
name1="/dev/sdg"
elif [[ $numb666 = "8." ]]
then
name1="/dev/sdh"
fi
parted $name1 'print'|yad --geometry=900x600 --list --title "Drive Results" --text "Listing Drive Types.." --column "Types" --button="Exit:1" --button="OK:0"
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
yad --text="Choose a the name of a file to obtain the most recent version:" --button="Exit:1" --button="OK:0"
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
search555=$(yad --entry --entry-label="Drive to Defrag Enter as sda2" --button="Exit:1" --button="OK:0")
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
cd /
###########################
fsck "/dev/$search555" -f
###########################

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

#43 Post by mikeb »

The -y parameter might help just not sure if it works for all formats...answers yes to all questions.
or the -p = no questions.

mike

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

#44 Post by slavvo67 »

Hi Mikeb:

I didn't get it at first but the -y did indeed fix the issue.

Good to hear from ya,

Slavvo67

FIXED

#!/bin/bash


# Just a little GUI to defrag partitions -Slavvo67
# Needs YAD and fsck
# fsck takes a while on USB's so wait a bit longer for those.
cd /
choice2=$(yad --title='Drives' --text='Choose Drive Prefix for Possible Defrag' --form --field='Show:CB' '0. Exit!1. SDA!2. SDB!3. SDC!4. SDD!5. SDE!6. SDF!7. SDG!8. SDH' --button="Exit:1" --button="OK:0")
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
numb666=${choice2:0:2}
if [[ $numb666 = "1." ]]
then
name1="/dev/sda"
elif [[ $numb666 = "2." ]]
then
name1="/dev/sdb"
elif [[ $numb666 = "3." ]]
then
name1="/dev/sdc"
elif [[ $numb666 = "4." ]]
then
name1="/dev/sdd"
elif [[ $numb666 = "5." ]]
then
name1="/dev/sde"
elif [[ $numb666 = "6." ]]
then
name1="/dev/sdf"
elif [[ $numb666 = "7." ]]
then
name1="/dev/sdg"
elif [[ $numb666 = "8." ]]
then
name1="/dev/sdh"
fi
parted $name1 'print'|yad --geometry=900x600 --list --title "Drive Results" --text "Listing Drive Types.." --column "Types" --button="Exit:1" --button="OK:0"
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
search555=$(yad --entry --entry-label="Drive to Defrag Enter as sda2" --button="Exit:1" --button="OK:0")
ret=$?
if [[ $ret -eq 1 ]]; then
exit 0
fi
cd /
fsck "/dev/$search555" -fy | yad --geometry=900x600 --list --title "Defragging" --text "/dev/$search555" --column "Working..." --button="Exit:1" --button="OK:0"

stemsee

thumbnails

#45 Post by stemsee »

How to get yad to display a list of thumbnails from backgrounds directory. I know the --image switch to display one full sized image, but that's all.

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

#46 Post by Geoffrey »

The only way I know of displaying an image from a list, is in a file selector with a preview

Code: Select all

yad --file-selection --add-preview
Attachments
yad-preview.png
(108.24 KiB) Downloaded 1651 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
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#47 Post by mikeb »

Hmm could the icons box be used in some way...might be messy though as its intended as a launcher dialog for desktop files...

yad --help-icons

mike

stemsee

#48 Post by stemsee »

Thanks Geoffrey

That is better than what I have now.

stemsee

#49 Post by stemsee »

In fact I am getting thumbnails in yad and preview.

Code: Select all

wp=`yad --title "Select Wallpapers" --geometry=400x500 --file-selection --multiple --add-preview` 
Attachments
capture30443.jpg
(46.79 KiB) Downloaded 1519 times
capture32134.jpg
(40.12 KiB) Downloaded 1517 times

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

#50 Post by Geoffrey »

stemsee wrote:In fact I am getting thumbnails in yad and preview.
Yeah, me too now, the thumbnailer was a little slow creating them.
[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]

Post Reply