'pupdialog': 'dialog' with X

I am writing a little replacement for 'dialog', for when X is running. It uses gtkdialog, and is intended to be a drop-in replacement for 'dialog'.

This came about yesterday when I started to convert one of my scripts that uses 'dialog', to have nicer interfaces. Rather than a piece-meal approach of replacing each call to dialog with a block of code for gtkdialog, which is what I started to do, I thought it would be simpler in the long run to write a replacement for dialog.

Hence 'pupdialog'. This will be in Woof, so available for all scripts. I will probably get it to call 'dialog' if no X, so "pupdialog" can be simply put into scripts replacing "dialog", and those scripts will then work with or without X.

Last night I was playing with code to parse the commandline. I came up with this, which is very compact:

#evaluate the passed parameters...

#ex: --timeout 90 --extra-button --ok-label "SAVE TO A FILE" --extra-label "SAVE TO ${xPDEV}" --cancel-label "DO NOT SAVE" --yesno "etetetete" 0 0
AVAR='START'; AVAL=''
for AFIELD in ${@}
do
case $AFIELD in
--timeout|--extra-button|--ok-label|--extra-label|--cancel-label|--yes-label|--no-label|--yesno) eval "${AVAR}='${AVAL}'"; AVAR="`echo -n "$AFIELD"| tr -d '-' | tr '[a-z]' '[A-Z]'`"; AVAL='' ;;
*) AVAL="${AVAL}${AFIELD} " ;;
esac
done
AVAL="`echo "$AVAL" | tr '\t' ' ' | tr -s ' ' | sed -e 's% $%%'`"
WIDTH="`echo -n "$AVAL" | rev | cut -f 1 -d ' ' | rev`"
HEIGHT="`echo -n "$AVAL" | rev | cut -f 2 -d ' ' | rev`"
AVAL="`echo "$AVAL" | rev | cut -f 3-999 -d ' ' | rev`"
eval "${AVAR}='${AVAL}'"



Posted on 19 Sep 2011, 8:21


Comments:

Posted on 19 Sep 2011, 9:34 by technosaurus
Xdialog
how about this
[ $DISPLAY ] && DIALOG=Xdialog || DIALOG=dialog


(goingnuts has an improved version of this code)

then just replace dialog or Xdialog with $DIALOG

the big advantage is that you can also gain a console based (read low RAM usage) interface to previously X-only apps like the install and remaster scripts

(yes I know Xdialog isn't as "elegant" as gtkdialog, but it works ... even on my gtk1 only systems)

I already did this for a lot of the stuff in woof for bashbox (I think I may have had to write a couple of wrappers for slight spelling differences, that really should be handled by a small mod to the dialog/Xdialog sources)


Posted on 19 Sep 2011, 12:14 by BarryK
Re Xdialog
Xdialog doesn't support an 'extra' button. I have a msgbox that in dialog has three button, yes, no and extra.

So yes, Xdialog can be used, except for my msgbox with 3 buttons.

Also isn't Xdialog broken for international language support?

dialog supports ansi color highlighting of text, I don't think Xdialog does. That's another thing I want.



Posted on 19 Sep 2011, 13:48 by technosaurus
Xdialog extra button patch
I thought I remembered seeing that patch somewhere.

http://murga-linux.com/puppy/viewtopic.php?t=64795
amigo posted a fix for default-no and extra-button
... further worked out by bigbass and dougal ... some other patches as well


Posted on 19 Sep 2011, 18:35 by disciple
xdialog/gtkdialog/xmessage
Interesting. I'd wondered about replacing xmessage with a gtkdialog wrapper script, as an alternative to gxmessage (xmessage is not up-to-scratch mainly because it doesn't support button navigation with the tab key).

There is a wrapper script using xdialog, http://xdialog.free.fr/Xmessage.txt, but it doesn't support the "-buttons" option


Posted on 20 Sep 2011, 16:07 by 8-bit
how about xmesssage
This also works for 3 buttons with a default button.
It is slightly modified from trapster's example in the link provided by technosaurus.

#!/bin/sh
#use xmessage to ask first.

answer=$(xmessage "Would you like start a terminal? " -buttons yes,no,maybe -default no -print)
if [ $answer = "yes" ]
then
xterm
fi
if [ $answer = "maybe" ]
then
urxvt
fi




Posted on 20 Sep 2011, 17:55 by Sage
Version number location
Used to be /etc/puppyversion, but where is it now, please?!


Posted on 20 Sep 2011, 20:20 by 01micko
ver no
Sage, you can click the green free-space icon (in lupu and slacko) in the tray and ver info displays at top of screen, as well as free space in drives.
Other wise try
cat /etc/DISTRO_SPECS


Posted on 20 Sep 2011, 22:14 by Sage
ver info
Thanks a bunch, mick!


Posted on 20 Sep 2011, 22:39 by Sage
ver info
...but neither seems to work in Wary!


Posted on 20 Sep 2011, 22:42 by Sage
neither seems to work in War
... DISTRO_SPECS is available directly from the File Manager in Wary - curious?!