Author |
Message |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Sat 28 Aug 2010, 15:45 Post subject:
Wizards should always be able to run from console without X Subject description: 5 functions to output same content to shell, dialog or xdialog |
|
Might be a little provocative but:
Setup-wizards should as a minimum be able to run from shell without any GUI wrapped around it. As a secondary demand it should run in a very basic environment (like ash...).
The attached demo script (floppytools.sh) contains 5 functions to help accomplish above without missing an opportunity to use a GUI if present:
message_fc, input_fc, menu_fc, input_date and input_time.
All 5 functions is called with the same arguments but can output in pure shell, in dialog or in Xdialog.
This can be set automatic in the script so the users environment determine which output should be used.
floppytools.sh need some polish in coding but main purpose is to demonstrate the use of the 3 of the 5 functions...
Functions can be refined to be more selective ex. choosing more advanced GUIs...
Update: Always discovers the bug after posting...now it actually runs form shell in autoselect mode...(changed [ -n $DISPLAY ] to [ ! "$(ps | grep xwin)" = "" ] to determine if in X or not)
Update - see 4th post
View how-to further down - and the output of message_fc and menu_fc from the same code...
 |
Description |
tools for floppy things (copy, formate, apply image, make image)
|

Download |
Filename |
floppytools.sh.tar.gz |
Filesize |
2.13 KB |
Downloaded |
475 Time(s) |
Last edited by goingnuts on Mon 22 Nov 2010, 13:39; edited 5 times in total
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1438 Location: England
|
Posted: Sun 29 Aug 2010, 19:43 Post subject:
|
|
+1
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sun 29 Aug 2010, 21:31 Post subject:
|
|
Code: | #main code from P412 floppy-format.sh Copyright (c) Barry Kauler 2004 www.goosee.com/puppy
#and floppytool.sh by J.P. Nimmo(from tinycore)
#function to use pure shell, dialog or xdialog output |
Last time I was around, tinycore didn't even have dialog (roberts removed it when he couldn't figure out how to get it to work). I doubt if they have Xdialog. edit; not in base, anyway (no more comments re: tc )
If you've noticed, puppy uses gtkdialog3 (and dialog and Xdialog).
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Sun 29 Aug 2010, 22:22 Post subject:
|
|
Quote: | ...puppy uses gtkdialog3 (and dialog and Xdialog).
|
...and xmessage and yaf-splash and gtkdialog2...
of which only dialog works from console...
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Sun 14 Nov 2010, 09:05 Post subject:
Subject description: update |
|
Updated the functions:
Now input handles both text and file-select
"Infinite" selects in menu
Much better sizing of Xdialog-boxes
Added date and time dialogs
Attached two examples using the functions: settime.sh and floppytools.sh
Floppytools has been updated so cancel is handled more logic...
Both examples use the dialogfunctions.sh as includes.
Description |
Examples (floppytools and settime) using dialogfunctions.sh
|

Download |
Filename |
dialog_functions.pet |
Filesize |
3.88 KB |
Downloaded |
439 Time(s) |
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Wed 17 Nov 2010, 20:24 Post subject:
|
|
Quote: | Setup-wizards should as a minimum be able to run from shell without any GUI wrapped around it. |
slackware has pkgtool that does all the important things to set up and install packages
people still complain because it looks old but they miss the point that it runs without X
*I re wrote it in Xdialog to give it a modern look and added functions to it such as dependency checking but I still keep the non X version as an emergency when X is broken for some reason
it already works on a "puppy base" and its easy to modify the set up part
to your special needs
thats the script to use and modify
Joe
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Thu 18 Nov 2010, 12:22 Post subject:
|
|
How-to message:
Code: |
#!/bin/sh
. dialogfunctions.sh
TITLE="Message Demo"
TEXT="This is the output from the
message_fc
function.
"
#run the function
message_fc
|
Description |
Output from message_fc via Xdialog |
Filesize |
6.29 KB |
Viewed |
1019 Time(s) |

|
Description |
Output from message_fc via dialog |
Filesize |
6.15 KB |
Viewed |
1073 Time(s) |

|
Description |
Shell/console output from message_fc |
Filesize |
2.22 KB |
Viewed |
978 Time(s) |

|
Last edited by goingnuts on Thu 18 Nov 2010, 12:31; edited 1 time in total
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Thu 18 Nov 2010, 12:25 Post subject:
|
|
Howto - menu_fc:
Code: |
#!/bin/sh
. dialogfunctions.sh
TITLE="Message Demo"
TEXT="Example of creating a menu and evaluation
of the function retur."
#write CHOICES to file
echo "This is the first choice
This is the second choice
And the last choice" >/tmp/choices
#run the function
menu_fc
#evaluate response
menuitem=$(cat /tmp/reply) 2> /dev/null
case $menuitem in
0) echo "Your further code for first choice goes here";;
1) echo "your further code for second choice goes here";;
2) echo "Your further code for third choice goes here";;
esac
|
Description |
Output via Xdialog |
Filesize |
9.94 KB |
Viewed |
1054 Time(s) |

|
Description |
Output via dialog |
Filesize |
9.28 KB |
Viewed |
1005 Time(s) |

|
Description |
Output via shell/console |
Filesize |
3.39 KB |
Viewed |
1007 Time(s) |

|
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Fri 19 Nov 2010, 02:46 Post subject:
|
|
big_bass wrote: |
people still complain because it looks old but they miss the point that it runs without X
|
The GUI/look is where your code meets the user...and the user is always right...
The dialogfunctions is a try to get around the look without compromising on functionality. A series of dialogs is still old school compared to a GTK GUI where everything can be set in one window - but the inclusion of the more basic core user-interfaces do not exclude the one-window-GTK-GUI: Just make a switch in the script to use GTK-fancy if GTK is present and you are in an X-environment - otherwise it will run anyway and you do not leave the user with no way to get the job done.
I found my self more productive not spending time on getting a dialog or a Xdialog widget to work - just doing the basic script logic and call the dialogfunctions.
I have exercised the functions on Puppy setup-scripts - always using a lot of time reading and understanding the GTK-part of the programs. On the other hand applying the functions on a CLI or dialog based script takes much less time.
If it makes sense and is of any help I could try to apply the dialogfunctions on your modified CLI or Xdialog Slackware pkgtool?
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Sat 20 Nov 2010, 18:52 Post subject:
|
|
here is an odd script on the same thought
some notes dialog and xdialog have differences when
you try to make dynamic menus
in xdialog I had to code a work around for it because
it lacks a command only used in dialog
joe
Code: | #!/bin/sh
# detects if X display is running and you clicked on the script
# or if you are running an app pasted in a terminal
# or you are not running x
# Joe Arose
# call this xtest2
clear
CONSOLE_APP=(`env |grep "DISPLAY="`)
clear
# you ran the script in X pasted inside a terminal
if [[ $CONSOLE_APP = "DISPLAY=:0.0" ]]; then
#echo " X is being used on ---> $CONSOLE_APP
yaf-splash -font "8x16" -outline 0 -margin 4 -fg black -text " you ran the script in X pasted inside a terminal"
# you ran the script in X by clicking on it DISPLAY=:0 not :0.0
elif [[ $CONSOLE_APP = "DISPLAY=:0" ]]; then
#echo " X is being used on ---> $CONSOLE_APP
yaf-splash -font "8x16" -outline 0 -margin 4 -fg black -text " you ran the script in X by clicking it"
elif [[ $CONSOLE_APP = "" ]]; then
echo "-----------------------------------------------------------------------"
echo ""
echo "X is not running you are running in the console type xwin to return "
echo "pkgtool is for installing packages in the console "
echo ""
echo "-----------------------------------------------------------------------"
fi
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sat 20 Nov 2010, 20:01 Post subject:
|
|
big_bass wrote: | here is an odd script on the same thought
some notes dialog and xdialog have differences when
you try to make dynamic menus
in xdialog I had to code a work around for it because
it lacks a command only used in dialog
joe
|
Lets you know if you click from ROX, but not from something like gtkdialog3 or bacon.
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Sat 20 Nov 2010, 22:53 Post subject:
|
|
$console_app is unnecessary - you can query DISPLAY directly (there are some examples in pupngo)
it _should_ work from gtkdialog and bacon and x and y and z - DISPLAY is set when X starts and unset when it exits (at least it is supposed to)
the :0.0 refers to screen 1 ... if you have multiple monitors (via Xinerama) I _think_ it would be .* (where * is the screen number)
I use this to set the DIALOG variable and use it in my scripts where the Xdialog scripts do not use a tag that isn't available in dialog
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Sat 20 Nov 2010, 22:56 Post subject:
|
|
Quote: | lets you know if you click from ROX, but not from something like gtkdialog3 or bacon. |
havent tried in bacon
that would be difficult because you compile the code another head for the code would have to do the check maybe
you just place it as a head in gtkdialog like the easy demo here
then the gtkdialog code
Code: |
#!/bin/bash
# detects if X display is running and you clicked on the script
# or if you are running an app from console pasted in a termial
# or you are not running x
# Joe Arose
# call this xtest2
clear
CONSOLE_APP=(`env |grep "DISPLAY="`)
# you ran the script in X by clicking on it DISPLAY=:0 not :0.0
# yaf-splash -font "8x16" -outline 0 -margin 4 -fg black -text " X is being used on ---> "$CONSOLE_APP"" &
clear
# you ran the script in X pasted inside a terminal
if [[ $CONSOLE_APP = "DISPLAY=:0.0" ]]; then
#echo " X is being used on ---> $CONSOLE_APP
yaf-splash -font "8x16" -outline 0 -margin 4 -fg black -text " you ran the script in X pasted inside a terminal"
elif [[ $CONSOLE_APP = "DISPLAY=:0" ]]; then
#echo " X is being used on ---> $CONSOLE_APP
yaf-splash -font "8x16" -outline 0 -margin 4 -fg black -text " you ran the script in X by clicking it"
elif [[ $CONSOLE_APP = "" ]]; then
echo "-----------------------------------------------------------------------"
echo ""
echo "X is not running you are running in the console type xwin to return "
echo "pkgtool is for installing packages in the console "
echo ""
echo "-----------------------------------------------------------------------"
fi
export MAIN_DIALOG='
<vbox>
<frame Checkbox example>
<checkbox>
<label>This is a checkbox...</label>
<variable>CHECKBOX</variable>
<action>echo Checkbox is $CHECKBOX now.</action>
<action>if true enable:ENTRY</action>
<action>if false disable:ENTRY</action>
</checkbox>
<checkbox>
<label>I want an OK button NOW!</label>
<variable>CHECKBOX2</variable>
<action>if true enable:OKBUTTON</action>
<action>if false disable:OKBUTTON</action>
</checkbox>
<checkbox>
<label>I want coffee NOW!</label>
<variable>CHECKBOX3</variable>
<action>if true enable:OKBUTTON</action>
<action>if false disable:OKBUTTON</action>
</checkbox>
</frame>
<hbox>
<button ok>
<variable>OKBUTTON</variable>
</button>
<button cancel></button>
</hbox>
</vbox>
'
gtkdialog --program=MAIN_DIALOG
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 3217
|
Posted: Sat 20 Nov 2010, 23:29 Post subject:
|
|
Tried script as posted, with same result.
Edit: Works if clicked from ROX, though, but not if loaded from a JWM icon.
That seems to be the issue....running the program from the JWM taskbar.
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Sun 21 Nov 2010, 09:39 Post subject:
|
|
Maybe this one will do it?
Code: |
#!/bin/sh
[ -n $DISPLAY ] && [ "$(tty)" = "not a tty" ] && exec rxvt -e sh -c $0
echo "I am forced to be spawned from a shell"
read DUMMY |
Seems to work clicking from rox, running from shell in X and running from console.
From jwm menu you still need to start with "rxvt -e PROGRAM".
From jmw tray TrayButton use "exec:rxvt -e PROGRAM".
From jwm desktop TrayButton use "exec:PROGRAM".
So final header in dialogfunctions.sh could be:
Code: |
TYPE="cli" #dialog or cli
[ $(which dialog) ] && TYPE="dialog" && DIALOG=dialog
[ $(which Xdialog) ] && [ -n $DISPLAY ] && DIALOG=Xdialog
[ -n $DISPLAY ] && [ "$(tty)" = "not a tty" ] && [ ! "${DIALOG}" = "Xdialog" ] && exec rxvt -e sh -c $0
|
(Xdialog do not need the forced spawn - I do not know if GTKdialogs needs it). The call for rxvt could be changed to /usr/local/bin/defaultshell if present or a check for different shells available.
|
Back to top
|
|
 |
|