YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#741 Post by fredx181 »

misko_2083 wrote: Aww, I lost the bet. I was betting on Fred the Netherlandian to be the first one to go off topic. :lol:
Me ??? I would never forgive myself, I'm not like you, bad guys ! :lol:
How close can yad get to immitating a terminal? or swallowing one?

Why reinventing the hot water? Smile
Bobby Copper aka YadBashBobby had that idea.
Can't find Bobby's script anywhere, Maybe he removed it because it didn't work well ? :?: .

Fred

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

#742 Post by misko_2083 »

fredx181 wrote:
misko_2083 wrote: Aww, I lost the bet. I was betting on Fred the Netherlandian to be the first one to go off topic. :lol:
Me ??? I would never forgive myself, I'm not like you, bad guys ! :lol:
Don't know about MochiMopel but I'm terrible.
I even recommended Debian Administrator's Guide to a certain "dev" in a systemd related thread. :)
fredx181 wrote:
How close can yad get to immitating a terminal? or swallowing one?

Why reinventing the hot water? Smile
Bobby Copper aka YadBashBobby had that idea.
Can't find Bobby's script anywhere, Maybe he removed it because it didn't work well ? :?: .

Fred
After some deep search.
Who knows where is the script. Didn't find it on either github or gitlab.
Maybe he keeps his repos private on gitlab.
Found a few forum posts but the script nowhere.

stemsee

#743 Post by stemsee »

I finally understand how to get yad --progress working! (I'm slow! ok)
And also how to see the full 100%

Code: Select all

export d=0; ( sleep 0.5; while [[ $d -lt 1024 ]]; do  d=$((d+10)); echo $d; sleep 0.1; done ) | yad --progress --percentage=$d --timeout=$((d+1)) --no-buttons --undecorated --progress-text="testing"
of course sleep integer could be a variable for a file size check. And also the -lt 1024 could be the total filesize in a variable.

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

#744 Post by step »

Tip: avoid using option --auto-kill because it is too easy to end up killing the whole system by mistake.
[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]

stemsee

#745 Post by stemsee »

step wrote:Tip: avoid using option --auto-kill because it is too easy to end up killing the whole system by mistake.
oh! I didn't know that :shock:

count files as %, and file name as progress text

Code: Select all

cnt=0;tot=$(for i in $(ls /usr/sbin); do cnt=$((cnt + 1)); done; echo $cnt); for i in $(ls /usr/sbin); do echo "#$i"; cnt=$((cnt+1)); echo $((cnt*100/tot)); sleep 0.1; done | yad --progress --auto-close --undecorated --no-buttons

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

#746 Post by step »

stemsee wrote:
step wrote:Tip: avoid using option --auto-kill because it is too easy to end up killing the whole system by mistake.
oh! I didn't know that :shock:
Don't take me wrong; it isn't that yad kills the whole system on purpose. It is that --auto-kill and the similar --kill-parent options give your code the means to take the system down if your code isn't very careful. If specified, these two options will send a kill signal to the process that is the yad's parent **at the time** the yad dialog closes itself or is closed. Now, ask yourself if your code is designed to always know which is its **current** parent process. In the case of an orphaned yad dialog, its parent process becomes the init process, and when you close the dialog init is killed -- most likely not what your code intended to do - and the system will go down.
[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]

stemsee

#747 Post by stemsee »

Thanks for the explanation step ... in fact I have never used --auto-kill .

Competition

who can come up with the code which generates a yad progress bar that starts and ends at the same point as the mksquashfs command!

I did a couple, but sometimes the mksquashfs progress races ahead, while the yad (measuring the created .sfs size) moves steadily.

What is mksquashfs progress actually counting? here is my closest effort.
first start mksquashfs fs in one term.

Code: Select all

 mksquashfs /mnt/sdc3/lap/stems-apps /mnt/sdc3/lap/stems-app.sfs -comp xz
then in another term

Code: Select all

tot=$(du -k /mnt/sdc3/lap/stems-apps | tail -1 | awk '{print $1}'); while sleep 1; do size=$(du -k /mnt/sdc3/lap/stems-appp.sfs | awk '{print $1}'); perc=$((size * 88 / (tot/4))); echo "$size"; echo $perc; done | yad --progress --percentage=0 --progress-text=""
 
I could not use --auto-close because 100% is frequently reached as mksquashfs rewrites the .sfs file on disk.
Attachments
xscreenshot-20191020T124939.png
(16.6 KiB) Downloaded 430 times
xscreenshot-20191020T125103.png
(14.95 KiB) Downloaded 432 times
xscreenshot-20191020T125337.png
(14.29 KiB) Downloaded 459 times
xscreenshot-20191020T125418.png
(13.3 KiB) Downloaded 444 times
Last edited by stemsee on Tue 22 Oct 2019, 09:11, edited 1 time in total.

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

#748 Post by fredx181 »

Hi stemsee, maybe this can help ?
http://murga-linux.com/puppy/viewtopic.php?t=111674
But I think finally it turned out that Xdialog is more suitable than yad for this.

Fred

stemsee

#749 Post by stemsee »

Thanks Fred

I got the yad version working well!

cheers
stemsee

EDIT: improved
Attachments
dir2sfs.gz
(2.13 KiB) Downloaded 105 times
xscreenshot-20191021T200553.png
(6.56 KiB) Downloaded 392 times

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

#750 Post by misko_2083 »

Image
It's working.
https://www.youtube.com/watch?v=cwJMRKAQAMU
That is html and forms in an undecorated paned dialog.

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.

Post Reply