site  contact  subhomenews

'pupdialog': 'dialog' with X

September 19, 2011 — BarryK
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}'"

Comments

Xdialog
Username: technosaurus
how about this [code][ $DISPLAY ] && DIALOG=Xdialog || DIALOG=dialog[/code] (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)

Re Xdialog
Username: BarryK
"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.

Xdialog extra button patch
Username: technosaurus
"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

xdialog/gtkdialog/xmessage
Username: disciple
"Interesting. I'd wondered about replacing [i]xmessage[/i] 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 [i]xdialog[/i], http://xdialog.free.fr/Xmessage.txt, but it doesn't support the "-buttons" option

how about xmesssage
Username: 8-bit
"This also works for 3 buttons with a default button. It is slightly modified from trapster's example in the link provided by technosaurus. [code] #!/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 [/code]

ver no
Username: 01micko
"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 [i]cat /etc/DISTRO_SPECS[/i]


Tags: woof