Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 29 Jan 2020, 00:47
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 52 of 56 [837 Posts]   Goto page: Previous 1, 2, 3, ..., 50, 51, 52, 53, 54, 55, 56 Next
Author Message
fredx181


Joined: 11 Dec 2013
Posts: 4261
Location: holland

PostPosted: Thu 28 Nov 2019, 14:23    Post subject:  

Argolance wrote:
misko_2083 is like Lucky Luck, he shoots faster than his shadow Cool

Laughing 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 !
Quote:
Regarding this script, how to make:
Code:
yad --text-info="Doesn't work"

Pipe the text to yad --text-info ?
Code:
echo "Works" | yad --text-info


EDIT: also:
Code:
yad --text-info --filename=/root/my-documents/clipart/README-clipart.txt


EDIT2: Regarding echo "Works" | yad --text-info
Code:
 --command="bash -c 'echo "Works" | yad --text-info'"

should do

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3732
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 28 Nov 2019, 18:30    Post subject:  

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

Code:
--command="bash -c 'echo "Works" | yad --text-info'"

Both do the job. Thanks!

Cordialement.

_________________

A second life for your PCs...
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1515
Location: Ukraine

PostPosted: Fri 29 Nov 2019, 07:02    Post subject:  

Dear all,

What about this for self-contained animation?

Code:
#!/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
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 101

PostPosted: Fri 29 Nov 2019, 12:00    Post subject:  

Argolance wrote:
Bonjour,
misko_2083 is like Lucky Luck, he shoots faster than his shadow Cool

Watch out Dalton brothers. Wink
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3732
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Fri 29 Nov 2019, 13:43    Post subject:  

Bonsoir,
vovchik wrote:
What about this for self-contained animation?

Wow, very skilful/impressive! Surprised

Cordialement.

_________________

A second life for your PCs...
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4261
Location: holland

PostPosted: Fri 29 Nov 2019, 15:43    Post subject:  

vovchik wrote:
What about this for self-contained animation?

Thanks very much vovchik ! Great stuff ! (as always Very Happy )

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4261
Location: holland

PostPosted: Fri 29 Nov 2019, 18:53    Post subject:  

Hi all, here's new alarm script (2 slightly different), changes:
- Using preferences file ~/.yalrm
(remembering now most previously used settings for next time run)
- Supports now setting the alarm for next day, same hour (previously didn't work) (but gives prompt 'Are you sure' yes/no in case accidentally set)
- Display of tray icon as long as waiting for the alarm to go off (thanks Argolance and vovchik Smile )
TODO maybe: Multiple alarms can be set, but, as it is now, everytime a new tray icon appears, better only one icon but tooltip and message when left click changed when setting new alarm

First script: depends on the 4 icons Argolance attached here: http://murga-linux.com/puppy/viewtopic.php?p=1042989#1042989
Extract and make sure they are in /root, e.g. '/root/alarm_1.png', '/root/alarm_2.png' etc..
Code:
#!/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
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

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
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=/root/alarm_4.png --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
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 --auto-kill --no-middle --listen --text="Alarm is running in the background...
Set to $hr:$mn" --command="bash -c command" &
export XPID=$!
}; export -f show_icon

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" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
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 ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

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" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur: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


Second script contains the icon setup for yad --notification that vovchik provided (self containing), for the rest it's the same as above.
Code:
#!/bin/bash

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
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

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

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
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
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 \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
XPID=$!
}; export -f show_icon

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" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
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 ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

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" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur: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

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1515
Location: Ukraine

PostPosted: Sat 30 Nov 2019, 04:59    Post subject:  

Dear Fred,

Great work. Works nicely on my setup, and it is useful. Very nice coding., too Smile The only thing missing, and pretty easy to add, is tooltips for the widgets (e.g. duration, interval).

Thanks for this little gem.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4261
Location: holland

PostPosted: Sat 30 Nov 2019, 06:18    Post subject:  

Thanks vovchik !
Quote:
The only thing missing, and pretty easy to add, is tooltips for the widgets (e.g. duration, interval).

I have no idea how, isn't that only supported for buttons ?

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1515
Location: Ukraine

PostPosted: Sat 30 Nov 2019, 08:10    Post subject:  

Dear Fred,

You are right. I don't really know how (yet). In c and gtkdialog you can do that by setting a widget's properties. With yad, it's a different story. Maybe there is a way. Time to look at the manual and other people's code, I guess. Smile

With kind regards,
vovchik
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 101

PostPosted: Sat 30 Nov 2019, 08:21    Post subject:  

Fredx, If you move the current time to the window title bar, can you think of anything that you would use the first tab for?

Code:
#!/bin/bash

win_class="timer_class"
TITLE="Alarm - Current Time"

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
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

function change_title {
local yad_xid

# need some time to register window class with X
while [[ ${yad_xid} == "" ]]; do
   # get Xwindow id
   yad_xid="$(wmctrl -lx | grep -e "yad.${win_class}" |  grep -oE "[0-9a-z]{10}")"
done

# convert to decimal number
yad_xid="$(echo $((${yad_xid})))"

while true
 do
   wmctrl -i -r "${yad_xid}" -N "$TITLE : $(date '+%T')" 2>/dev/null || break
   sleep 1
done
}


alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

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
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
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 \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
XPID=$!
}; export -f show_icon

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" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
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 ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

# Keep changing the title to current time
change_title &

while :
do
  echo "What to do with this tab?"
  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" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --class="${win_class}" --center --title="$TITLE : $(date '+%T')" --paned --key="$$" --orient=vert --no-buttons
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3732
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sat 30 Nov 2019, 09:45    Post subject:  

Hello,
I had fun internationalizing the first version.... Maybe a little too soon? The same thing can be done for the second one!
I think a right click menu to let user stop a running alarm process would be useful...

EDIT 1: I added a configuration directory /root/.yarlm automatically built at startup and a configuration file inside called "prefs". May be a conflict between the "old" configuration file with the directory (same name).
I forgot the desktop file. Confused
EDIT 2: The file "/usr/share/audio/2barks.wav" may be the defautl sound file?
aplay as player?
a button to quit the gui?

Cordialement.
191130_143943_629x168_easyshot.jpg
 Description   
 Filesize   14.88 KB
 Viewed   173 Time(s)

191130_143943_629x168_easyshot.jpg

set_alarm-191130.pet
Description 
pet

 Download 
Filename  set_alarm-191130.pet 
Filesize  5.22 KB 
Downloaded  23 Time(s) 

_________________

A second life for your PCs...

Last edited by Argolance on Sat 30 Nov 2019, 11:44; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1515
Location: Ukraine

PostPosted: Sat 30 Nov 2019, 10:47    Post subject:  

Dear misko_2083 and fred and argolance,

I like the idea of the current time in the window bar. As for the empty area, what about a checkbox (relative time) and spinbox for relative time-setting (i.e. in fifteen mintues)?

With kind regards,
vovchik
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3732
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sat 30 Nov 2019, 11:48    Post subject:  

vovchik wrote:
I like the idea of the current time in the window bar.

Me too, but not static time: so I am not sure it is possible!
Quote:
As for the empty area, what about a checkbox (relative time) and spinbox for relative time-setting (i.e. in fifteen mintues)?

Sorry, I do not understand what you mean... Embarassed

Cordialement.

_________________

A second life for your PCs...
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4261
Location: holland

PostPosted: Sat 30 Nov 2019, 13:15    Post subject:  

Here's again new alarm script with some basic changes (a fix and new addition).
(didn't add any of the above suggestions (yet), will reply about it later)
- Fixed that still the process ID of the script was left after closing the GUI
- Added (right-click) menu to tray icon, with choice of:
-- "Cancel Alarm and Exit tray"
-- "Exit tray only"
Which are important choices IMO as a user should be able to cancel the alarm or to exit the tray icon (without canceling the alarm, btw) (the icon is consuming some CPU)

This is the version with the yad --notification setup by vovchik , which I prefer because it's self containing:
Code:
#!/bin/bash

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
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

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

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
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

cancel_quit_tray () {
kill $(cat /tmp/yalrm_apid 2> /dev/null)
kill $(cat /tmp/yalrm_xpid 2> /dev/null)
}; export -f cancel_quit_tray

quit_tray () {
kill $(cat /tmp/yalrm_xpid 2> /dev/null)
}; export -f quit_tray

show_icon () {
(
echo menu:"Cancel Alarm and Exit tray!bash -c cancel_quit_tray!gtk-quit|Exit tray only!bash -c quit_tray!gtk-quit"
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 \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
export XPID=$!
echo $XPID > /tmp/yalrm_xpid
}; export -f show_icon

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" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
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 ALPID=$!
echo $ALPID > /tmp/yalrm_apid
wait $ALPID
}; 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 ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

while :
do
  date +"%H":"%M":"%S"
pidyad="$(pgrep -lf "yad --plug=$$" | awk '{ print $1 }')"
[ -z "$pidyad" ] && break
  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" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur: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

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 52 of 56 [837 Posts]   Goto page: Previous 1, 2, 3, ..., 50, 51, 52, 53, 54, 55, 56 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0990s ][ Queries: 12 (0.0057s) ][ GZIP on ]