Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 Aug 2017, 12:04
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 22 [321 Posts]   Goto page: Previous 1, 2, 3, 4, ..., 20, 21, 22 Next
Author Message
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Sun 22 Mar 2015, 05:23    Post subject:  

Hi
B.K.Johnsohn wrote
Quote:

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/master/README.md#how-do-i-put-downloads-into-a-specific-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/master/README.md#configuration

For our example:
Make sure you first create a Videos folder (that you can write to) in root
Code:

#!/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.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Sun 22 Mar 2015, 06:19    Post subject:  

@ slavvo67
Quote:

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/idpl/20231177/numer/1/nazwa/yad

This method works
Code:

#!/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.
dir1.jpg
 Description   
 Filesize   18.57 KB
 Viewed   1329 Time(s)

dir1.jpg

Back to top
View user's profile Send private message 
slavvo67

Joined: 12 Oct 2012
Posts: 1421
Location: The other Mr. 305

PostPosted: Sun 22 Mar 2015, 11:43    Post subject:  

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
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Sun 22 Mar 2015, 15:01    Post subject:  

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:

#!/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/Blogs/Productivity-Sauce/Dress-Up-Bash-Scripts-with-YAD
I recommend your dialog example slavvo67.
It is quicker and easier to use.
Back to top
View user's profile Send private message 
mikeb


Joined: 23 Nov 2006
Posts: 11071

PostPosted: Sun 22 Mar 2015, 15:25    Post subject:  

Quote:
yad --file --directory --width=600 --height=400


ah neat...was looking for that some time ago Smile

I must be testing an older yad..it wants --file-selection .....

great thread... Smile

mike
Back to top
View user's profile Send private message 
slavvo67

Joined: 12 Oct 2012
Posts: 1421
Location: The other Mr. 305

PostPosted: Sun 22 Mar 2015, 15:47    Post subject:  

I just started using YAD, too. Here's one to choose an individual file.

filechoice1=$(yad --geometry700x400 --file --filename --width=600)
Back to top
View user's profile Send private message 
mikeb


Joined: 23 Nov 2006
Posts: 11071

PostPosted: Sun 22 Mar 2015, 16:15    Post subject:  

--file-filter="Pburn Files|*.pba *.pbn" --filename="/path/"

shows only certain file types and starts in the /path directory...really handy

mike
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Mon 23 Mar 2015, 17:14    Post subject:  

Screenshots as bookmarks
Use YAD to implement an easy gui interface for 'CutyCapt'

http://cutycapt.sourceforge.net/

CutyCapt is a small cross-platform command-line utility to capture WebKit's rendering of a web page into a variety of vector and bitmap formats, including SVG, PDF, PS, PNG, JPEG, TIFF, GIF, and BMP.

I installed the following in Quirky Puppy Tahr 6.05
1. cutycapt
2. yad
Created a Pictures folder (writeable to) in root.
The following code will trigger the cutycapt program.
Code:

#!/bin/bash

dialog=$(yad --title "Cuty Capt" --form --field="Paste address" --field="Title")
address=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
title=$(echo $dialog | awk 'BEGIN {FS="|" }{print $2}')
domain=$(echo $address | sed 's/www.//g' | awk 'BEGIN {FS="://" }{print $2}' | awk 'BEGIN {FS="." }{print $1}')

echo $address
echo $domain
echo $title
cutycapt --url="$address" --max-wait=5000 --out=/root/Pictures/"$domain"-"$title".png


Paste a web page url (not https - it does not seem to work in cutycapt) into the first field.
Write some memory jogger text into the second field (like a bookmark title).
Hit ok or enter and wait 5 seconds for a screenshot to appear in the Pictures folder.
It will be named [domain]-[title].png where domain is the part of the url between '://' and the first '.'
Running in console mode for the first few times echos the variables and helps you see what is happening.
cc.jpg
 Description   
 Filesize   17.8 KB
 Viewed   1255 Time(s)

cc.jpg

Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Mon 23 Mar 2015, 20:08    Post subject:  

Some additions to the previous bit of code.
1. The web page capture .png gets written to the Pictures folder then it is displayed in a YAD window, with its filename as the window title.
2. Images in the Pictures folder are time-stamped for chronological listing.
Code:

#!/bin/bash

dialog=$(yad --title "Cuty Capt" --form --field="Paste address" --field="Title")
address=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
title=$(echo $dialog | awk 'BEGIN {FS="|" }{print $2}')
domain=$(echo $address | sed 's/www.//g' | awk 'BEGIN {FS="://" }{print $2}' | awk 'BEGIN {FS="." }{print $1}')
timestamp() {
date +"%Y-%m-%d_%H:%M:%S"
}
time=$(echo $(timestamp))
echo $address
echo $domain
echo $time
echo $title
cutycapt --url="$address" --max-wait=5000 --out=/root/Pictures/"$time"-"$domain"-"$title".png

yad --image /root/Pictures/"$time"-"$domain"-"$title".png --title /root/Pictures/"$time"-"$domain"-"$title".png

Note that sed is used to remove 'www.'
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Tue 24 Mar 2015, 04:03    Post subject:  

PDF format is better for saving large web page screen-shots.
Very often web pages are very long and the .png file will be thousands of pixels in height (file size very large).
I have found that using cutycapt to save as .pdf is much better when working with large web pages.
The pdf format chops the screen-shot into page sized chunks and the pdf viewer (Evince) displays a list of thumbnails on one side.
Code:

#!/bin/bash

dialog=$(yad --title "Cuty Capt" --form --field="Paste address" --field="Title")
address=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
title=$(echo $dialog | awk 'BEGIN {FS="|" }{print $2}')
domain=$(echo $address | sed 's/www.//g' | awk 'BEGIN {FS="://" }{print $2}' | awk 'BEGIN {FS="." }{print $1}')
timestamp() {
date +"%Y-%m-%d_%H:%M:%S"
}
time=$(echo $(timestamp))
echo $address
echo $domain
echo $time
echo $title
cutycapt --url="$address" --max-wait=5000 --out=/root/Pictures/"$time"-"$domain"-"$title".pdf

Saving as .pdf is very quick, stable and more user friendly than .png
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Thu 26 Mar 2015, 09:15    Post subject:  

So far we have a PDF static copy of a web address, timestamped and with a descriptive filename.
Saving a web page as a pdf, alows direct copy and paste of text, not so easy with a png file.
It would also be useful to include somewhere in our saved static pdf copy of the web page, the url of the particular website and make it copyable and pasteable into a browser address bar if required.
(I am using Quirky Puppy Tahr 6.05)
1. Install pdftk
2. Replace previous bash script with this:
Code:

#!/bin/bash

dialog=$(yad --title "Cuty Capt" --form --field="Paste address" --field="Title")
address=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
title=$(echo $dialog | awk 'BEGIN {FS="|" }{print $2}')
domain=$(echo $address | sed 's/www.//g' | awk 'BEGIN {FS="://" }{print $2}' | awk 'BEGIN {FS="." }{print $1}')
timestamp() {
date +"%Y-%m-%d_%H:%M:%S"
}
time=$(echo $(timestamp))
echo $address
echo $domain
echo $time
echo $title
cutycapt --url="$address" --max-wait=5000 --out=/root/Pictures/temp.pdf
pdftk /root/Pictures/temp.pdf dump_data > /root/Pictures/in.txt
cd /root/Pictures
sed -i '1i InfoValue: '$address'' in.txt
sed -i '1i InfoKey: Title' in.txt
sed -i '1i InfoBegin' in.txt
pdftk /root/Pictures/temp.pdf update_info in.txt output /root/Pictures/"$time"-"$domain"-"$title".pdf

Summary
cutycapt saves the web page to a temporary temp.pdf for pdftk to work with.
cutycapt saves the pdf metadata but does not include the metadata 'InfoKey: Title'.

pdftk gets a metadata dump_data and saves it to in.txt.
sed prepends 'InfoKey: Title' to in.txt.
pdftk does an update_info, using in.txt, to the output timestamped pdf file.

Now in evince the website url appears as the window title.
In evince click > file > properties and see that the website url is listed next to Title:
The evince properties dialog contents are copyable and pasteable, so you can grab the url.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Thu 26 Mar 2015, 17:01    Post subject:  

This might be a useful alternative to the simpler 'yad --color' dialog.
Code:

#!/bin/bash
dialog=$(yad --title "Select Colors" --form --field=Color1:CLR --field=Color2:CLR)
color1=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
color2=$(echo $dialog | awk 'BEGIN {FS="|" }{print $2}')

red1=${color1:1:2}
green1=${color1:5:2}
blue1=${color1:9:2}
color1="#"$red1$green1$blue1

red2=${color2:1:2}
green2=${color2:5:2}
blue2=${color2:9:2}
color2="#"$red2$green2$blue2
echo $color1
echo $color2

The returned variables on lines 3 and 4, $color1 and $color2 are 12 character strings preceded by a #.
I needed to extract from the 12 character string
red (1st and 2nd characters)
green (5th and 6th characters)
blue (9th and 10th characters)
and then remake the strings (concatenate the variables $red, $green, $blue) and prepend a #.
Run in console mode the first few times to observe the outputs $color1 and $color2.
colors.jpg
 Description   
 Filesize   18.86 KB
 Viewed   1128 Time(s)

colors.jpg

Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Mon 30 Mar 2015, 16:54    Post subject:  

Language Learning - Audio Flashcards with YAD
Demonstrates use of combo-box and mp3 audio files.

http://mpg123.de/

mpg123 is a real time MPEG 1.0/2.0/2.5 audio player/decoder for layers 1,2 and 3 (most commonly MPEG 1.0 layer 3 aka MP3).

I installed the following in Quirky Puppy Tahr 6.05
1. mpg123
2. yad

Created an Audio folder (writeable to) in root.
Saved 1.mp3 to 8.mp3 (weather audio files) and weather.txt in /root/Audio/weather/
Saved 1.mp3 to 8.mp3 (colors audio files) and colors.txt in /root/Audio/colors/

The following code will trigger mpg123.
It uses mpg123-alsa (automatically installed in 1. above).
Code:

#!/bin/sh
# language text files stored with corresponding single word audio files

# save 1.mp3 to 8.mp3 (weather audio files) and weather.txt in /root/Audio/weather/
# save 1.mp3 to 8.mp3 (colors audio files) and colors.txt in /root/Audio/colors/

dialog=$(yad --width=400 --title="category" --form --field="":CB 'weather!colors' --button=gtk-ok:0)
category=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
echo $category

#Load weather.txt or colors.txt file lines into a bash array

OLD_IFS=$IFS
IFS=$'\n'
let line_counter=0
for line in $(cat "/root/Audio/$category/$category.txt"); do
let line_counter=$(($line_counter+1))

portuguese=$(echo $line | awk 'BEGIN {FS="<pt>" }{print $2}' | awk 'BEGIN {FS="<en>" }{print $1}')
english=$(echo $line | awk 'BEGIN {FS="<en>" }{print $2}' | awk 'BEGIN {FS="<st>" }{print $1}')

echo $category" "$portuguese" "$english
dialog=$(yad --button=LISTEN:0 --title $category --width=300 --text " "$portuguese"  "$english" ")

mpg123-alsa /root/Audio/$category/$line_counter".mp3"

done
IFS=$OLD_IFS

weather.txt
Code:

<pt>ventoso<en>windy<st>
<pt>quente<en>warm<st>
<pt>ensolarado<en>sunny<st>
<pt>nevando<en>snowy<st>
<pt>chuvoso<en>rainy<st>
<pt>quente<en>hot<st>
<pt>frio<en>cold<st>
<pt>nublado<en>cloudy<st>

colors.txt
Code:

<pt>preto<en>black<st>
<pt>azul<en>blue<st>
<pt>castanho<en>brown<st>
<pt>verde<en>green<st>
<pt>cinzento<en>grey<st>
<pt>vermelho<en>red<st>
<pt>branco<en>white<st>
<pt>amarelo<en>yellow<st>


I hope this is self-explanatory.
category.jpg
 Description   
 Filesize   15.78 KB
 Viewed   1072 Time(s)

category.jpg

weather.jpg
 Description   
 Filesize   12.38 KB
 Viewed   1071 Time(s)

weather.jpg

Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 159

PostPosted: Tue 31 Mar 2015, 16:48    Post subject:  

Automatically picks up folder names from Audio directory and then loads them to the combo box.
Folders of txt files and corresponding mp3 files can be added without modifying YAD combo box code.
Folder names must be single words without spaces (we can complicate it with spaces another time).

Code:

#!/bin/sh
# language text files stored with corresponding single word audio files

# for example
# save 1.mp3 to 8.mp3 (weather audio files) and weather.txt in /root/Audio/weather/
# save 1.mp3 to 8.mp3 (colors audio files) and colors.txt in /root/Audio/colors/

cd /root/Audio
combo=$(for f in *; do [ -d "$f" ] && echo $f; done)
combo=$(echo $combo | sed 's/ /!/g')

echo $combo

dialog=$(yad --width=400 --title="category" --form --field="":CB $combo --button=gtk-ok:0)
category=$(echo $dialog | awk 'BEGIN {FS="|" }{print $1}')
echo $category

#Load weather.txt or colors.txt file lines into a bash array

OLD_IFS=$IFS
IFS=$'\n'
let line_counter=0
for line in $(cat "/root/Audio/$category/$category.txt"); do
let line_counter=$(($line_counter+1))

portuguese=$(echo $line | awk 'BEGIN {FS="<pt>" }{print $2}' | awk 'BEGIN {FS="<en>" }{print $1}')
english=$(echo $line | awk 'BEGIN {FS="<en>" }{print $2}' | awk 'BEGIN {FS="<st>" }{print $1}')

echo $category" "$portuguese" "$english
dialog=$(yad --button=LISTEN:0 --title $category --width=300 --text " "$portuguese"  "$english" ")

mpg123-alsa /root/Audio/$category/$line_counter".mp3"

done
IFS=$OLD_IFS

Last edited by kjdixo on Tue 31 Mar 2015, 17:43; edited 1 time in total
Back to top
View user's profile Send private message 
slavvo67

Joined: 12 Oct 2012
Posts: 1421
Location: The other Mr. 305

PostPosted: Tue 31 Mar 2015, 17:40    Post subject:  

Does anyone know how to get the standard ok and cancel buttons to work properly? I currently coded a zero in the pull down box instead, to cancel. Not a good way home....
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 22 [321 Posts]   Goto page: Previous 1, 2, 3, 4, ..., 20, 21, 22 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1407s ][ Queries: 14 (0.0069s) ][ GZIP on ]