Using YAD Simple Progress Bar

interpretive language scripts


Moderator: Forum moderators

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

wizard wrote: Sat Feb 22, 2025 2:33 pm

Will it accurately gauge the running process completion?

No. It's just a bit of animation. But you could also have it show the elaspsed time like with the Timer widget. This needs the gtk3 version of Xdialog to work correctly.

Code: Select all

XdialogGauge ()
{
mkfifo /tmp/TimerPipe 2>/dev/null
exec 7<>/tmp/TimerPipe
SEC=0; FULLSEC=0; DIR=1
while : ; do
 echo $((SEC*10))
 echo -e "XXX\nWorking ... $FULLSEC sec\nXXX"
 read -u 7 -t 1 && break
 ((FULLSEC++))
 ((SEC+=DIR))
 [ $((SEC%10)) -eq 0 ] && ((DIR*=-1))
done | Xdialog --no-buttons --title " " --gauge "Working ..." 4 30 0
}
export -f XdialogGauge

XdialogGauge &
sleep 35 #put commands here
echo > /tmp/TimerPipe
User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

FWIW, here are two "Working..." timer widgets based on yad. They use the --auto-close option to make them terminate cleanly without needing to be killed.

Code: Select all

#!/bin/bash

YadSecTimer ()
{
mkfifo /tmp/TimerPipe 2>/dev/null
exec 7<>/tmp/TimerPipe
SEC=0; FULLSEC=0; DIR=1
while : ; do
 [ $SEC -eq 10 ] && echo 99 || echo $((SEC*10))
 echo "#$FULLSEC sec"
 read -u 7 -t 1 && echo 100 && break
 ((FULLSEC++))
 ((SEC+=DIR))
 [ $((SEC%10)) -eq 0 ] && ((DIR*=-1))
done | yad --center --progress \
  --text="Working ..." \
  --width=200 \
  --height=70 \
  --no-buttons \
  --auto-close
}
export -f YadSecTimer

YadMinTimer ()
{
mkfifo /tmp/TimerPipe 2>/dev/null
exec 7<>/tmp/TimerPipe
SEC=0; MIN=0
while : ; do
 [ $SEC -eq 60 ] && echo 99 || echo $((SEC*10/6))
 echo "#$MIN min $SEC sec"
 read -u 7 -t 1 && echo 100 && break
 ((SEC++))
 [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
done | yad --center --progress \
  --text="Working ..." \
  --width=200 \
  --height=70 \
  --no-buttons \
  --auto-close
}
export -f YadMinTimer

YadSecTimer &
sleep 25  #put commands here
echo > /tmp/TimerPipe
echo done

YadMinTimer &
sleep 80  #put commands here
echo > /tmp/TimerPipe
echo done
User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

Here is a yad countdown timer widget.

xscreenshot-20250303T144844.png
xscreenshot-20250303T144844.png (10.12 KiB) Viewed 328 times

Code: Select all

#!/bin/bash

YadCountDown ()
{
[ $# -ne 2 ] && exit
MESSAGE=$1; WAIT=$2
for ((SEC=$WAIT; SEC >= 0; SEC--)); do
  [ $SEC -eq $WAIT ] && echo 99 || echo $((SEC*100/$WAIT))
  echo "#$SEC"
  sleep 1
done | yad --center --progress \
  --text="$MESSAGE" \
  --width=300 \
  --height=70 \
  --button=OK:1 \
  --auto-close
}
export -f YadCountDown

YadCountDown "Click the button within 10s" 10   #don't background this
REPLY=$?
case $REPLY in
  0) echo "Button not clicked"
     ;; #do stuff
  1) echo "Button clicked"
     ;; #do other stuff
  252) echo "Cancelled" ;;
esac
Post Reply

Return to “Scripts”