Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Wed 12 Aug 2009, 00:04 Post subject:
Add GTK GUI frontends to a command line program in minutes Subject description: Using a simple gtkdialog template |
|
Here is a little template I put together adding GTK GUI frontends to command line programs.
Just use the individual parts (as many times as needed - just copy/paste and increment the numbers or comment out unneeded sections) to collect the required data in the GUI and pass it to the command line.
Code: | #! /bin/bash
export CHOOSER="
<window title=\"YOURPROGRAMNAME \"icon-name=\"gtk-cdrom\">
<vbox>
<frame Select your file>
<hbox>
<entry editable=\"true\" accept=\"filename\">
<variable>FILE1</variable>
</entry>
<button>
<input file stock=\"gtk-file\"></input>
<variable>FILE_BROWSE_FILENAME</variable>
<visible>enabled</visible>
<action type=\"fileselect\">FILE1</action>
</button>
</hbox>
</frame>
<frame Select a directory>
<hbox>
<entry editable=\"true\" accept=\"directory\">
<variable>DIR1</variable>
</entry>
<button>
<input file stock=\"gtk-open\"></input>
<variable>FILE_BROWSE_DIRECTORY</variable>
<action type=\"fileselect\">DIR1</action>
</button>
</hbox>
</frame>
<frame Entry box for user definable strings>
<hbox>
<entry editable=\"true\">
<variable>WORD1</variable>
<default> default text here </default>
</entry>
</hbox>
</frame>
<frame choose any or all:>
<hbox>
<checkbox>
<label>Check the box if you want to ...</label>
<variable>CBOX1</variable>
<default>false</default>
</checkbox>
</hbox>
<hbox>
<checkbox>
<label>Check the box if you want to ...</label>
<variable>CBOX2</variable>
<default>true</default>
</checkbox>
</hbox>
</frame>
<frame choose one of:>
<combobox>
<variable>COMBO1</variable>
<item>item 1</item>
<item>item 2</item>
</combobox>
</frame>
<frame choose one of:>
<combobox>
<variable>COMBO2</variable>
<item>item 1</item>
<item>item 2</item>
</combobox>
</frame>
<hbox>
<button>
<input file icon=\"gtk-ok\"></input>
<label>OK</label>
<action type=\"exit\">EXIT_OK</action>
</button>
<button>
<input file icon=\"gtk-quit\"></input>
<label>QUIT</label>
<action type=\"exit\">EXIT_NOW</action>
</button>
</hbox>
</vbox>
</window>
"
CHOOSER2==`gtkdialog3 --program=CHOOSER --center`
if [ "`echo $CHOOSER2 | grep EXIT_NOW`" != "" ]; then
exit 0
fi
#Get all of the variables
FILE1="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep FILE1 | sed 's/FILE1//'`"
#This is another file example if you need to prepend the flag -f ... it could be any string
#FILE1=" -f ""`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep FILE1 | sed 's/FILE1//'`"
WORD1="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep WORD1 | sed 's/WORD1//'`"
DIR1="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep DIR1 | sed 's/DIR1//'`"
CBOX1="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep CBOX1 | sed 's/CBOX1//'`"
CBOX2="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep CBOX2 | sed 's/CBOX2//'`"
COMBO1="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep COMBO1 | sed 's/COMBO1//'`"
COMBO2="`echo "$CHOOSER2" | sed 's/\"//g' | sed 's/=//g' | grep COMBO2 | sed 's/COMBO2//'`"
if [ $CBOX1 = "true" ];then
CBOX1=" -X " #where -X is the parameter you wish to pass when this checkbox is checked
else
CBOX1="" #setting it back to "null" allows us to pass all parameters without doing more "if thens"
fi
if [ $CBOX2 = "true" ];then
CBOX2=" -X " #where -Y is the parameter you wish to pass when this checkbox is checked
else
CBOX2="" #setting it back to "null" allows us to pass all parameters without doing more "if thens"
fi
#you can add any number of any of these variables
#to debug you can add echo $VARNAME for each variable and run the script from rxvt
#The following is an imaginary example to open an 80x4 terminal and execute program_name
#with cbox flags (if set) using file1 (presumably as input of type combo1)
# and output to a file of type combo2 named word1 in dir1
#rxvt +sb -bg orange -geometry 80x4 -e program_name $CBOX1... $FILE1 $COMBO1 $DIR1/$WORD1 $COMBO2
gxmessage -wrap -name YourProgram "This is a message to tell the user that the program is finished. You can use the variable names outside of the quotes like this: CBOX1 = "$CBOX1", CBOX2 = "$CBOX2", DIR1 = "$DIR1", FILE1 = "$FILE1", WORD1 = "$WORD1", COMBO1 = "$COMBO1", COMBO2 = "$COMBO2" Make sure you put the output in user understandable terms after you have finished the debugging process"
unset CHOOSER |
 |
Description |
|
Filesize |
24.87 KB |
Viewed |
3497 Time(s) |

|
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Wed 12 Aug 2009, 00:41 Post subject:
|
|
here is a quick example using tar ()
rxvt -e tar -$COMBO1$CBOX1"f "$FILE1
where:
COMBO1 is x or t (x=extract or y=list files)
CBOX1 is v (verbose if checked)
"f " is to get input file
FILE1 is the input file (default value should be $1 so that if you "open with" your program the user doesn't have to find it again)
Here is a list of available window icons:
document-open-recent
gtk-about
gtk-add
gtk-bold
gtk-caps-lock-warning
gtk-cdrom
gtk-clear
gtk-close
gtk-color-picker
gtk-connect
gtk-convert
gtk-copy
gtk-cut
gtk-delete
gtk-directory
gtk-disconnect
gtk-edit
gtk-execute
gtk-file
gtk-find-and-replace
gtk-find
gtk-floppy
gtk-font
gtk-fullscreen
gtk-go-back-ltr
gtk-go-down
gtk-go-forward-ltr
gtk-goto-bottom
gtk-goto-first-ltr
gtk-goto-last-ltr
gtk-goto-top
gtk-go-up
gtk-harddisk
gtk-help
gtk-home
gtk-indent-ltr
gtk-indent-rtl
gtk-index
gtk-info
gtk-italic
gtk-jump-to-ltr
gtk-jump-to-rtl
gtk-justify-center
gtk-justify-fill
gtk-justify-left
gtk-justify-right
gtk-leave-fullscreen
gtk-media-forward-ltr
gtk-media-next-ltr
gtk-media-pause
gtk-media-play-ltr
gtk-media-play-rtl
gtk-media-previous-ltr
gtk-media-record
gtk-media-rewind-ltr
gtk-media-stop
gtk-missing-image
gtk-network
gtk-new
gtk-open
gtk-orientation-landscape
gtk-orientation-portrait
gtk-orientation-reverse-landscape
gtk-orientation-reverse-portrait
gtk-page-setup
gtk-paste
gtk-preferences
gtk-print-error
gtk-print-paused
gtk-print
gtk-print-preview
gtk-print-report
gtk-print-warning
gtk-properties
gtk-quit
gtk-redo-ltr
gtk-redo-rtl
gtk-refresh
gtk-remove
gtk-revert-to-saved-ltr
gtk-revert-to-saved-rtl
gtk-save-as
gtk-select-all
gtk-select-color
gtk-select-font
gtk-sort-ascending
gtk-sort-descending
gtk-spell-check
gtk-stop
gtk-strikethrough
gtk-undelete-ltr
gtk-undelete-rtl
gtk-underline
gtk-undo-ltr
gtk-undo-rtl
gtk-unindent-ltr
gtk-unindent-rtl
gtk-zoom-100
gtk-zoom-fit
gtk-zoom-in
gtk-zoom-out
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Fri 14 Aug 2009, 19:14 Post subject:
Re: Add GTK GUI frontends to a command line program in minutes Subject description: Using a simple gtkdialog template |
|
technosaurus wrote: | Here is a little template I put together adding GTK GUI frontends to command line programs.
|
technosaurus,
Thanks very much for posting this. I'm just now trying to experiment with GTKdialog and this is a definite help.
Does anyone actually produce Puppy GTKdialog programs using Glade? It seems to me that the learning curve for Glade is rather steep.
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3425 Location: Oregon
|
Posted: Wed 09 Sep 2009, 00:18 Post subject:
|
|
I got in a hurry and uploaded a menu based on your work before finishing it fully. But it goes along with a command line program to format usb floppy drives.
And it all works!
The program and gui are in the Additional Software section and called:
USB Floppy Formatter.
Also, this was my first attempt ever of doing something like this.
|
Back to top
|
|
 |
ttuuxxx

Joined: 05 May 2007 Posts: 11193 Location: Ontario Canada,Sydney Australia
|
Posted: Wed 09 Sep 2009, 00:44 Post subject:
Re: Add GTK GUI frontends to a command line program in minutes Subject description: Using a simple gtkdialog template |
|
technosaurus wrote: | Here is a little template I put together adding GTK GUI frontends to command line programs. |
I don't know if you have much time but a really good pdf, program called mupdf needs a GUI, its really fast rendering and displays nicely, way better than epdfview. But its command-line, http://www.murga-linux.com/puppy/viewtopic.php?p=329167#329167
ttuuxxx
_________________ http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games 
|
Back to top
|
|
 |
PupGeek
Joined: 06 Sep 2009 Posts: 388
|
Posted: Sat 10 Oct 2009, 18:13 Post subject:
Re: Add GTK GUI frontends to a command line program in minut Subject description: Using a simple gtkdialog template |
|
seaside wrote: |
Does anyone actually produce Puppy GTKdialog programs using Glade? It seems to me that the learning curve for Glade is rather steep. |
trouble with glade is that it is pretty much for programming rather than scripting.... kinda like ncurses..... id love to be able to use ncurses with shell scripts.
|
Back to top
|
|
 |
|