YAD - Tips

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

#751 Post by stemsee »

Hey misko

Very cool.

I can almost visualise the code in my mind.

stemsee

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#752 Post by jafadmin »

Does anyone know how to do this in Yad?

Code: Select all

Xdialog --title "Example"  \
  --no-tags \
  --check "Sugar with that?" \
  --radiolist "Setup device:" 14 40 20 \
  1 " Manual Configuration" off \
  2 " Automatic Configuration" on
That makes a nice little dialog combining a radiolist and a checkbox.

My struggle is to do the same thing in Yad. I can make a checkbox dialog. I can make a radiolist dialog. But I can't figure out how to do both at once like Xdialog does it. :( :cry: :?

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

#753 Post by fredx181 »

Only way I can think of is with a rather complicated --paned dialog

Code: Select all

SETTINGS=$(
(yad --plug=$$ --tabnum=1 --list \
    --text="  Setup device     " \
    --radiolist \
    --column="" --column="Option" \
    "FALSE" " Manual Configuration" \
    "TRUE" " Automatic Configuration" &
yad --plug=$$ --tabnum=2 --form \
 --field="Sugar with that? :CHK" "FALSE" &
yad --title="Example" --center --window-icon=gtk-preferences --width=400 --height=200 --paned --splitter=120 --key=$$ --orient=vert)
)
Easier would be to use --form with combo-box:

Code: Select all

SETTINGS=$(yad --title="Example" --center --form --item-separator=":" \
 --field="Setup device :CB" "Manual Configuration:Automatic Configuration" \
 --field="Sugar with that? :CHK" "FALSE")
Fred

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#754 Post by jafadmin »

@fredx181

WOW! You is the absolute man! Both are workable solutions and great "howto" examples.

Thank you very much.

jafa

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#755 Post by Argolance »

Bonjour,
fredx181 wrote: :arrow: In this thread, second message

One suggestion (maybe for next time using yad --notification):
Instead of restarting the tray-icon when it needs updated, you can write the new variables for icon, menu and tooltip to the pipe, e.g.:

Code: Select all

echo "icon:$NEW_ICON" >&3
echo "menu:$NEW_MENU" >&3
echo -e "tooltip:$NEW_POPUP_TEXT" >&3
Then it would be a more smooth change in the system-tray.
(or maybe instead of >&3 : >$COMPTON_FIFO)
Would it be possible to have an example of the way this works, please?

EDIT: After a few tests, I see the enormous difference and simplicity of this way of working that I have long sought. I leave my question as it is because the answer may interest some users who want to know a little bit more?

Thank you so much! :D

Cordialement.

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

#756 Post by fredx181 »

Here's example, just to demonstrate refresh icon, menu or tooltip, probably you get the picture.
I guess I was wrong earlier with e.g. this

Code: Select all

echo "icon:$NEW_ICON" >&3
Should be:

Code: Select all

echo "icon:$NEW_ICON" >$PIPE

Code: Select all

quit_tray () {
echo "quit" >$PIPE
rm -f $PIPE
}
export -f quit_tray

my_menu () {
GET_MENU="Run at startup!bash -c auto_start!$CHECKICON|Exit!bash -c quit_tray!gtk-quit"
echo menu:"${GET_MENU}" >$PIPE
}; export -f my_menu

auto_start () {
if [ -f /tmp/MYPROGRAM_auto ]; then
export CHECKICON=gtk-ok
rm -f /tmp/MYPROGRAM_auto
# do something more here...

else
export CHECKICON=gtk-stop
touch /tmp/MYPROGRAM_auto
# do something more here...
fi

# refresh menu
my_menu
}; export -f auto_start 

left_click () {
if [ -f /tmp/MYPROGRAM_running ]; then
echo "icon:gtk-stop" >$PIPE
POPUP_TEXT="MyProgram stopped"
echo "tooltip:$POPUP_TEXT" >$PIPE 
rm -f /tmp/MYPROGRAM_running
# do something more here...

else
echo "icon:gtk-ok" >$PIPE
POPUP_TEXT="MyProgram running"
echo "tooltip:$POPUP_TEXT" >$PIPE
touch /tmp/MYPROGRAM_running
# do something more here...
fi
}; export -f left_click
 
export PIPE="/tmp/MYPROGRAM.$RANDOM"
mkfifo $PIPE

# attach a file descriptor to the file
exec 3<> $PIPE

# tray icon
[ -f /tmp/MYPROGRAM_running ] && TRAY_ICON="gtk-ok" || TRAY_ICON="gtk-stop"

# menu
[ -f /tmp/MYPROGRAM_auto ] && CHECKICON=gtk-stop || CHECKICON=gtk-ok
my_menu

# tooltip
[ ! -f /tmp/MYPROGRAM_running ] && export POPUP_TEXT="MyProgram stopped" || export POPUP_TEXT="MyProgram running"
 
## Run yad and tell it to read its stdin from the file descriptor ####
yad --notification --listen \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c left_click" <&3
EDIT: Few minutes later. Made some small changes.

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#757 Post by Argolance »

Bonsoir,
As far as I know, this little example was missing among all these tips! It is a good lesson that will allow me to improve some of my scripts which use yad --notification, starting with CompSysTray!

Thank you very much for your availability and kindness.
:D

Cordialement.

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

#758 Post by misko_2083 »

fredx181 wrote:Only way I can think of is with a rather complicated --paned dialog
*-*-*-*-*-*
Fred
There is another way but it's not simpler because JavaScript is required. :)
And I think yad doesn't have --html option in pupies.
Image

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

#759 Post by fredx181 »

Here's alarm script using yad.
Inspired by Misko's last post, not as fancy looking though :wink: (no -html)
There can be found many alarm scripts on the web, but none that I really like, so made my own.
One good thing is IMO that you can set the alarm for the next day e.g. from current time 21:00 to target time next day at e.g. 6:00
Feedback would be appreciated !

Code: Select all

#!/bin/bash

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
 
sound="$2"
if [ ! -f "$sound" ]; then
yad --center --title="No sound file" --text="  No sound file selected   " --width=350 --button="gtk-close:0"
exit
fi

yad --center --undecorated --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $3:$5</b> " --width=280 --no-buttons --timeout 4

hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
mn="$5"
target="$hr:$mn"
repeat="$4"
interval="$6"
dur="$7"

hrnow=$(echo $(date +"%k"))

# For when trying to set alarm for next day e.g. from current 21:00 to target 6:00
if [ "$hr" -lt "$hrnow" ]; then
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else           # if target hour is larger number than current e.g. from 6:00 > 8:00
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

echo "Wake Up!"

while [ $repeat -gt 0 ]; do
$PLAYER "$sound" </dev/null >/dev/null 2>&1 &
sleep $dur
pidplayer="$(pgrep -lf "$PLAYER $sound" | awk '{ print $1 }')"
[ -n "$pidplayer" ] && kill -9 $pidplayer
repeat=$(($repeat-1))
if [ $repeat -gt 0 ]; then
  if [ $dur -lt $interval ]; then
  sleep $(($interval-$dur)) 2> /dev/null
#  else
#  sleep $interval 2> /dev/null
  fi
fi
done
}; export -f alrm

# set hour and minute at current time in yad GUI
hour=$(echo -e "$(seq -w $(date +"%H") 23)\n$(seq -w 00 $(date +"%H"))" | sed '$ d' |xargs | tr ' ' ':')
min=$(echo -e "$(seq -w $(date +"%M") 59)\n$(seq -w 00 $(date +"%M"))" | sed '$ d' |xargs|tr ' ' ':')

[ -z "$PLAYER" ] && PLAYER=mplayer

while :
do 
  date +"%H":"%M":"%S"
  sleep 0.5
done | yad --plug="$$" --tabnum=1 --form --cycle-read --columns=2 --field="\t\t<i><b>S e t  A l a r m</b></i>\t:lbl" --field="Current Time:: " &

yad --plug="$$" --tabnum=2 --center --title="Alarm" --form --columns=4 --item-separator=":" \
--field="Player::sfl" "$PLAYER" \
--field="Sound::sfl" "" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "01:01..100:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "00:00..1000:01" \
--field="Duration:\n(seconds):NUM" "05:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --center --title="Alarm" --paned --key="$$" --orient=vert --no-buttons
Fred
Attachments
2019-11-28-204931_659x179_scrot.png
YAD alarm
(39.9 KiB) Downloaded 327 times

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#760 Post by Argolance »

Bonjour,
alarm script works fine!
Thanks.
Why not an optional icon in the system tray to launch the script and the same icon but very slightly flashing when the alarm is set and running in the background? :wink:

Cordialement.

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

#761 Post by fredx181 »

Argolance wrote:Bonjour,
alarm script works fine!
Thanks.
Why not an optional icon in the system tray to launch the script and the same icon but very slightly flashing when the alarm is set and running in the background? :wink:

Cordialement.
Thanks for testing and suggestion !
I'm not sure if or when I'll continue improving this, there can be many options, like e.g. remember last settings, mute sound when the alarm goes off or set the volume etc.., a systray icon (with menu) indeed would be good.

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#762 Post by Argolance »

For example... :)
Attachments
mini-locale.gif
(5.54 KiB) Downloaded 262 times

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

#763 Post by fredx181 »

Argolance wrote:For example... :)
Thanks, but how you get that (left side) animated icon in the system tray ?

Fred

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

#764 Post by misko_2083 »

fredx181 wrote:
Argolance wrote:For example... :)
Thanks, but how you get that (left side) animated icon in the system tray ?

Fred

Code: Select all

#!/bin/bash
exec 3> >(yad --notification --listen)
while sleep 2; do
     echo "icon:gtk-ok" >&3
     sleep 2
     echo "icon:gtk-yes" >&3
     sleep 2
     echo "icon:gtk-no" >&3
done
exec 3>&-

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#765 Post by Argolance »

Bonjour,
misko_2083 is like Lucky Luck, he shoots faster than his shadow 8)
I don't remember which Forum member gave me these "while..." lines that work fine too:

Code: Select all

#!/bin/bash
command () {
echo -en "\\033[1;32m"
echo "VOUS-Y AVEZ CRÛ?"
} ; export -f command

while true; do echo 'icon:'/root/alarm_1.png; sleep 1; echo 'icon:/root/alarm_2.png'; sleep 1; echo 'icon:/root/alarm_3.png'; sleep 1; echo 'icon:/root/alarm_4.png'; sleep 1; done | yad --notification --icon-size=20 --auto-kill --no-middle --listen --text="Alarm is running in the background...
Click this icon and you will see the Eiffel Tower..." --command="urxvt -hold -e bash -c command" &
XPID=$!
sleep 60
kill $XPID

Regarding this script, how to make:

Code: Select all

yad --text-info="Doesn't work"
as --command option above work? Didn't found the solution, idem for this:

Code: Select all

yad --text-info < /root/my-documents/clipart/README-clipart.txt
Cheers
Attachments
alarm_icons.tar.gz
To unzip in /root...
(1.77 KiB) Downloaded 120 times

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

#766 Post by fredx181 »

Argolance wrote:misko_2083 is like Lucky Luck, he shoots faster than his shadow Cool
:lol: Yes, watch MiskY, he's one of a kind !!
Thanks for the code and the icons, I was thinking for a while that it was a .gif image, but not not supported by yad --notification, this way works nicely too !
Regarding this script, how to make:
Code:
yad --text-info="Doesn't work"
Pipe the text to yad --text-info ?

Code: Select all

echo "Works" | yad --text-info
EDIT: also:

Code: Select all

yad --text-info --filename=/root/my-documents/clipart/README-clipart.txt
EDIT2: Regarding echo "Works" | yad --text-info

Code: Select all

 --command="bash -c 'echo "Works" | yad --text-info'"
should do

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#767 Post by Argolance »

Bonsoir,

Code: Select all

--command="yad --text-info --filename=/root/my-documents/clipart/README-clipart.txt"

Code: Select all

--command="bash -c 'echo "Works" | yad --text-info'"
Both do the job. Thanks!

Cordialement.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#768 Post by vovchik »

Dear all,

What about this for self-contained animation?

Code: Select all

#!/bin/bash

A_ICON="/tmp/alarm1a.svg"
B_ICON="/tmp/alarm1b.svg"
C_ICON="/tmp/alarm1c.svg"
TOOLTIP="Alarm is running in the background...
Click this icon and you will see a text box..." 
MSG="It works!!!"
COL="red"
if [ ! -e "$A_ICON" ]; then
	SVG="<""svg width='22' height='22' viewBox='0 0 100 100'>
		<mask id='mask_circle'>
		  <circle cx='50' cy='50' r='50' fill='white'/>
		  <circle cx='50' cy='50' r='12' fill='gray'/>
		</mask>
		<linearGradient x1='20' y1='60' x2='60' y2='40' id='lg' 
		 gradientUnits='userSpaceOnUse'>
		  <stop style='stop-color:dark$COL;stop-opacity:1' offset='0'/>
		  <stop style='stop-color:$COL;stop-opacity:1' offset='1'/>
		</linearGradient>
	  <circle cx='50' cy='50' r='28%' style='fill:dark$COL'/>
	  <circle cx='50' cy='50' r='23%' style='fill:url(#lg);
	   stroke:gray;stroke-width:3'/>
	</svg>"
   echo "$SVG" > $A_ICON
   SVG=$(echo "$SVG" | sed 's/28%/38%/g' | sed 's/23%/33%/g')
   echo "$SVG" > $B_ICON
   SVG=$(echo "$SVG" | sed 's/38%/48%/g' | sed 's/33%/43%/g')
   echo "$SVG" > $C_ICON
fi
while true; do 
	echo 'icon:'$A_ICON; 
	sleep 0.25; 
	echo 'icon:'$B_ICON; 
	sleep 0.25; 
	echo 'icon:'$C_ICON; 
	sleep 0.25; 
	echo 'icon:'$B_ICON; 
	sleep 0.25; 
done | yad \
--notification \
--icon-size=20 \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="$TOOLTIP" \
--command="bash -c 'echo $MSG | yad --title=\"Alarm box\" \
--window-icon=\"$C_ICON\" \
--text-info'" &
XPID=$!
# select timeout in seconds
sleep 20
kill $XPID
With kind regards,
vovchik

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

#769 Post by misko_2083 »

Argolance wrote:Bonjour,
misko_2083 is like Lucky Luck, he shoots faster than his shadow 8)
Watch out Dalton brothers. ;)

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#770 Post by Argolance »

Bonsoir,
vovchik wrote:What about this for self-contained animation?
Wow, very skilful/impressive! :o

Cordialement.

Post Reply