Pashua is a very very simple GUI builder for MacOSX scripting languages. The author (Carsten Bluem [L1 ]) has demos written in PHP, Perl, Python, sh and AppleScript. I hope to submit a Tcl wrapper and demo. As I'm a rank beginner with respect to Tcl, I'm posting my code here so that others more adept with Tcl can critique the code before submission.
#wrapper for Pashua in Tcl #Bruce M. Axtens, 2004. proc pashua_run {script} { upvar #0 argv0 appName upvar #0 env envir set tempFile [exec /usr/bin/mktemp /tmp/Pashua_XXXXXXXX] set handle [open $tempFile w] puts $handle $script close $handle #search for Pashua binary set bundlePath "Pashua.app/Contents/MacOS/Pashua" set theHome $envir(HOME) set theList [list "$appName/Pashua" \ "$appName/$bundlePath" \ "/$bundlePath" \ "./$bundlePath" \ "/Applications/$bundlePath" \ "$theHome/Applications/$bundlePath" ] set theBinary "" foreach possib $theList { if {[file exists $possib]} then { if {[file executable $possib]} then { set theBinary $possib break } } } if {$theBinary ne ""} { set handle [open "|$theBinary $tempFile" r] while {[eof $handle]==0} { gets $handle theLine set equals [string first {=} $theLine] if {$equals > -1} { array set results \ [list [string range $theLine 0 [expr $equals - 1]] \ [string range $theLine [expr $equals + 1] end]] } } return [array get results] } else { return "" } }
The following is a test script (test.tcl) based on Blüm's one for Perl. Any suggestions to make it more Tcl-ish? Make sure if you copy this code out to a file that you remove the indent as Pashua will treat " tcl_type" as " tcl_type" not "tcl_type".
#!/usr/bin/tclsh source pashua_run.tcl set res [pashua_run { # Lines starting with a hash character are # comments, empty lines are ignored # Set transparency: 0 is transparent, 1 is opaque transparency=0.95 # Set window title windowtitle=Our first example. Isn't it simple? # Define a checkbox 'I like Tcl', default: checked tcl_type=checkbox tcl_label=I like Tcl tcl_default=1 # Define radiobuttons book_type=radiobutton book_label=Which Tcl book do you prefer? book_option=Practical Programming in Tcl and Tk book_option=The Perl Cookbook book_default=Practical Programming in Tcl and Tk # Define a popup menu editor_type=popup editor_label=What's your favourite editor for the Mac? editor_width=320 editor_option=AlphaX editor_option=Alphatk editor_option=BBedit editor_option=BBedit Lite editor_option=Emacs editor_option=jEdit editor_option=MacPerl editor_option=NEdit editor_option=Pepper editor_option=Perlidex editor_option=SubEthaEdit editor_option=vi/vim editor_option=XPerlEdit editor_option=joe editor_option=Something else editor_default=BBedit Lite # Add a filesystem browser fs_type=openbrowser fs_label=Some file or folder location fs_width=320 # A separator line - # Define a text field , default: 'user' user_type=textfield user_label=Enter your username user_width=320 user_default=useR # Define a password field pwd_label=Enter your password pwd_type=password pwd_width=320 # Define a combobox host_label=Enter a hostname or IP to connect to host_type=combobox host_width=320 host_option=www.apple.com host_option=q41.de host_option=wiki.tcl.tk host_option=localhost host_default=wiki.tcl.tk # Add a cancel button - if you like, you can set the # button label by uncommenting the second line below cncl_type=cancelbutton #cncl_label=If you click here, no values will be returned }] array set x $res puts "I [expr {$x(tcl)==1 ? "like" : "don't like"}] Tcl.\ I read \"$x(book)\" for inspiration and\ code using $x(editor). \ My username is '$x(user)' and \ the password you entered was '$x(pwd)'."