YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
stemsee

#526 Post by stemsee »

I am interested to know what other ways I can utilise exclusively (time slots) a yad dnd panel which is part of --notebook --paned gui.

So far I am using tee together with a variable which that yad dnd element is piped to. This gives two pipes out of the dnd. When I want only the tee output I redifine the variable to tap=/dev/null . It works. But I found that I can also define the output of the dnd by association, dndout=$(yad --dnd | tee /tmp/outdnd &>$tap &) &, and seems to work without affecting its function in the --notebook gui.

I want to know how many pipes I can feed to without using tee... is this possible in theory

Code: Select all

dndout=$(yad --plug=$$ --tabnum=2  --dnd &>$tap &>$apt &>$pat &) &
currently

Code: Select all

yad --listen --plug=$$ --tabnum=1 --item-separator=" " --form --cycle-read --columns=2 --field=A --field=0 --field=1 --field=2 --field=3 --field=4 --field=5 --field=6 --field=7 --field=8 --field=9 --field=10 <& 2 &
yad --plug=$$ --tabnum=2 --text="\t\t\t\t\t\t\tDnD panel\n\tClick a button\n\tThen Drag the mac address here!" --dnd | tee $pat 1>$tap &
yad --geometry=$(cat $camino/geometry/$WINDOWTITLE) --title="$WINDOWTITLE" --title=Bluetooth --window-icon=$pics/bluetooth-active.png --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo command" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" 1>/tmp/Wifi-TrayNet/btfn &

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#527 Post by misko_2083 »

stemsee wrote:I am interested to know what other ways I can utilise exclusively (time slots) a yad dnd panel which is part of --notebook --paned gui.

So far I am using tee together with a variable which that yad dnd element is piped to. This gives two pipes out of the dnd. When I want only the tee output I redifine the variable to tap=/dev/null . It works. But I found that I can also define the output of the dnd by association, dndout=$(yad --dnd | tee /tmp/outdnd &>$tap &) &, and seems to work without affecting its function in the --notebook gui.

I want to know how many pipes I can feed to without using tee... is this possible in theory

Code: Select all

dndout=$(yad --plug=$$ --tabnum=2  --dnd &>$tap &>$apt &>$pat &) &
currently

Code: Select all

yad --listen --plug=$$ --tabnum=1 --item-separator=" " --form --cycle-read --columns=2 --field=A --field=0 --field=1 --field=2 --field=3 --field=4 --field=5 --field=6 --field=7 --field=8 --field=9 --field=10 <& 2 &
yad --plug=$$ --tabnum=2 --text="\t\t\t\t\t\t\tDnD panel\n\tClick a button\n\tThen Drag the mac address here!" --dnd | tee $pat 1>$tap &
yad --geometry=$(cat $camino/geometry/$WINDOWTITLE) --title="$WINDOWTITLE" --title=Bluetooth --window-icon=$pics/bluetooth-active.png --key=$$ --columns=2 --paned --height=220 --width=300 --tab=Found --tab=DnD --button="Command":"echo command" --button="Scan":"echo btscanfn" --button="Remove":"echo rmdev" --button="Connect":"echo btcon" --button="Disconnect":"echo btdisconfn" 1>/tmp/Wifi-TrayNet/btfn &
Hi there Stemsee, long time no chat :)

Thinking that this kind of redirection &>$tap &>$apt &>$pat is possible only in zsh.

About the paned dialog, what is the purpose of the ten fields in the first tab?

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#528 Post by step »

Hi stemsee, so you want to fan output to N taps using shell only? What about piping to a "while read; do" loop and echoing to as many files as you need inside the body of the loop? Something like:

Code: Select all

dndout=$(yad --plug --tabnum=2 --dnd |
while read s; do
  echo "$s" >> $tap; echo "$s" >> $apt; echo "$s" >> $path; echo "$s"
done)
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Yad Launcher

#529 Post by lamplinux »

Is it possible for yad to display all file names in a folder, i.e. /usr/share/applications... like firefox.desktop google-chrome.destop, etc. and have a chck box next to each listed file displayed in list.

Then user checks the box of each file they want to use in a home folder (directory).

Then upon button click - checked files are then copied from /usr/share/applications to /home/user/yadlauncher/applications ?

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

Re: Yad Launcher

#530 Post by step »

lamplinux wrote:Is it possible for yad to display all file names in a folder, i.e. /usr/share/applications... like firefox.desktop google-chrome.destop, etc. and have a chck box next to each listed file displayed in list.

Then user checks the box of each file they want to use in a home folder (directory).

Then upon button click - checked files are then copied from /usr/share/applications to /home/user/yadlauncher/applications ?
Yes. Here's a template you can elaborate on:

Code: Select all

cd /usr/share/local/share/applications/ && ls *.desktop | yad --center --list --column= --checklist --column=file | cut -d'|' -f2 | xargs echo cp -t /dest/dir 
This will print the copy command that would be executed. If that's OK delete "echo" from the command to get a working version. Of course change /dest/dir, absolute path to the destination directory, as you see fit.

If you then want to display an icon grid for the files in /dest/dir use:

Code: Select all

yad --icons --read-dir=/dest/dir
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

RE: yad list help

#531 Post by lamplinux »

Step, Thank You Very much!! I will work on this tomorrow. I will sleep well tonight knowing it will be a productive day having received your help !

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#532 Post by MochiMoppel »

@lamplinux As always step was one step ahead :lol:

Normally the --file dialog is used for such task. That's what it is made for:

Code: Select all

TARGET="/home/user/yadlauncher/applications"
CHECKED=$(yad --title="Please select (multiple) files" --file --geometry=700x500 --button="Copy to $TARGET":0 --button=Cancel:1 --file-filter=*.desktop --multiple --filename=/usr/share/applications/* )
(($?)) && exit
IFS=TMP IFS='|'
cp -t "$TARGET" $CHECKED 
IFS=$TMP
The --list dialog with checkboxes is a bit more complicated. I used the sed command to add default values for the checkbox column (without it the dialog would display only every 2nd file of the source directory):

Code: Select all

IFS=TMP IFS=$'\n'
TARGET="/home/user/yadlauncher/applications"
SOURCE=/usr/share/applications
cd "$SOURCE"
SOURCE=$(ls *.desktop | sed 's/^/FALSE\n/')
CHECKED=$(yad  --title="Please select (multiple) files" --list --print-column=2 --separator=$IFS --checklist --geometry=400x600 --column="" --column=Name --button="Copy to $TARGET":0 --button="gtk-cancel":1 $SOURCE) 
(($?)) && exit
cp -t "$TARGET" $CHECKED
IFS=$TMP
If it hasn't to be yad you should also consider Xdialog. The beauty here is that you can click anywhere in the line and don't have to target a tiny checkbox:

Code: Select all

IFS=TMP IFS=$'\n'
TARGET="/home/user/yadlauncher/applications"
SOURCE=/usr/share/applications
cd "$SOURCE"
SOURCE=$(ls *.desktop | sed 's/.*/&\n&\nno/')
CHECKED=$(Xdialog  --title="Please select (multiple)files" --ok-label=Copy --stdout --no-tags  --separate-output --checklist  "Copy selected file to\n $TARGET" 400x600 0 $SOURCE ) 
(($?)) && exit
cp -t "$TARGET" $CHECKED
IFS=$TMP

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

RE: yad list select

#533 Post by lamplinux »

@MochiMoppel

Thank You. I will use your code tonight and see what it does. I've been using yad for some years now but, I lack experience with bash.

Thank You for code help.

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

RE: Adding a couple more options.

#534 Post by lamplinux »

Thank you @Step & @MochiMoppel for yad + bash code help.

I would like to expand on this to do the following. Now that I have a starting point I know I can eventually get to what I want to offer to others. (I'm just very slow at it)

Expanding Yad Favorite app launching:

1. Check mark shown for all .desktop files present in base directory.

2. Option for user to remove 1 or more .desktop file from base directory. (If check mark remove, its .desktop file is remove from base directory),

3. Display icon next checkbox for all possible /usr/share/applications/*.desktop files.. (For Example, Reading 3rd line, 5th character and all characters to the right of 5th character to end of line of each icon.desktop file. --- 5th line - "icon=internet_icon).

4. Dropdown or I guess, DND, to allow user to assign each .ldesktop file to specific folders. For example, Internet, Network, Personal, Sparky, Yad, etc.

Does my mod concept sound useful.. What else could this yad script offer to users for each launching of apps, websites, settings, bash commands like "sudo apt update", etc ?

oldaolgeezer
Posts: 64
Joined: Sun 03 Dec 2006, 19:34

YAD - Tips

#535 Post by oldaolgeezer »

It possible for yad to display all grocery item names
and have a check box next to each item displayed in list.
Then the user checks the box of each item they want to buy.
Then upon button click - checked files are then copied to a file

it uses Anthony Tekatch's shopping list.txt file (which can be edited
with your local grocery store's aisle numbers or name with Puppy's Geany editor)
License: GPL
http://unihedron.com/projects/grocget/d ... 0.6.tar.gz
http://freshmeat.sourceforge.net/projects/grocget
Anthony's original program needs Python, and some Gnome modules but just his list.txt file
(which has two fields: the aisle number followed by the grocery item's name)
can be used from his tar file in this yad script example (to save some initial typing)

and a little editing of MochiMoppel's original Xdialog script from:
http://www.murga-linux.com/puppy/viewto ... 31#1016071

the final resultant file: todaysgroceryshoppinglist.txt can be printed out
or emailed or USB'ed to a smart phone for use in the local grocery store so you
only walk on aisles that have what you are buying.

Thank you: Anthony Tekatch and MochiMoppel

Code: Select all

#!/bin/bash 

# It possible for yad to display all grocery names 
#     and have a check box next to each listed item displayed in list.
#Then the user checks the box of each item they want to buy.
#Then upon button click - checked files are then copied to a file

# it uses Anthony Tekatch's shopping list.txt file (which can be edited 
#     with your local grocery store's aisle numbers or name with Puppy's Geany editor)
#    License: GPL
#    http://unihedron.com/projects/grocget/downloads/grocget-0.6.tar.gz
#    http://freshmeat.sourceforge.net/projects/grocget
#  Anthony's original program needs Python, and some Gnome modules but just his list.txt file 
#   (which has two fields: the aisle number followed by the grocery item's name)
#      can be used from his tar file in this yad script example (to save some initial typing)

#  and a little editing of MochiMoppel's original Xdialog script from:
#  http://www.murga-linux.com/puppy/viewtopic.php?p=1016071&sid=4fe9401fedc62e90f7be909e80b63231#1016071

#   the final resultant file: todaysgroceryshoppinglist.txt can be printed out 
#        or emailed or USB'ed to a smart phone for use in the local grocery store so you 
#             only walk on aisles that have what you are buying.

#  The default value of IFS is a space, a tab, and a newline
IFS=TMP IFS=$'\n'

#  current working directory to be the directory that the script is located in
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

SOURCE=$(cat list.txt | sed 's/.*/&\n&\nno/')

CHECKED=$(Xdialog  --title="Please select (multiple) items" --ok-label=Select --stdout --no-tags  --separate-output --checklist  "Copy selected item to\n shopping list" 400x600 0 $SOURCE )  

(($?)) && exit

echo   -e   "$CHECKED"

echo   -e   "$CHECKED"  >   todaysgroceryshoppinglist.txt

IFS=$TMP

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: RE: Adding a couple more options.

#536 Post by MochiMoppel »

@lamplinux: Yad may pose some problems. Placing icons next to the checkmarks may be one of them. Earlier in this thread I posted a demo for an icon finder. For this particular use case it is nice to show the icons in their original size, but in your case you might want to have them automatically resized to fit the row height. AFAIK yad can't do that.

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Re: RE: Adding a couple more options.

#537 Post by lamplinux »

@MochiMoppel - all my desktop icons could be copied and resized automatically to say 16px. Then use the reduced size icons. Would that work ?

Also, I am using Your's and @Step code to also select music files too but, with one issue. I'm using mpg123 (in the background). I stop the play with a killall mpg123 command. The files display in Yad list but, fail to copy to base directory because of blank spaces.

How could I handle blank spaces in Awk so the selected files copy to the target directory ?

Thanks for your help.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

Re: RE: Adding a couple more options.

#538 Post by step »

lamplinux wrote:@MochiMoppel - all my desktop icons could be copied and resized automatically to say 16px. Then use the reduced size icons. Would that work ?

Also, I am using Your's and @Step code to also select music files too but, with one issue. I'm using mpg123 (in the background). I stop the play with a killall mpg123 command. The files display in Yad list but, fail to copy to base directory because of blank spaces.

How could I handle blank spaces in Awk so the selected files copy to the target directory ?

Thanks for your help.
if you're using something like

Code: Select all

ls *.mp3 | xargs cp -t /dest/dir
change that to

Code: Select all

printf "%s\0" *.mp3 | xargs -0 cp -t /dest/dir
This will take care of filepaths with spaces in them
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: RE: Adding a couple more options.

#539 Post by MochiMoppel »

lamplinux wrote:@MochiMoppel - all my desktop icons could be copied and resized automatically to say 16px. Then use the reduced size icons. Would that work ?
Depends. I'm not sure what you mean by "copied and resized automatically". If you manage to find the full paths of the .desktop icons, copy and resize those icons and then reference them in your yad list it should work.
Also, I am using Your's and @Step code to also select music files too but, with one issue. I'm using mpg123 (in the background). I stop the play with a killall mpg123 command. The files display in Yad list but, fail to copy to base directory because of blank spaces.
If you refer to my code please explain which of the 3 demos fail. They would fail if SOURCE path contains spaces (in which case you would have to put the path - like TARGET - in quotes, e.g SOURCE="/my/music folder").Since files display in the list as you wrote, this can't be the reason
How could I handle blank spaces in Awk so the selected files copy to the target directory ?.
Awk? Where does awk come into play?

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#540 Post by fredx181 »

MochiMoppel wrote:For this particular use case it is nice to show the icons in their original size, but in your case you might want to have them automatically resized to fit the row height. AFAIK yad can't do that.
yad can scale the icons with list display, but only if you specify the name of the icon only, without extension (instead of full path) and should be in icon search path (e.g. /usr/share/pixmaps), so then instead of e.g.

Code: Select all

 /usr/share/pixmaps/browser.png

Just:

Code: Select all

browser
But probably not very useful info for what @lamplinux wants, In case of listing .desktop files, on puppy the "Icon=...." has mostly the full path specified, so icons may show with different sizes then.

Fred

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

#541 Post by slavvo67 »

Hi oldaolgeezer,

I ran without the list.txt file being there and as you could imagine, my output was a mess. So I added the following after your DIR= line but before your SOURCE= line. To be exact, my if statement started on line 29.

if [ -e list.txt ]; then
yad --text="list.txt exists!"
else
touch list.txt
echo "01 apples
01 apricot
01 asparagus
01 bananas
01 beets
01 brocoli
01 brussel sprouts
01 cantelope
01 carrots
01 green peppers
01 ketchup
01 kiwi
01 milk
01 mozrla chs block
01 mozrla chs slices
01 mushrooms
01 onion
01 orange juice pure
01 oranges
01 peas
01 spinach
01 strawberries
01 tomato
01 tzaziki
01 yams
01 yogurt
02 butter
02 cheddar
02 cheese slices
02 cheese sticks
02 chili beans
02 cottage cheese
02 eggsDairy
02 jam
02 mayonaise
02 pork& beans
02 salmon
02 soup
02 soya sauce
03 shampoo
03 tea bisk
03 zest
04 chickpeas
04 egg noodles
04 jello
04 oil
04 parmesan cheese
04 pasta
04 pineapple slices
04 potatoes canned
04 pudding
04 raisins
04 rice
04 salt
04 sphagetti sauce
04 wheat germ
05 crackers
05 mustard
05 peanut butter
05 tea bags
06 dog food
06 flour
06 ginger ale
06 gravy (canned)
06 pumpkin pie filling
06 sugar
07 bounce
07 dish soap
07 dishwasher soap
07 hand soap liquid
07 lasagne noodles
07 laundry detergent
07 tomato canned
03 toothpaste
07 water
08 kleenex
08 minty bones
08 napkins
08 paper towels
08 toilet paper
04 mandarin oranges
04 pineapple chunks
12 bacon
12 chicken breasts
12 ground beef
12 ham roast
12 ham slices
12 meatballs
12 pork cutlets
12 sausage
12 spare ribs
12 steak flank
12 steak round
12 steak sirloin
12 steak tenderloin
12 wieners
16 comet
16 garbage bags
03 cereal
19 Bread
19 bread crumbs
19 buns
19 hamburg buns
19 hotdog buns
19 pita slices
19 rice cakes
20 cabbage Rolls
20 cake
20 chicken Cordon Swiss
20 cool whip
20 corn frozen
20 frozen dinners
20 ice-cream
20 mravioli
20 perogies
20 raspberries frozen (425g)
20 waffles
20 whipped cream">>list.txt
fi

oldaolgeezer
Posts: 64
Joined: Sun 03 Dec 2006, 19:34

YAD - Tips

#542 Post by oldaolgeezer »

slavvo67

I'm glad you were able to get Anthony Tekatch's
list.txt file extracted. (Others who are interested can copy
and paste it from your above post.)

I, myself, was very impressed with the "professional look" of
MochiMoppel's Xdialog command's window.
(I've attached a screen shot to show this.)

I downloaded grocget-0.6.tar.gz file and clicked on it and scanned its
contents and then selected his "grocget-0.6/list.txt" only and extracted just that
to a small directory I made called "grocery_shopping_for_Linux_stuff" on my
Windows NTFS drive. I put just the "list.txt" and my "yad_groceryshoppinglist.sh"
files in that directory.

I brought that directory up in a ROXfiler window and with a right click, choose
"window" then "terminal here". In my roxterm terminal window which opened, I entered
my script name with ". ./":
. ./yad_groceryshoppinglist.sh
after many cycles of trying, Geany editing and retrying "window" then "terminal here",
I wanted to share the versatility of MochiMoppel code.

Perhaps MochiMoppel's Xdialog script showing how to select file names and this
yad_groceryshoppinglist script showing selecting lines from within one file
will inspire others to code even more useful little script programs.
Attachments
Screenshot_of_yad_groceryshoppinglist_script.jpg
(59.38 KiB) Downloaded 651 times

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

RE: Failing - That's me ! All your code worked,

#543 Post by lamplinux »

Hi all, your code worked fine. I was trying to use awk to copy files with spaces and had problems. I will work with your code this weekend and learn more about what it does.

@step, your code with printf did the trick with copying files with spaces. Thanks !

Thanks Everyone for your help. I just need to test more to see what all the code does. I'm learning and still a newbie.

Will come back next week after testing, tweaking, learning. Thanks Again !!!! You all are very much appreciated.

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Yad as a mp3 player using mpv

#544 Post by lamplinux »

Experimenting with both mpg123 and mpv I need to send a keystroke to advance to next song.

mpg123 requires the "f" key to go to next song. mpg123 -C *.mp3

mpv requires the "Return" key to go to next sone. mpv *.mp3

Can not understand why when I click on Next Track Music button, another instance of mpv is executed.

Code: Select all

#!/bin/bash

play_mpv(){
cd /home/bobby/yadbash/sparky-launcher/music/
mpv *.mp3
}
export -f play_mpv


yad --form \
 --field="Play Random Music:BTN" "bash -c play_mpv" \
 --field="Next Track Music:BTN" "xdotool key Return" \
 --field="STOP MUSIC:BTN" "killall mpv"

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Yad as a mp3 player using mpv

#545 Post by MochiMoppel »

lamplinux wrote:Can not understand why when I click on Next Track Music button, another instance of mpv is executed.
Because when you click the button, yad becomes the active window and the xdotool sends a Return keystroke - without further instructions of course to the active window. Yad receives the keystroke and applies it to the first button and starts another instance of mpv. You should be happy that the Return key does not go to the button you just pushed as this would result in an infinite loop.

What you need to do is let your command activate the mpv window and then send Return.

Post Reply