Skip to content

Commit

Permalink
EasyBashGUI with notify functions and an improuved notify message.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaisarger committed Nov 16, 2019
1 parent eed9ef4 commit f9a109b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 43 deletions.
8 changes: 4 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ question -> "[text]" => ( 1 argument, box output to exit c
message -> "[text]" => ( 1 argument )
alert_message -> "[text]" => ( 1 argument )
ok_message -> "[text]" => ( 1 argument )
notify_message -> "[text]" => ( 1 argument )
notify_message -> <-i "[icon]"> "[text]" => ( 1 option, 1 argument )
text => ( STDIN, NO argument, box output to "${dir_tmp}/${file_tmp}" and STDERR ) (^)
wait_seconds -> "[integer]" => ( 1 argument )
wait_for -> "[text]" => ( 1 argument, PID to kill to "wait_for__PID" variable and STDERR ) (@)
Expand All @@ -113,8 +113,8 @@ list -> <+|->"[item 1]" ... <+|->"[item n]" => ( [n] arguments, optiona
progress -> "[text]" => ( percent with or without '%' in STDIN, 1 argument )
progress -> "[text]" "[elements number]" => ( "PROGRESS" string in STDIN, 2 arguments )
adjust -> "[text]" "[min]" "[init]" "[max]" => ( 4 arguments, box output to "${dir_tmp}/${file_tmp}" and STDERR )
notify -> <-c "[click command (for mouse left button)]"> <-i "[icon_good]#[icon_bad]"> <-t "[tooltip_good]#[tooltip_bad]"> "[menu item 1]" "[menu command 1]" ... "[menu item n]" "[menu command n]" => ( [n*2] arguments )
notify_change -> "[good|bad]" => ( 1 argument )
notify -> <-c "[click command (for mouse left button)]"> <-i "[icon_good]#[icon_bad]"> <-t "[tooltip_good]#[tooltip_bad]"> "[menu item 1]" "[menu command 1]" ... "[menu item n]" "[menu command n]" => ( 3 options, [n*2] mandatory arguments )
notify_change -> <-i "[new icon]"> <-t "[new tooltip]"> "[good|bad]" => ( 2 options, 1 mandatory argument )


(*) = "0" exit status is "YES", "1" exit status is "NOT", other exit codes you should make program exit : normally in a script you have just to check exit status to know user choice ;
Expand Down Expand Up @@ -204,7 +204,7 @@ while :
elif [ "${answer}" = "BAD" ]
then
notify_message "Changed in \"bad\" ..."
notify_change "bad"
notify_change -i "gtk-help" -t "This tooltip is bad" "bad"
else
exit
fi
Expand Down
146 changes: 111 additions & 35 deletions lib/easybashgui.lib
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#####################################
#####################################
#
LIB_VERSION="12.0.2"
LIB_VERSION="12.0.3"
LIB_NAME="easybashgui.lib"
LIB_URL="https://github.com/BashGui/easybashgui"
LIB_AUTHOR="Vittorio Cagnetta"
Expand Down Expand Up @@ -495,15 +495,14 @@ fi
###############
#
export notify_send_seconds=4
export notify_check_loop_seconds=5
#
export notify_icon_default="gtk-stop"
export notify_icon_default="gtk-execute"
export notify_icon_good="gtk-home"
export notify_icon_bad="gtk-help"
#
export notify_tooltip_default="${0##*/}-> starting..."
export notify_tooltip_good="${0##*/}-> ok"
export notify_tooltip_bad="${0##*/}-> bad!"
export notify_tooltip_default="${supertitle} -> starting..."
export notify_tooltip_good="${supertitle} -> OK"
export notify_tooltip_bad="${supertitle} -> BAD"
#
notify_send="NO"
esistenza_notify_send="$(type 'notify-send' 2> /dev/null )"
Expand Down Expand Up @@ -900,9 +899,9 @@ if [ "${yad}" = "SI" ]
unset icons
unset tooltips
#
while getopts ":c:i:t:" function_options
while getopts ":c:i:t:" notify_function_options
do
case ${function_options} in
case ${notify_function_options} in
#
c ) export click_command="${OPTARG}" ;;
i ) export icons="${OPTARG}" ;;
Expand Down Expand Up @@ -959,7 +958,7 @@ if [ "${yad}" = "SI" ]
done )"
local IFS=$' \t\n'
#
notify_menu=" ${supertitle}${notify_items}|-> Quit!quit"
notify_menu=" ${supertitle}|${notify_items}|-> Quit!quit"
#
##
#
Expand Down Expand Up @@ -989,7 +988,7 @@ if [ "${yad}" = "SI" ]
# add handler for tray icon left click...
notify_on_click()
{
echo "tooltip:${0##*/}-> wait..." 1> "${ebg_PIPE}"
echo "tooltip:${0##*/} -> wait..." 1> "${ebg_PIPE}"
#
if [ ${#click_command} -eq 0 ]
then
Expand Down Expand Up @@ -1028,7 +1027,7 @@ if [ "${yad}" = "SI" ]
#
###
#
# notify_change "[good|bad]"
# notify_change <-i "[new_icon]"> <-t "[new_tooltip]"> "[good|bad]"
#
notify_change()
{
Expand All @@ -1038,20 +1037,52 @@ if [ "${yad}" = "SI" ]
[ ${#ebg_PIPE} -eq 0 ] && break
[ ! -e "${ebg_PIPE}" ] && break
#
unset new_icon
unset new_tooltip
#
unset OPTIND
while getopts ":i:t:" notify_change_function_options
do
case ${notify_change_function_options} in
#
i ) export new_icon="${OPTARG}" ;;
t ) export new_tooltip="${OPTARG}" ;;
#
esac
done
shift $((OPTIND-1))
#
##############################
#
notify_change_how="${1}"
[ ${#notify_change_how} -eq 0 ] && notify_change_how="bad"
#
##############################
#
if [ "${notify_change_how}" = "good" -o "${notify_change_how}" = "GOOD" ]
then
#
echo "icon:${notify_icon_good}"
echo "tooltip:${notify_tooltip_good}"
###
[ ${#new_icon} -gt 0 ] && notify_change_icon="${new_icon}" || notify_change_icon="${notify_icon_good}"
echo "icon:${notify_change_icon}"
#
[ ${#new_tooltip} -gt 0 ] && notify_change_tooltip="${new_tooltip}" || notify_change_tooltip="${notify_tooltip_good}"
echo "tooltip:${notify_change_tooltip}"
###
#
elif [ "${notify_change_how}" = "bad" -o "${notify_change_how}" = "BAD" ]
then
#
echo "icon:${notify_icon_bad}"
echo "tooltip:${notify_tooltip_bad}"
###
[ ${#new_icon} -gt 0 ] && notify_change_icon="${new_icon}" || notify_change_icon="${notify_icon_bad}"
echo "icon:${notify_change_icon}"
#
[ ${#new_tooltip} -gt 0 ] && notify_change_tooltip="${new_tooltip}" || notify_change_tooltip="${notify_tooltip_bad}"
echo "tooltip:${notify_change_tooltip}"
###
#
else
#
return 1
#
fi 1> "${ebg_PIPE}"
#
Expand Down Expand Up @@ -1357,54 +1388,99 @@ fi
# question()
#
##
#
# notify_message()
[ "${mode}" = "dialog" ] && notify_send="NO"
[ "${mode}" = "dialog" ] && export notify_send="NO"
# notify_message <-i [icon]> "text"
if [ "${notify_send}" = "SI" ]
then
notify_message()
{
local FUNCT_NAME="notify_message"
local IFS=$' \t\n'
#
notify_message_text="${@}"
unset notify_message_icon
#
unset OPTIND
while getopts ":i:" notify_change_function_options
do
case ${notify_change_function_options} in
#
i ) export notify_message_icon="${OPTARG}" ;;
#
esac
done
shift $((OPTIND-1))
#
##############################
#
export notify_message_text="${@}"
#
##############################
#
notify_send_milliseconds=$(( ${notify_send_seconds} * 1000 ))
notify-send -t ${notify_send_milliseconds} -a "${0##*/}" -i "${notification_icon_default}" "${notify_message_text}"
[ ${#notify_message_icon} -gt 0 ] && : || notify_message_icon="${notify_icon_default}"
#
notify-send -t ${notify_send_milliseconds} -a "${supertitle:-EasyBashGUI}:" -i "${notify_message_icon}" "${notify_message_text}"
#
}
elif [ "${notify_send}" = "NO" ]
then
#
notify_message_alt()
{
wait_for "\n\n${notify_message_text}\n\n\n\n(Please, install \"kdialog\" or \"notify-send\" for a nicer notification)\n\n."
sleep ${notify_send_seconds}
terminate_wait_for
}
#
notify_message()
{
local FUNCT_NAME="notify_message"
local IFS=$' \t\n'
#
unset notify_message_icon
#
unset OPTIND
while getopts ":i:" notify_change_function_options
do
case ${notify_change_function_options} in
#
i ) export notify_message_icon="${OPTARG}" ;;
#
esac
done
shift $((OPTIND-1))
#
##############################
#
export notify_message_text="${@}"
#
##############################
#
[ ${#notify_message_icon} -gt 0 ] && : || notify_message_icon="${notify_icon_default}"
#
if [ "${mode}" = "dialog" ]
then
#
wait_for "${notify_message_text}"
wait_for "\n${notify_message_text}"
sleep ${notify_send_seconds}
terminate_wait_for
#
elif [ "${mode}" != "dialog" ]
then
notify_dummy_var="$(
if [ "${kdialog}" = "SI" ]
then
export supermode=kdialog
fi
#
source easybashgui
#
wait_for "${notify_message_text}\n\n\n\n(Please install \"notify-send\" for a nicer notification)"
sleep ${notify_send_seconds}
terminate_wait_for
#
clean_temp
)" &>/dev/null &
if [ "${kdialog}" = 'SI' ]
then
#
:
kdialog --icon "${notify_message_icon}" --passivepopup "${supertitle:-EasyBashGUI}:\n\n${notify_message_text}" ${notify_send_seconds}
#
else
#
:
notify_message_alt &
#
fi
#
fi
#
}
Expand Down
2 changes: 1 addition & 1 deletion lib/easybashlib
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ ebg_on_exit()
#echo -e "Bye!" 1>&2
#
# Hint: Scripts that fork should start with "ebg_on_exit $0 killtree $BASHPID", to clean up child
# processes. (Also remember to kill all disowned proceses if appropriate.)
# processes. (Also remember to kill all disowned processes if appropriate.)
#
#echo "Exiting. .........DEBUG" 1>&2
eb_debug_output "Exiting."
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#EBGlib=$(wildcard easybashgui_[0-9].[0-9].[0-9])
VERSION=12.0.2
VERSION=12.0.3

#cartelle di destinazione
DESTDIR ?= ""
Expand Down
2 changes: 1 addition & 1 deletion src/easybashgui
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# something like if [ -e $(eb_incl__absolute_path)/$module_*.*.* ] ?
#
###################################################################
MODULE_VERSION="12.0.2"
MODULE_VERSION="12.0.3"
MODULE_NAME="easybashgui"
libexec_dir="/usr/lib/easybashgui"
###################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/easybashgui-debug
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# something like if [ -e $(eb_incl__absolute_path)/$module_*.*.* ] ?
#
###################################################################
MODULE_VERSION="12.0.2"
MODULE_VERSION="12.0.3"
MODULE_NAME="easybashgui-debug"
###################################################################
#
Expand Down

0 comments on commit f9a109b

Please sign in to comment.