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
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#736 Post by misko_2083 »

rufwoof wrote:This will do the same using yad, with the button labels you prefer. Just modify the SHUTDOWNCOMMAND to actually run your shutdown command instead of running geany

Code: Select all

#!/bin/bash

SHUTDOWNCOMMAND=geany

(  echo "99" ; sleep 1
   echo "90" ; sleep 1
   echo "80" ; sleep 1
   echo "70" ; sleep 1
   echo "60" ; sleep 1
   echo "50" ; sleep 1
   echo "40" ; sleep 1
   echo "30" ; sleep 1
   echo "20" ; sleep 1
   echo "10" ; sleep 1 ) |
  yad --progress --title="$TITLE $VERSION" --text=" Are you sure you want to shutdown? \n\n Turning off computer in 10 seconds \n\n Press Cancel to abort shutdown " \
  --percentage=0 --auto-close --auto-kill --button=CANCEL:1 --button=SHUTDOWN:0
[[ $? -eq 0 ]] && $SHUTDOWNCOMMAND
Thanks but after 3.0 the progress bar no longer works.
So many changes as the newer versions are not backward compatible. No gtk-icons support, right-click notification menu no longer works, entry is deprecated...
It's in quiet unstable now. Probably even more stuff will be removed when the old obsolete code derived from zenity is removed.

stemsee

#737 Post by stemsee »

Standalone yad based simple-savefile-creator (mksavefile.sh)

Code: Select all

#!/bin/sh
#
export PROG=$(basename $0)
running=`ps -e | grep -w "$PROG" | wc -l`
[[ "$running" -gt 2 ]] && exit  # run only one instance
deps=`busybox which yad`
[[ -f /etc/DISTRO_SPECS ]] && . /etc/DISTRO_SPECS
if [[ ! -z "$deps" ]]; then
	all=`yad --center --on-top --width=500 --title="Simple-Savefile-Creator" --form --item-separator=" " --field=Size:CBE "512 1024 1534 2048" --field=Filesystem:CBE "ext4 ext2 ext3" --field=ByteSize:CBE "1024 512 64" --field=Name:CBE "changes live-rw fd64save ${DISTRO_FILE_PREFIX}save qsave." --field=Path1:CBE "mnt media" --field=Path2:CBE "sda1 mmcblk0p1 sdb1" --field=Path3:CBE "casper fatdog upupbb Slacko64 EasyOS Quirky"`
	size=`echo $all | cut -f1 -d'|'`
	fs=`echo $all | cut -f2 -d'|'`
	bs=`echo $all | cut -f3 -d'|'`
	savefile=`echo $all | cut -f4 -d'|'`
	Path1=`echo $all | cut -f5 -d'|'`
	PAth2=`echo $all | cut -f6 -d'|'`
	PATh3=`echo $all | cut -f7 -d'|'`
	if [[ "$savefile" == changes* ]]; then
	 savefile="${savefile}.dat"
	elif [[ "$savefile" == fd64save* ]]; then
	 savefile="${savefile}.${fs}"
	elif [[ "$savefile" == $DISTRO_FILE_PREFIX* ]]; then
	 savefile="${savefile}save.`echo $fs | cut -c4`fs"
	fi

fi
if [ -z $(busybox which gxmessage) ]; then
	MESSAGE=xmessage
else
	MESSAGE=gxmessage
fi
[[ -f /tmp/missdeps ]] && rm -f /tmp/missdeps
# check paths....
[[ -z "$deps" ]] && echo "yad was not found" >> /tmp/missdeps
[[ ! -d "/$Path1" ]] && echo "directory /$Path1 not found" >> /tmp/missdeps
[[ -z `mount | grep "$PAth2"` ]] && echo "$PAth2 is not mounted" >> /tmp/missdeps
[[ ! -d "/${Path1}/${PAth2}/$PATh3" ]] && echo "directory not found /${Path1}/${PAth2}/$PATh3" >> /tmp/missdeps
[[ -f "/${Path1}/${PAth2}/$PATh3/$savefile" ]] && echo "/${Path1}/${PAth2}/$PATh3/$savefile already exists !!" >> /tmp/missdeps
missing=`cat /tmp/missdeps`
[[ ! -z "$missing" ]] && $MESSAGE -center "This part of the PATH is problematic
$missing

" -fore black -back green -timeout 6
[[ ! -z "$missing" ]] && exit
yad --center --on-top --text="Does this look right?
		dd if=/dev/zero of=/${Path1}/${PAth2}/${PATh3}/$savefile bs=${bs}k count=$size
		mkfs -t $fs -q -m 0 -F /${Path1}/${PAth2}/${PATh3}/$savefile
"
ret=$?
case $ret in
0) yad --listen --progress --text="Creating Savefile \nPlease Wait" --pulsate --no-buttons --on-top --undecorated --width=200 --height=140 --center &
export prog=$!
dd if=/dev/zero of=/${Path1}/${PAth2}/${PATh3}/$savefile bs=${bs}k count=${size}
mkfs -t $fs -q -m 0 -F /${Path1}/${PAth2}/${PATh3}/$savefile
chmod a+rw /${Path1}/${PAth2}/${PATh3}/$savefile
fsck -M -C -a -l /${Path1}/${PAth2}/${PATh3}/$savefile
kill $prog
[[ ! -z `du -h /${Path1}/${PAth2}/${PATh3}/$savefile | grep "$size"` ]] && yad --text="Savefile creation completed" --timeout=2 --center --no-buttons --undecorted --skip-taskbar --on-top
[[ -z `du -h /${Path1}/${PAth2}/${PATh3}/$savefile | grep "$size"` ]] && yad --text="Savefile creation incomplete" --timeout=2 --center --no-buttons --undecorted --skip-taskbar --on-top;;
1) exit;;
*) exec $0 &
exit;;
esac

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

#738 Post by MochiMoppel »

misko_2083 wrote:Bit off topic
Way off topic :lol: , but that's OK. Gives me a good excuse for throwing in another solution .... with Xdialog (we don't have a dedicated thread, do we?)

Xdialog's infobox can be configured to work similar to yad's text-info. Though it accepts only one button and the syntax is a bit weird it is simple and can be quite useful:

Code: Select all

for i in {5..0}; do
	echo  XXX
	echo "Turning off computer in $i seconds"
	echo XXX
	sleep 1
done | Xdialog --cancel-label "Abort shutdown"  -infobox "" 300x100 0
(($?)) && exit
Xdialog  -infobox "Continue now with shutdown commands" 300x100 4000
Attachments
Screenshot.png
(4.63 KiB) Downloaded 750 times

stemsee

#739 Post by stemsee »

How close can yad get to immitating a terminal? or swallowing one?

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

#740 Post by misko_2083 »

MochiMoppel wrote:
misko_2083 wrote:Bit off topic
Way off topic :lol: , but that's OK. Gives me a good excuse for throwing in another solution .... with Xdialog (we don't have a dedicated thread, do we?)
Aww, I lost the bet. I was betting on Fred the Netherlandian to be the first one to go off topic. :lol:
That's very minimal solution.
stemsee wrote:How close can yad get to immitating a terminal? or swallowing one?
Why reinventing the hot water? :)
Bobby Copper aka YadBashBobby had that idea.
https://www.youtube.com/watch?v=stPAWGXQyLY
Haven't seen him on the forums for a long time.

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 100 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.

Post Reply