YAD - Tips
Multiple yad --entry write to separate files
Is it possible for yad --entry to have several entry boxes in same window and then write each entry box input to a separate file ?
Code: Select all
dock1_name=$(yad --entry --title="Change Dock1 Window Name" --text="Enter New Dock1 name") && echo $dock1_name > /home/bobby/yadbash/beta/code/dock1name.file
Code: Select all
cd /home/bobby/yadbash/beta/code
dock1_name=$(head -n 1 dock1name.file)
yad --icons --read-dir=/usr/share/applications --monitor --single-click --item-width=70 --sort-by-name\
--geometry="1244x153+1+592" --on-top --vscroll-policy=auto --undecorated \
--title="YadBash Simple Coding" --text="$dock1_name" --window-icon=/usr/share/icons/sparky/about/sparky48.png \
--no-buttons --skip-taskbar
- misko_2083
- Posts: 114
- Joined: Tue 08 Nov 2016, 13:42
Re: Multiple yad --entry write to separate files
Well you can use the arraylamplinux wrote:Is it possible for yad --entry to have several entry boxes in same window and then write each entry box input to a separate file ?
Code: Select all
dock1_name=$(yad --entry --title="Change Dock1 Window Name" --text="Enter New Dock1 name") && echo $dock1_name > /home/bobby/yadbash/beta/code/dock1name.file
Code: Select all
cd /home/bobby/yadbash/beta/code dock1_name=$(head -n 1 dock1name.file) yad --icons --read-dir=/usr/share/applications --monitor --single-click --item-width=70 --sort-by-name\ --geometry="1244x153+1+592" --on-top --vscroll-policy=auto --undecorated \ --title="YadBash Simple Coding" --text="$dock1_name" --window-icon=/usr/share/icons/sparky/about/sparky48.png \ --no-buttons --skip-taskbar
The trick is to use the quoted output and remove it later with xargs.
Also the internal field separator must be set for the array.
In this case newline character.
Code: Select all
#!/bin/bash
# backup IFS
OIFS=$IFS
# set IFS to newline char
IFS=$'\n'
res=($(yad --form --quoted-output --separator="\n" \
--field=1 --field=2 \
--field=3 --field=4 \
--field=5))
# get exit status
out=$?
# Restore IFS
IFS=$OIFS
# OK (0), canceled (1) or closed dialog (252)
[ $out -ne 0 ] && exit 1
# for looping trough array
for i in {0..4}; do
# write each element 0-4 into field-1 to field-5
# xargs removes outer quotes
echo "${res[$i]}" | xargs > /tmp/field-$((i+1))
done
--form multiple records written to many files.
@misko, That works great - as always. Thank You !!!!
May I ask for another option to your array output ? Then I'll be able to output and read all night long.
Can the output of the array be written to the same line number of each of the "field-$" files ?
For example, Form data output is written to line 3 of each "field-$" file. So, not to over write the file, just update Line 3 of each file. I hope I'm asking this well enough.
I'm trying to use sed to accomplish this with your array but, don't fully understand what I m doing (learning though).
Bobby's attempt:
May I ask for another option to your array output ? Then I'll be able to output and read all night long.
Can the output of the array be written to the same line number of each of the "field-$" files ?
For example, Form data output is written to line 3 of each "field-$" file. So, not to over write the file, just update Line 3 of each file. I hope I'm asking this well enough.
I'm trying to use sed to accomplish this with your array but, don't fully understand what I m doing (learning though).
Bobby's attempt:
Code: Select all
# Using sed to update file - line 3 looping trough array
for i in {0..4}; do
sed '3 c\ > echo "${res[$i]}"' | xargs > /tmp/field-$((i+1))
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Instead of
try
Code: Select all
echo "${res[$i]}" | xargs > /tmp/field-$((i+1))
This assumes that the target file has a line 3, which sed will then replace with the field content.new=$(echo "${res[$i]}" | xargs)
sed -i "3s/.*/$new/" /tmp/field-$((i+1))
This assumes that the target file has a line 3, which sed will then replace with the field content.[/quote]new=$(echo "${res[$i]}" | xargs)
sed -i "3s/.*/$new/" /tmp/field-$((i+1))
I tried code as written but, no file writing. 5 files with words on lines 1 through 4.
I will see if I can make some (roll of the dice mod" to your code and see what I get as output.
I appreciate your help as it gets me to research what the code is doing and learn from that.
- misko_2083
- Posts: 114
- Joined: Tue 08 Nov 2016, 13:42
Bobby, Mochi's line should work, unless you are entering special characters in yad fields that mess up regular expressions or delimiter with sed later.
So you will want to escape them first.
So you will want to escape them first.
Code: Select all
for i in {0..4}; do
new="$(echo "${res[$i]}" | xargs -I {} echo "{}" | sed -e 's/[]\/&$*.^[]/\\&/g')"
sed -i "3s/.*/$new/" /tmp/field-$((i+1))
done
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
- removed -
(was not directly related to lamplinux's issue)
(was not directly related to lamplinux's issue)
Last edited by MochiMoppel on Sat 09 Feb 2019, 14:22, edited 1 time in total.
My Life is now complete. Thank You :)
@MochiMoppel @misko, I had to remove the backslashs between --field-1, --filed-2, etc. to get it to work. But, Dang it !!!! IT NOW WORKS !!! Whoo Whoo , Thank You Both !!!!!!!!!!!
Now its time to take over the world (or maybe not) but, lots of hours of fun time creating all kinds of fully user customizable Yad powered Launching and Bash Command solutions.
Have a Great Weekend ! I am very Happy !! All Thanks to you both. Cheers !!!!!!
Now its time to take over the world (or maybe not) but, lots of hours of fun time creating all kinds of fully user customizable Yad powered Launching and Bash Command solutions.
Have a Great Weekend ! I am very Happy !! All Thanks to you both. Cheers !!!!!!
Focus - Automatic each --form --field user entry box
I discovered that I can read current data to each field to a form entry box but, if user does not change the data, it is written back to the file as - blank space.
But, if I click in each field entry box, the read data then becomes an entry and saved properly back to same file.
?? Is there a way in Yad (or bash) to emulate a user clicking a box "like auto focus" for all --field boxes in a script - automatically ?
But, if I click in each field entry box, the read data then becomes an entry and saved properly back to same file.
?? Is there a way in Yad (or bash) to emulate a user clicking a box "like auto focus" for all --field boxes in a script - automatically ?
Last edited by lamplinux on Wed 13 Feb 2019, 06:37, edited 1 time in total.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
???
Please give a small example.
In principle it should work, but that depends very much on your code.
At least this should work:
Please give a small example.
In principle it should work, but that depends very much on your code.
At least this should work:
Code: Select all
#!/bin/bash
echo 'apple pie
banana cake
peach ice' > /tmp/testo
res=$(yad --form --separator="\n" --field=1 --field=2 --field=3 --button="Save & Exit:0" --button=Cancel:1 < /tmp/testo)
(($?)) && exit #exit here if exit status of yad > 0 (Save&Exit button was not pressed)
echo "$res" > /tmp/testo #write back to file
Got my example code to work
@MochiMoppel, Thank You but, I got the below script to work. Its mainly from code you guys provided. (without it, I'd never have anything working ) But, I'm loving it ! Things are working and I'm learning too.
Now, to do this yad --dialog-separator --form --icon-read --notepad all in one window...
Since the input should be a numerical only, do I use the NUM for fields in below script ?
I also would like to have all four numbers currently saved in file, to display RO in 4 other form boxes but, I'll get that sure enough (I know I can . Would I do that in a --pane window ?
Now, to do this yad --dialog-separator --form --icon-read --notepad all in one window...
Since the input should be a numerical only, do I use the NUM for fields in below script ?
I also would like to have all four numbers currently saved in file, to display RO in 4 other form boxes but, I'll get that sure enough (I know I can . Would I do that in a --pane window ?
Code: Select all
#!/bin/bash
# backup IFS
OIFS=$IFS
configDir=/home/bobby/yadbash/sparkypad/config
# set IFS to newline char
IFS=$'\n'
posFile=$configDir/docks/dock-size-position/dock-size-pos
sizPosDir=$configDir/docks/dock-size-position
wideDocks=$(sed -n 1p < $sizPosDir/dock-size-pos)
hiDocks=$(sed -n 2p < $sizPosDir/dock-size-pos)
posxDocks=$(sed -n 3p < $sizPosDir/dock-size-pos)
posyDocks=$(sed -n 4p < $sizPosDir/dock-size-pos)
yad --form --separator="\n" --field="Width" "$wideDocks" --field="Height" "$hiDocks" --field="From Left" "$posxDocks" --field="From Top" "$posyDocks" --window-icon="start-here" --center --title="Dock Window Sizing" --button="Cancel":0 --button="Save":0 > $posFile
# get exit status
out=$?
# Restore IFS
IFS=$OIFS
# 0K (0), canceled (1) or closed dialog (252)
[ $out -ne 0 ] && exit 0
Switching out directory of --icons --read-dir
Is it possible using a While True or case event to swap out the icon directory in a yad window and have it automatically updated it because it uses --monitor ?
Update: I could use a default directory and copy icons to and from the default directory each time a button is clicked. (Non Programmer way)
Code: Select all
yad --dialog-sep --image="my-image.png" --width="700" --height="400" --center --window-icon=$HOME/icons/window-icon.png --icons --read-dir=$HOME/ions/dock/config --monitor --single-click --item-width=70 --sort-by-name --title="Config Utility" --text="Please Make Your Selection\n" --button="Config" --button="Bookmarks" --button="Music" --button="Images" --button="Videos" --button="Exit":1
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Re: Got my example code to work
It works? Your Cancel button does not work as it should (you assigned it the same 0 exit code as the Save button) and since you immediately redirect the yad output to $posFile without checking the exit code you will end up with an empty $posFile if you close the dialog with Alt+F4 or with the window's x button.lamplinux wrote:@MochiMoppel, Thank You but, I got the below script to work
lamplinux, I can't see what you are asking for as you already answered some of your questions yourself.
In any case I'm a bit busy now but I'm sure some of our yad experts can help you much better than I can.
Using images with --button=
Just mentioning this because I happened upon it by accident hacking yad code
Example output:
Code: Select all
export imageDir=/home/user/images
go_imagebutton() {
cd $HOME/bobby
ls -l
}
export -f go_imagebutton
--button="!$imageDir/bobby.png!Bobby Button":"bash -c go_imagebutton"
How would I use Yad as a Wrapper for a program
I'm trying to wrap Yad around mpv to play videos: Here's my code that does not work.
No examples on web anywhere.
(update: I have looked at code in miskos wrapper for youtube-dl but, I don't understand and its so complicated)
No examples on web anywhere.
(update: I have looked at code in miskos wrapper for youtube-dl but, I don't understand and its so complicated)
Code: Select all
mpv /home/bobby/Videos/* | yad2 --dialog-sep --image="/home/bobby/yadbash/sparkypad/images/side-banners/niklback-revolution.png" --undecorated --geometry=1366x560+1+1 --title="Sparkpad Images" --border=0 --skip-taskbar
Dear lamplinux,
I cobbled this together for my own purposes and use it regularly:
Change the image paths in the script and desktop, and it should work for you too.
With kind regards,
vovchik
UPDATED: Fixed the script above and in the archive to run mpv and not smplayer.
I cobbled this together for my own purposes and use it regularly:
Code: Select all
#!/bin/bash
# ****************************************************************
# PROGRAM: gmpv
# PURPOSE: yad-based gui wrapper for mpv (URL or file)
# AUTHOR: vovchik, November 2018
# DEPENDENCIES: bash, yad, mpv
# VERSION: 0.1c
# ****************************************************************
# ***********************
# INITIALIZATION
# ***********************
# create icon and copy to /tmp/mpv.svg
LOAD=""
TITLE="Wait..."
TXT="Loading video..."
TMP="/tmp/gmpv.txt"
SEARCH="VO:"
rm "$TMP"
# search for "VO:"
SVG="<svg width='48' height='48' viewBox='0 0 100 100'>
<linearGradient id='l1' gradientUnits='objectBoundingBox'
x1='1' x2='1' y1='0' y2='1'>
<stop stop-color='skyblue' offset='1'/>
<stop stop-color='white' offset='0'/>
</linearGradient>
<path style='fill:#111111' d='M 10,3.1 10,97 90,97 90,3.1 z m 4,5.9
6,0 0,5 -6,0 z m 66,0 6,0 0,5 -6,0 z m -66,11 6,0 0,5 -6,0 z m 66,0
6,0 0,5 -6,0 z m -66,11 6,0 0,5 -6,0 z m 66,0 6,0 0,5 -6,0 z m -66,11
6,0 0,5 -6,0 z m 66,0 6,0 0,5 -6,0 z m -66,11 6,0 0,5 -6,0 z m 66,0
6,0 0,5 -6,0 z m -66,11 6,0 0,5 -6,0 z m 66,0 6,0 0,5 -6,0 z m -66,11
6,0 0,5 -6,0 z m 66,0 6,0 0,5 -6,0 z m -66,11 6,0 0,5 -6,0 z m 66,0
6,0 0,5 -6,0 z'/>
<path style='fill:url(#l1)' d='m 23,5 54,0 0,26 -54,0 z m 0,29 54,0
0,28 -54,0 z m 0,31 54,0 0,30 -54,0 z'/>
</svg>"
IMAGE="/home/vovchik/my-documents/anim/c1.gif"
ICON="/tmp/mpv.svg"
if [ ! -e "$ICON" ]; then
echo "$SVG" > /tmp/mpv.svg
fi
FONT="DejaVu Sans Mono Bold 14"
BUT="<span color='black'>Close</span>!!Close window"
NL="
"
results=""
get_url="$@"
LINE_COUNT=""
HELP="<b>Gmpv</b> needs an input argument.
Enter file/URL or '<b>?</b>' for help:"
ABOUT=$(mpv --list-options)
ERROR="$NL""<b>WARNING!</b>""$NL -----
Install <b>mpv</b> before""$NL""running this program.""$NL"
export SVG ICON FONT BUT NL HELP ABOUT results get_url SEARCH TMP IMAGE TITLE TXT LOAD
# ***********************
# END INITIALIZATION
# ***********************
# ***********************
# FUNCTIONS
# ***********************
# -----------------------
function GET_URL()
# -----------------------
{
get_url=$(yad \
--entry \
--title="Play URL" \
--text="$HELP" \
--entry-text "$get_url" \
--window-icon="$ICON" \
--image="$ICON" \
--image-on-top \
--center \
--margins=5 \
--width=400 \
--fontname="$FONT" \
--text-info \
--title="Mpv Gui" \
--buttons-layout=end \
--button="Play!!Play this URL":0 \
--button="Quit!!Click to quit this little program":1 \
--editable)
}; export -f GET_URL
# -----------------------
function SHOW_RESULTS()
# -----------------------
{
echo "Play: $get_url"
if [[ -z $get_url ]];then
echo "No URL. Bye-bye."
exit 1
elif [[ "$get_url" = "?" || "$get_url" = " " ]];then
# about box
results="$ABOUT"
echo "$results"
echo "About: mpv$NL$NL$results" | \
yad \
--window-icon="$ICON" \
--geometry=700x550+300+100 \
--title="Mpv About" \
--tail \
--text-info \
--fore="black" \
--back="#FFF7F7" \
--margins=5 \
--button="$BUT" \
--fontname="DejaVu Sans Mono 13" \
--autoscroll -
else
mpv "$get_url" >> "$TMP" &
while [ -z "$LOAD" ]; do
LOAD=$(grep "$SEARCH" /tmp/gmpv.txt)
echo running
sleep 0.5
done | yad \
--progress \
--title="$TITLE" \
--picture \
--size=orig \
--filename="$IMAGE" \
--width=280 \
--height=190 \
--pulsate \
--center \
--inc=2 \
--no-buttons \
--auto-close \
--auto-kill \
--undecorated \
--text-align=center \
--window-icon="$ICON" \
--text="<b>Loading video...</b>"
fi
}; export -f SHOW_RESULTS
# -----------------------
function SHOW_ERROR()
# -----------------------
{
yad \
--window-icon="$ICON" \
--title="Mpv Gui" \
--image-on-top \
--center \
--image="$ICON" \
--text-align="center" \
--text="$ERROR" \
--button="$BUT"
}; export -f SHOW_ERROR
# ***********************
# END FUNCTIONS
# ***********************
# ***********************
# MAIN
# ***********************
if [ $(which mpv) ]; then
while true; do
GET_URL
SHOW_RESULTS
done
else
echo "mpv was not found. Please install it."
SHOW_ERROR
fi
# ***********************
# END MAIN
# ***********************
With kind regards,
vovchik
UPDATED: Fixed the script above and in the archive to run mpv and not smplayer.
- Attachments
-
- gmpv.tar.gz
- (10.76 KiB) Downloaded 112 times
Last edited by vovchik on Fri 22 Feb 2019, 10:41, edited 1 time in total.
Yad Video Wrapper
@vovchik - Thank You so much. I will use your script tonight and learn from your code.