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 30 Jul 2014, 23:56
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Add GTK GUI frontends to a command line program in minutes
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4288

PostPosted: 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
frontend.png
 Description   
 Filesize   24.87 KB
 Viewed   2800 Time(s)

frontend.png


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


Joined: 18 May 2008
Posts: 4288

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

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

Joined: 11 Apr 2007
Posts: 886

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


Joined: 03 Apr 2007
Posts: 3357
Location: Oregon

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


Joined: 05 May 2007
Posts: 10747
Location: Ontario Canada,Sydney Australia

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

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

Joined: 06 Sep 2009
Posts: 388

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
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.0815s ][ Queries: 13 (0.0068s) ][ GZIP on ]