Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 03 Sep 2014, 03:48
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Wizards should always be able to run from console without X
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [31 Posts]   Goto page: 1, 2, 3 Next
Author Message
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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...
floppytools.sh.tar.gz
Description  tools for floppy things (copy, formate, apply image, make image)
gz

 Download 
Filename  floppytools.sh.tar.gz 
Filesize  2.13 KB 
Downloaded  335 Time(s) 

Last edited by goingnuts on Mon 22 Nov 2010, 13:39; edited 5 times in total
Back to top
View user's profile Send private message Visit poster's website 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: 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
View user's profile Send private message Visit poster's website 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: 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
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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... Smile
Back to top
View user's profile Send private message Visit poster's website 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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.
dialog_functions.pet
Description  Examples (floppytools and settime) using dialogfunctions.sh
pet

 Download 
Filename  dialog_functions.pet 
Filesize  3.88 KB 
Downloaded  283 Time(s) 
Back to top
View user's profile Send private message Visit poster's website 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: 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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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
Xdialog_output.png
 Description   Output from message_fc via Xdialog
 Filesize   6.29 KB
 Viewed   949 Time(s)

Xdialog_output.png

dialogOutput.png
 Description   Output from message_fc via dialog
 Filesize   6.15 KB
 Viewed   1012 Time(s)

dialogOutput.png

ShellOutput.png
 Description   Shell/console output from message_fc
 Filesize   2.22 KB
 Viewed   921 Time(s)

ShellOutput.png


Last edited by goingnuts on Thu 18 Nov 2010, 12:31; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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
XdialogMenu.png
 Description   Output via Xdialog
 Filesize   9.94 KB
 Viewed   961 Time(s)

XdialogMenu.png

dialogMenu.png
 Description   Output via dialog
 Filesize   9.28 KB
 Viewed   937 Time(s)

dialogMenu.png

shellMenu.png
 Description   Output via shell/console
 Filesize   3.39 KB
 Viewed   947 Time(s)

shellMenu.png

Back to top
View user's profile Send private message Visit poster's website 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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
View user's profile Send private message Visit poster's website 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: 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



_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: 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
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: 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 Surprised.* (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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: 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







_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: 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.
console-test.png
Description 
png

 Download 
Filename  console-test.png 
Filesize  438.38 KB 
Downloaded  272 Time(s) 
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: 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
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 3 [31 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1113s ][ Queries: 13 (0.0052s) ][ GZIP on ]