site  contact  subhomenews

gtkdialog-splash

June 01, 2010 — BarryK
This is great! Forum member 'mave' has created this:

http://www.murga-linux.com/puppy/viewtopic.php?t=55837&start=30

I couldn't resist doing some work on it... to make it a bit more complete, so it can be a drop-in replacement for yaf-splash in Puppy. I added the '-placement' option. Yaf-splash closes on a mouse-click, but I couldn't get that to work, so I set it to default close on a mouse-over -- then I added the '-close' option (not in yaf-splash):

gtkdialog-splash


an easy splash - possible replace for yaf-splash in Lucid Puppy (NOT Puppy 4.x)
mave 30.05.2010
no warranty
Thanks for Puppy!

usage: gtkdialog-splash [OPTIONS] [-timeout SEC] -text TEXT | -kill PID

- text EXPRESSION
- timeout COUNT (in sec, default: 3)
- icon GTK-XXX (for example: gtk-info all gtk-stock-symbols, default: none)
- bg COLOR (background color red, blue, yellow..., default: grey)
- fg COLOR (font color, default: black)
- placement center|mouse|top|bottom|top-left|bottom-left (default center)
- close never|mouseover|box (default is mouseover)
- fontsize SIZE (small, medium, large, x-large, default: large)

- kill PID (process ID called before: PID=0 auto-search fo the last one,
PID=xxxxx kill the last one read by PID=$!)


The close box is nice. A simple test:

# gtkdialog-splash -text "this is a text message, enough to test wrapping. Unlike yaf-splash, it auto-wraps the text, which is okay. Centering is approximate. Default size now is medium" -close box -fontsize large -placement top

Here is the code:
#!/bin/sh

#brilliant replacement for yaf-splash, written by mave, june 2010.
#gpl license see: /usr/share/doc/legal/gpl-2.0.txt
#BK added '-placement', '-close'.

#ignore scripts that do 'killall gtkdialog3'...
GTKDIALOG3="`which gtkdialog3`"
[ ! "$GTKDIALOG3" ] && GTKDIALOG3="`which gtkdialog`"
[ ! "$GTKDIALOG3" ] && exit
[ ! -f /tmp/gtkdialogyaf ] && ln -s $GTKDIALOG3 /tmp/gtkdialogyaf

ROOTGEOM="`xwininfo -root | grep -o ' \\-geometry .*' | cut -f 3 -d ' '`" #ex: 1280x800+0+0
ROOTX=`echo -n "$ROOTGEOM" | cut -f 1 -d 'x'`
ROOTY=`echo -n "$ROOTGEOM" | cut -f 1 -d '+' | cut -f 2 -d 'x'`
CENTERX=`expr $ROOTX \/ 2`

helptext="\ngtkdialog-splash\n
\n
an easy splash - possible replace for yaf-splash in Lucid Puppy (NOT Puppy 4.x)\n
mave 30.05.2010\n
no warranty\n
Thanks for Puppy!\n
\n
usage: gtkdialog-splash [OPTIONS] [-timeout SEC] -text TEXT | -kill PID \n
\n
- text EXPRESSION\n
- timeout COUNT (in sec, default: 3)\n
- icon GTK-XXX (for example: gtk-info all gtk-stock-symbols, default: none)\n
- bg COLOR (background color red, blue, yellow..., default: grey)\n
- fg COLOR (font color, default: black)\n
- placement center|mouse|top|bottom|top-left|bottom-left (default center)\n
- close never|mouseover|box (default is mouseover)\n
- fontsize SIZE (small, medium, large, x-large, default: large)\n\n
- kill PID (process ID called before: \tPID=0 auto-search fo the last one,\n
\t\t\t\t\tPID=xxxxx kill the last one read by PID=\$!)
\n"


params=$@

if [ ${#params} -eq 0 ]; then # no options, no text, so print info/help...
echo -e $helptext
exit
fi

BasePIDFile="/tmp/GTKDIALOG-SPLASH"
dummy=SECONDS
text=""
timeout="" # default values...
bg="grey"
fg="black"
icon=""
fontsize="medium" # small, medium, large, x-large
pid=""
placement='center'
close='mouseover'

param=""
optarg=$dummy

for arg in "$@";
do
if [ $optarg == "TEXT" ] # getting optional argument of a parameter
then
text=$arg
optarg=$dummy
elif [ $optarg == "PLACEMENT" ]
then
placement=$arg
optarg=$dummy
elif [ $optarg == "CLOSE" ]
then
close=$arg
optarg=$dummy
elif [ $optarg == "TIMEOUT" ]
then
timeout=$arg
optarg=$dummy
elif [ $optarg == "BG" ]
then
bg=$arg
optarg=$dummy
elif [ $optarg == "FG" ]
then
fg=$arg
optarg=$dummy
elif [ $optarg == "ICON" ]
then
icon="<pixmap>
<input file stock=\"$arg\"></input>
</pixmap>"
optarg=$dummy
elif [ $optarg == "KILL" ]
then
pid=$arg
if [ ${#pid} -eq -1 ]
then
dlgPID=`ps|grep -w 'GTKDIALOG_SPLASH'`
kill $dlgPID 2>/dev/null
else
TmpFile=$BasePIDFile${pid}
dlgPID="`cat $TmpFile`"
kill $dlgPID 2>/dev/null
rm -f $TmpFile
exit
fi
elif [ $optarg == "FONTSIZE" ]
then
fontsize=$arg
optarg=$dummy
else
case $arg in
-kill)
optarg="KILL"
;;
-text)
optarg="TEXT"
;;
-timeout)
optarg="TIMEOUT"
;;
-bg)
optarg="BG"
;;
-fg)
optarg="FG"
;;
-icon)
optarg="ICON"
;;
-fontsize)
optarg="FONTSIZE"
;;
-placement)
optarg="PLACEMENT"
;;
-close)
optarg="CLOSE"
;;
-help | --help)
echo -e $helptext
exit
;;
esac
fi
done

#process placement, default is center...
WINPLACE=''
WINTYPE=1
case $placement in
mouse)
GEOMPARAM=''
WINPLACE='window-position="2"'
WINTYPE=2
;;
top|top-right)
X=`expr $CENTERX - 200` #not accurate
Y=0
WINTYPE=10
;;
top-left)
X=0
Y=0
WINTYPE=10
;;
bottom|bottom-right)
X=`expr $CENTERX - 200` #not accurate
Y=`expr $ROOTY - 70`
WINTYPE=10
;;
bottom-left)
X=0
Y=`expr $ROOTY - 70`
WINTYPE=10
;;
esac

#process close of window, default is mouseover...
CLOSETAG1=''
CLOSETAG2='<action signal="enter-notify-event" type="exit">Exit on mouse-over</action>'
case $close in
never)
CLOSETAG2=''
;;
box)
CLOSETAG2=''
CLOSETAG1='<vbox><button><input file icon="mini-cross"></input><action type="exit">Exit on click close-box</action></button></vbox>'
;;
esac

gtkrc="style \"gtkdialog-splash\"
{
bg[NORMAL] = \"$bg\"
fg[NORMAL] = \"$fg\"
}
class \"*\" style \"gtkdialog-splash\""

echo $gtkrc > /tmp/gtkdialog-splash_gtkrc

export GTK2_RC_FILES=/tmp/gtkdialog-splash_gtkrc:/root/.gtkrc-2.0

# <action signal=\"button-press-event\" type=\"exit\">Exit on mouse click</action>

export GTKDIALOG_SPLASH="
<window title=\"gtkdialog-splash\" icon-name=\"gtk-preferences\" resizable=\"false\" decorated=\"false\" ${WINPLACE}>
<hbox>
$icon
<text use-markup=\"true\">
<label>\"<b><span size='$fontsize'>$text</span></b>\"</label>
</text>
${CLOSETAG1}
</hbox>
${CLOSETAG2}
</window>"

case $WINTYPE in
2) #mouse
/tmp/gtkdialogyaf -p GTKDIALOG_SPLASH &
;;
10)
#echo "X=$X Y=$Y" #TEST
/tmp/gtkdialogyaf --program=GTKDIALOG_SPLASH --geometry=+"${X}"+"${Y}" &
;;
*) #center
/tmp/gtkdialogyaf -p GTKDIALOG_SPLASH --center &
;;
esac
dlgPID=$!

if [ ${#timeout} -gt 0 ]; then
sleep $timeout
kill $dlgPID
else
TmpFile=$BasePIDFile$$
echo $dlgPID > $TmpFile # create tmp file named by parent-PID, storing gtkdialog3-PID
fi


Seems to work fine as a replacement for yaf-splash, so I have done that for Quirky. I have placed 'gtkdialog-splash' in /usr/bin, with /usr/bin/yaf-splash a symlink to it. I have placed this into Woof. If you are building a Puppy and choose to use the original yaf-splash, that's fine, it will override /usr/bin/yaf-splash.

Comments

Closing on hover
Username: disciple
Closing on hover seems like it could be a bit disconcerting. Personally I don't see why people don't like splashes with window decorations, or buttons..."1 Jun 2010, 22:06"01636"123.100.79.11're Gtkdialog-Splash"01micko"Barry, disciple, Certainly a unique usage of gtkdialog. I think [b]mave[/b] came up with the idea because Iguleder was having problems with yaf-splash with the Hebrew translation for Quickpet. Yaf-splash would not do Bidi (rtl) languages. I put in a workaround using gtkdialog for the splashes in Quickpet. Then mave came up with his idea and I used that instead. I PMed the info to zigbert who made the post in "Gtkdialog Tips" thread on the forum. I then discovered shinobar's yaf-splash work around for Chinese/Japanese/Korean which included placement options, but not the colours. (could have saved you some work Barry and probably more to your liking disciple, window decorations). It's part of shinobar's [b]lang_support_all-1.0.sfs [/b] from http://www.murga-linux.com/puppy/viewtopic.php?p=385038#385038. [code]#!/bin/bash # yaf-splash using gtkdialog3 by shinobar # 20100305 #erase previous splash PIDFILE=/tmp/$(basename $0).pid PID=$(cat $PIDFILE 2>/dev/null) [ "$PID" ] && kill $PID 2>/dev/null rm -f $PIDFILE CREDIT="yaf-splash, gtkdialo3 version 1 Mar 2010" usage() { echo "$CREDIT" exit } [ $# -gt 0 ] || usage #LOGFILE=/tmp/yaf-splash.log #echo "$0 $@" >> $LOGFILE #read options TEXT="" CENTER="" GEOMETRY="" PLACEMENT="" TIMEOUT="" BG="" TODISPLAY="" while [ $# -gt 0 ]; do case $1 in *-help) usage;; -text) shift; TEXT="$@";; -timeout) shift; TIMEOUT=$1; shift;; -geometry) shift; GEOMETRY="$1"; shift;; -placement) shift; PLACEMENT=$1; shift;; -bg) shift; BG=$1; shift;; -display) shift; TODISPLAY=$1; shift;; -countdown|-font|-outline|-margin|-fg|-bd|-bw|-xrm) shift; shift;; *) shift;; esac [ "$TEXT" ] && break done [ "$TEXT" ] || exit if [ "$PLACEMENT" ]; then X=0 Y=0 C=$(echo -e "$TEXT"| wc -L) R=$(echo -e "$TEXT"| wc -l) [ $C -lt 24 ] && [ $X -eq 0 ] && X=240 [ $R -lt 2 ] && [ $Y -eq 0 ] && Y=32 if [ "$GEOMETRY" ]; then SIZE=$(echo $GEOMETRY| cut -d'+' -f1) X=$(echo $SIZE| cut -d'x' -f1) Y=$(echo $SIZE| cut -d'x' -f2) fi XX=$X YY=$(($Y + 20)) # head bar [ $XX -ne 0 ] || XX=320 [ $YY -ne 0 ] || YY=72 [ "$TODISPLAY" ] && DISP="-display $TODISPLAY" || DISP="" ROOTINFO=$(xwininfo $DISP -root) ROOTX=$(echo "$ROOTINFO"| grep 'Width:' | cut -d':' -f2| tr -dc '0-9') ROOTY=$(echo "$ROOTINFO"| grep 'Height:' | cut -d':' -f2| tr -dc '0-9') ROOTY=$(($ROOTY - 32)) # mergin for desktop tray W=$((($ROOTX - $XX) / 2)) H=$((($ROOTY - $YY) / 2)) case $PLACEMENT in top-left) GEOMETRY="${X}x${Y}+0+0";; top) GEOMETRY="${X}x${Y}+${W}+0";; top-right) GEOMETRY="${X}x${Y}+$(($ROOTX - $XX))+0";; left) GEOMETRY="${X}x${Y}+0+${H}";; center) CENTER="-c";; right) GEOMETRY="${X}x${Y}+$(($ROOTX - $XX))+${H}";; bottom-left) GEOMETRY="${X}x${Y}+0+$(($ROOTY - $YY))";; bottom) GEOMETRY="${X}x${Y}+${W}+$(($ROOTY - $YY))";; bottom-right) GEOMETRY="${X}x${Y}+$(($ROOTX - $XX))+$(($ROOTY - $YY))";; esac echo "$GEOMETRY" >&2 fi ICON="" if [ "$BG" ]; then #ICON="info" case $BG in red|tomato) ICON="error";; esac fi export MAIN_DIALOG="<text><input>echo -en \"$TEXT\"</input></text>" [ "$ICON" ] && MAIN_DIALOG="<hbox><pixmap icon_size=\"3\"><input file stock=\"gtk-dialog-$ICON\"></input></pixmap> $MAIN_DIALOG</hbox>" #echo "$MAIN_DIALOG" >> $LOGFILE [ "$GEOMETRY" ] && GEOMETRY="-G $GEOMETRY" [ "$TODISPLAY" ] && TODISPLAY="--display=$TODISPLAY" if [ "$TIMEOUT" = "" ]; then echo -n $$ > $PIDFILE exec gtkdialog3 $TODISPLAY $GEOMETRY $CENTER >/dev/null else gtkdialog3 $TODISPLAY $GEOMETRY $CENTER >/dev/null & XPID=$! echo -n $XPID > $PIDFILE trap "kill $XPID && rm -f $PIDFILE" 15 # kill also my child when i am killed COUNT=0 while [ $COUNT -lt $TIMEOUT ];do COUNT=$(($COUNT + 1)) sleep 1 ps|grep -qw "^[[:blank:]]*$XPID" || break done kill $XPID && rm -f $PIDFILE fi [/code] I also PMed that to ziggy, purely for his enjoyment, seeing nice code can be fun! I was going to PM it to mave, but no need now! I will point him to this blog topic. Cheers Username: 2 Jun 2010, 11:53
"01636"115.64.206.145'gtkdialog-splash fix"BarryK"01micko, Great, I'll take a look at it! Regarding my first post, I fixed a bug in it (able to kill by pid): Oh, comment is too long, so just providing the changed part: [code] case $WINTYPE in 2) #mouse [ ${timeout} -eq 0 ] && exec /tmp/gtkdialogyaf -p GTKDIALOG_SPLASH #to keep same pid. /tmp/gtkdialogyaf -p GTKDIALOG_SPLASH & ;; 10) #echo "X=$X Y=$Y" #TEST [ ${timeout} -eq 0 ] && exec /tmp/gtkdialogyaf --program=GTKDIALOG_SPLASH --geometry=+"${X}"+"${Y}" #to keep same pid. /tmp/gtkdialogyaf --program=GTKDIALOG_SPLASH --geometry=+"${X}"+"${Y}" & ;; *) #center [ ${timeout} -eq 0 ] && exec /tmp/gtkdialogyaf -p GTKDIALOG_SPLASH --center #to keep same pid. /tmp/gtkdialogyaf -p GTKDIALOG_SPLASH --center & ;; esac dlgPID=$! #if [ ${timeout} -gt 0 ]; then sleep $timeout kill $dlgPID #else # TmpFile=$BasePIDFile$$ # echo $dlgPID > $TmpFile # create tmp file named by parent-PID, storing gtkdialog3-PID #fi [/code] Username: 3 Jun 2010, 8:52
"01636"114.129.167.148'Re yaf-splash"BarryK"I looked at shinobar's script, fine, but mave's code plus my enhancements has many more features. I even added an optional close box, for those who like to have one! Username: 3 Jun 2010, 8:09
"01636"114.129.167.148'decoration ;-)"mave"Thanks Barry for your friendly comment :-) http://www.murga-linux.com/puppy/viewtopic.php?p=424119#424119 ...there is now the option "-deco", getting a ral window for those, mssing this. mave/Markus"4 Jun 2010, 2:30"01636"84.149.79.113'Re gtkdialog-splash"BarryK"Latest: http://www.murga-linux.com/puppy/viewtopic.php?p=424315#424315 Username: 4 Jun 2010, 19:31
"01636"114.129.167.148'

Tags: woof