YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#286 Post by slavvo67 »

I'm running 37.0 but sometimes Victor breaks a version when implementing new things.... Maybe I'll upgrade again ....


Thanks

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

#287 Post by slavvo67 »

Is there any way to pass the drag and drop to the next part of the script without requiring the ok box to be clicked? The no buttons option does not advance unless you close the actual window....

Thank you

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

#288 Post by MochiMoppel »

slavvo67 wrote:Is there any way to pass the drag and drop to the next part of the script without requiring the ok box to be clicked?
Which "ok box"? You should place the "next part" before the yad statement as a function:

Code: Select all

function myfunction {
	Xdialog --msgbox "You dropped\n$0" x
}
export -f myfunction

yad --width=200 --height=200 --dnd --command="bash -c 'myfunction'"

stemsee

#289 Post by stemsee »

solved!

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

#290 Post by step »

Hi all, the conversation that we started, near page 16, about a drag-and-drop script has grown into yet-another script here --> screenshot.
[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
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

Iconbox

#291 Post by misko_2083 »

I have this folder /home/user/Desktop/yad_iconbox
in that folder, there is a script switch.sh and a deskop file

Code: Select all

#!/bin/bash
#switch.sh

PARAM="$@"
case $PARAM in
   test)
      if [[ -f "/home/user/Desktop/yad_iconbox/icon-on.desktop" ]]; then
         sed -i 's/gtk\-yes/gtk\-no/g' /home/user/Desktop/yad_iconbox/icon-on.desktop
         mv /home/user/Desktop/yad_iconbox/icons-on.desktop /home/user/Desktop/yad_iconbox/icon-off.desktop
         #more commands here
       else
         sed -i 's/gtk\-no/gtk\-yes/g' /home/misko/Desktop/yad_iconbox/audacious-off.desktop
         mv /home/user/Desktop/yad_iconbox/icon-off.desktop /home/user/Desktop/yad_iconbox/icon-on.desktop
          #commands...
       fi
       ;;
   *) exit
   ;;     
esac
icon-off.desktop

Code: Select all

[Desktop Entry]
Version=1.0
Type=Application
Name=Icon
GenericName=Icon
Comment=Test
Icon=gtk-no
Categories=GTK;
Exec=/home/user/Desktop/yad_iconbox/switch.sh test
TryExec=/home/user/Desktop/yad_iconbox/switch.sh test
Terminal=false
I launch the Iconbox with next

Code: Select all

#!/bin/bash
yad --icons --single-click --monitor --height=300 \
    --width=500 --read-dir="/home/user/Desktop/yad_iconbox"
If I click on this icon, it will change.

I would like to know is there a way to do this using the stdin, since --icons dialog can read from stdin.
--listen
Read data from stdin. Data must be in order - Name, Tooltip,
Icon, Command, InTerm separated by newline. InTerm is a case
insensitive boolean constant (TRUE or FALSE).

Is there a way to force the dialog to reset the icons with something being sent to the pipe?
Example:

Code: Select all

(echo -e "Name\nTooltip\ngtk-ok\necho \"\"\nFALSE"; sleep 1; echo "Reset the icons") | yad --icons --single-click --listen --monitor --height=300 --width=500

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

Re: Iconbox

#292 Post by MochiMoppel »

misko_2083 wrote:If I click on this icon, it will change.
Really? First I needed to fix the switch.sh script:
- Change one instance of icons-on.desktop to icon-on.desktop and
- /home/misko/Desktop/yad_iconbox/audacious-off.desktop to /home/user/Desktop/yad_iconbox/icon-off.desktop
Is there a way to force the dialog to reset the icons with something being sent to the pipe?
I don't think that this is possible. AFAIK you can only add icons this way but not change existing ones:

Code: Select all

#!/bin/bash
export PIPE_03=/tmp/yadpipe03 
mkfifo $PIPE_03 
exec 3<> $PIPE_03 

yad --icons --single-click --height=300 --width=500 --listen < $PIPE_03 &
echo -e "Name\nTooltip\ngtk-ok\nbeep\nFALSE" > $PIPE_03
sleep 1
echo -e "Yes\nTooltip\ngtk-yes\nbeep\nFALSE" > $PIPE_03
sleep 1
echo -e "No\nTooltip\ngtk-no\nbeep\nFALSE"   > $PIPE_03
I found no way to clear the icons box. Your original method, using --monitor and --read-dir, seems to be a .better approach.

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

Re: Iconbox

#293 Post by misko_2083 »

Thank you for the reply MochiMoppel
Sorry about the errors. :)
I've seen the Yad source and there is only one way as you say.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

birthday

#294 Post by achim »

Hi,
6 months ago I switched to Ubuntu 4.16 and have now a lot of fun to yad. Now, however, I have a problem for days. I want you to read and display the result from the "Birthday" on yad. Since the result of more than one word, I get with the attached code, the result only with each displayed (word for word). Can somebody help me with it?

#! / bin / bash

yad --title = 'special events' \
--text = 'birthday' \
--text-align = center --geometry = 950x400 \
--list \
--scroll \
--column = " event "\
--buttons-layout = "center" \
--button =" <b> <span color = 'blue'> Close </ span> </ b> "\
--image-on-top \
- image = / home / hachims / .icons / drive-3-cb-system-dos-icon.png \
$ (birthday -f /home/hachims/Dokumente/b2.txt)

PS. I loaded a professional script with yad to download from youtube down from the net. Can I publish this?

Sorry, I just see that is the wrong forum. Please by YAD tips move. Thank you!

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

Re: birthday

#295 Post by MochiMoppel »

achim wrote:Since the result of more than one word, I get with the attached code, the result only with each displayed (word for word)
You are not supposed you get any result at all with this code. Lots of spaces where there shouldn't be any, starting with the shebang '#! / bin / bash', followed by spaces around = and lastly by the space after $ in '$ (birthday -f /home/hachims/Dokumente/b2.txt)'

If this is fixed you need to send the result of your birthday command to yad, presumably with something like
<<< "$(birthday -f /home/hachims/Dokumente/b2.txt)". Mind the double quotation marks around your statement.

If this doesn't help we need to know the output of the birthday -f /home/hachims/Dokumente/b2.txt command.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Re: birthday

#296 Post by achim »

Hi MochiMoppel

thank you for your help, with your suggestion does the YAD script now properly. Still my question remains whether interest in a very functional YAD script "Youtube downloader" is. It is not written by me, but recently downloaded from the Internet. I ask for a short answer.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

execute order

#297 Post by achim »

Hello,
I use the following script under Ubuntu as an alternative to the command known under Windows "Run". It works so far, but there is no message if the string is not found. This situation should be caught with a "not found" message and restart the script. Does somebody has any idea?

Code: Select all

#! /bin/bash

XTERM="xterm"

# create history file 
mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/ 
HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/ix-run.history 
touch $HISTFILE

# create and run dialog 
TITLE="Befehl ausführen" 
TEXT="\nBefehl eingeben und Enter drücken:\n" 
rcmd=$(yad --width=500 --center --window-icon="gtk-execute" --name="${0##/}" --title="$TITLE" --text="$TEXT" --image="gtk-execute" --editable --entry --rest $HISTFILE)

echo "tooltip:Beispielmenü" 

[-z "$rcmd" ] && exit 0

# run command 
case $rcmd in
    http://*|https://*|ftp://*)
        xdg-open $rcmd & 
        ;;
    mailto://*)
        xdg-email $rcmd & 
        ;;
    man://*)
        eval $XTERM -e "man ${rcmd#man://}" & 
        ;;
    telnet*|ssh*)
        eval $XTERM -e "$rcmd" & 
        ;;
    *)
        eval $rcmd & 
        ;;
esac

# add command to history 
head $HISTFILE | grep -qF "$rcmd" || echo -e "$rcmd\n$(<$HISTFILE)" > $HISTFILE

exit 0
Thanks in advance

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

Re: execute order

#298 Post by Geoffrey »

achim wrote:Hello,
I use the following script under Ubuntu as an alternative to the command known under Windows "Run". It works so far, but there is no message if the string is not found. This situation should be caught with a "not found" message and restart the script. Does somebody has any idea?
Some time back I used this script also, I modified it to give a error message if the command didn't exist and the option to clear the history, this uses exo-open not xdg-open hope this is of help.

Code: Select all

#! /bin/bash
HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/ix-run.history
# delete history file
Clear_History(){
	rm $HISTFILE
	yad --fixed --title="History" --window-icon="applications-system" --text="\n        History Cleared        \n" --timeout="2" --no-buttons
	`basename "$0"`
}
export -f  Clear_History
XTERM="xterm"
# create history file
if [ ! -f $HISTFILE ]; then
mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/
echo 'Clear_History' > $HISTFILE
fi
# create and run dialog
TITLE="Run command"
TEXT="\nEnter command to execute:\n"
CMD='yad --fixed --width=400 --center --window-icon="applications-system" --buttons-layout=center --title="$TITLE" --text="$TEXT" --button="gtk-ok:0" --image="applications-system" --entry --editable'
ARGS=$(perl -pe 's/(^.*$)/"\1"/;s/\n/ /' $HISTFILE)
rcmd=$(eval $CMD $ARGS)

# run command
case $rcmd in
    www.*|http://*|https://*|ftp://*|mailto:*)
        exo-open $rcmd &
        ;;
    man://*)
        eval $XTERM -e "man ${rcmd#man://}" &
        ;;
    telnet*|ssh*)
        eval $XTERM -e "$rcmd" &
        ;;
    *)
        eval $rcmd 2> /tmp/run-command-error &
        ;;
esac
sleep .1
if grep -c 'command not found' /tmp/run-command-error; then
yad --fixed --title="Error" --window-icon="applications-system" --text="\n Command not found \n" --timeout="2" --no-buttons 
sed 's/ $CMD// $HISTFILE'
rm /tmp/run-command-error
`basename "$0"`
else
# add command to history
grep -qF "$rcmd" $HISTFILE || echo $rcmd >> $HISTFILE
fi
exit 0
Edit: removed error in code.
Last edited by Geoffrey on Mon 17 Apr 2017, 04:29, 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]

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Re: execute order

#299 Post by achim »

Hi Geoffrey,
Thank you for your help. However, your modified variant does not report any errors, but terminates the script without comment. Basically, it runs with me just as the original. I use the YAD version 0.38.2 (GTK + 3.20.8). If you have something else to think about, then please contact me.

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

Re: execute order

#300 Post by Geoffrey »

@achim, you are using your run script in puppy?

I'm unaware of any Puppy flavor that uses yad compiled with GTK + 3.20.

I've modified your script, works for me ok

The code outputs the error to file, then grep checks for the 'command not found', if true then displays the message.

`basename "$0"` runs a new instance of your script, provided that it's in the PATH.

Code: Select all

#! /bin/bash

XTERM="xterm"

# create history file
mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/
HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/ix-run.history
touch $HISTFILE

# create and run dialog
TITLE="Befehl ausführen"
TEXT="\nBefehl eingeben und Enter drücken:\n"
rcmd=$(yad --width=500 --center --window-icon="gtk-execute" --name="${0##/}" --title="$TITLE" --text="$TEXT" --image="gtk-execute" --editable --entry --rest $HISTFILE)

echo "tooltip:Beispielmenü"

# run command
case $rcmd in
    http://*|https://*|ftp://*)
        xdg-open $rcmd &
        ;;
    mailto://*)
        xdg-email $rcmd &
        ;;
    man://*)
        eval $XTERM -e "man ${rcmd#man://}" &
        ;;
    telnet*|ssh*)
        eval $XTERM -e "$rcmd" &
        ;; *)
        eval $rcmd 2> /tmp/run-command-error &
        ;;
esac
sleep .1
if grep -c 'command not found' /tmp/run-command-error; then
yad --fixed --title="Error" --window-icon="applications-system" --text="\n Command $rcmd not found \n" --timeout="3" --no-buttons
rm /tmp/run-command-error
`basename "$0"`
else
# add command to history
head $HISTFILE | grep -qF "$rcmd" || echo -e "$rcmd\n$(<$HISTFILE)" > $HISTFILE
fi
exit 0
[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]

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Re: execute order

#301 Post by achim »

@ Geoffrey
My scripts are not running in the Puppy environment but under Ubuntu 16.04 LTS in the folder ~ / .local / share / nemo / scripts. I could install Puppy to test on a USB stick, but the scripts should all be running under Ubuntu.

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

#302 Post by fredx181 »

It could well be a language issue, the output from the shell 'command not found' in german is probably different, so you maybe just need to change this to german:

Code: Select all

if grep -c 'command not found' /tmp/run-command-error; then
EDIT: Or put this on top of script:

Code: Select all

export LANG=C
Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#303 Post by achim »

@ Fredx181
With the first code it has already worked. An error message will appear as desired.

@Alles
Thanks for the kind support.

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

#304 Post by fredx181 »

Hi All,

Here's is an experiment of mine (a bit weird, I admit:) ):
Using yad with additional options, e.g. foregound and background color, gradient background and font setting.
Originally meant to be similar as gtkdialog-splash (part of the code taken from it), to be used for simple colored messages, but the good thing is that all yad options can be used also.
Using pango markup can override these extra options (see example 2 and 3 below).
Type ./yad-splash or ./yad-splash --help for the options.
Having installed "gtk2-engines-murrine" is recommended (for e.g. better looking buttons)
(in fact a custom theme file /tmp/gtkrc.yadsplash will be created and used)
You may want to set the icon theme on top of the script, by default it's set to Faenza
ICON_THEME="icon_theme_name"

Example 1, see screenshot 1:

Code: Select all

./yad-splash --height=80 --width=200 --center --text "  \tYellow Text\n  \n  On Gradient Background  " --undecorated --button="gtk-close:1" --fg yellow --bg blue --bg_gradient true --bg_gradient_height 150 --font_name 'Sans Bold 9'
Example 2, see screenshot 2:

Code: Select all

./yad-splash --height=100 --width=200 --center --text="<span size='large' foreground='red'><b>\tYad-Splash </b></span> \n \n\tBrown Text\n  \n  On Gradient Background  "  --undecorated --no-buttons --fg "#4B200A" --bg "#F4E48F" --bg_gradient true --font_name 'Sans Bold 10' --bg_gradient_height 80
Example 3, (example from earlier in this thread, with added color options) see screenshot 3:

Code: Select all

./yad-splash --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>" --fg white --bg grey --bg_gradient true --bg_gradient_height 120 --font_name 'Sans Bold 9'
Fred
Attachments
yad-splash.tar.gz
yad-splash, extract and run ./yad-splash [OPTIONS]
(2.44 KiB) Downloaded 294 times
1.png
Example 1
(8.9 KiB) Downloaded 1753 times
2.png
Example 2
(15.48 KiB) Downloaded 1746 times
3.png
Example 3
(22.31 KiB) Downloaded 1764 times

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

youtube-dl

#305 Post by achim »

Hello everybody,
With the command

Youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' - merge output format mp4 "https://www.youtube.com/watch?v=4x0aYzcxmjk"
Downloade I from the Ubuntu Terminal the selected file in the best possible quality in the current directory. Has anyone an idea how I can make the whole thing with yad more comfortable, whereby the url address is of course variable.
Many Thanks

Post Reply