Changeset 2153


Ignore:
Timestamp:
Mar 26, 2011, 7:41:58 PM (14 years ago)
Author:
mmc
Message:

Hooked the new template capability into the builder. Added support for
all other Rappture languages. Some languages also generate a Makefile
that can be used to build the program.

Location:
trunk/builder/scripts
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/builder/scripts/Makefile.in

    r2082 r2153  
    2424                $(srcdir)/objpath.tcl \
    2525                $(srcdir)/slideframes.tcl \
     26                $(srcdir)/templates.tcl \
    2627                $(srcdir)/tool.rp \
    2728                $(srcdir)/tweener.tcl
     29
     30TEMPLATEFILES   = \
     31                $(srcdir)/templates/clang.tl \
     32                $(srcdir)/templates/fortran77.tl \
     33                $(srcdir)/templates/java.tl \
     34                $(srcdir)/templates/matlab.tl \
     35                $(srcdir)/templates/octave.tl \
     36                $(srcdir)/templates/perl.tl \
     37                $(srcdir)/templates/python.tl \
     38                $(srcdir)/templates/ruby.tl \
     39                $(srcdir)/templates/tcl.tl
    2840
    2941version         = $(PACKAGE_VERSION)
     
    3850                --outfile tclIndex
    3951
    40 install: install_scripts install_images
     52install: install_scripts install_templates install_images
    4153
    4254install_scripts:
     
    4860        $(INSTALL) -m 444 tclIndex $(destdir)
    4961
     62install_templates: $(TEMPLATEFILES)
     63        $(MKDIR_P) -m 0755 $(destdir)/templates
     64        @for i in $(TEMPLATEFILES); do \
     65            echo "Installing $$i" ; \
     66            $(INSTALL) -m 555 $$i $(destdir)/templates ; \
     67        done
     68
    5069install_images:
    5170        $(MKDIR_P) -m 0755 $(destdir)/images
    52         @for i in $(srcdir)/images/*.gif $(srcdir)/images/*.png $(srcdir)/images/*.xbm; do \
     71        @for i in $(srcdir)/images/*.png $(srcdir)/images/*.xbm; do \
    5372            echo "Installing $$i" ; \
    5473            $(INSTALL) -m 444 $$i $(destdir)/images ; \
  • trunk/builder/scripts/main.tcl

    r2147 r2153  
    7474option add *saveas*progv*Button.padX 2
    7575option add *saveas*progv*Button.padY 2
    76 option add *saveas*progl*Label.font {Helvetica -12}
    77 option add *saveas*progl*Combobox.textBackground #d9d9d9
    78 option add *saveas*progl*Combobox.borderWidth 1
    7976
    8077switch $tcl_platform(platform) {
     
    8885
    8986wm protocol . WM_DELETE_WINDOW main_exit
    90 wm title . "Instant Rappture"
     87wm title . "Rappture Builder"
    9188
    9289# install a better bug handler
     
    118115    exit 1
    119116}
     117
     118# load all languages recognized by the builder
     119RapptureBuilder::templates::init
    120120
    121121# ----------------------------------------------------------------------
     
    169169        return
    170170    }
     171    set win [.func.build.options.panes pane 0]
     172    $win.scrl.skel select none
     173
    171174    main_generate_xml
    172175
    173     if {[string length $LastToolXmlLoaded] > 0 && ![string equal [$ToolXml xml] $LastToolXmlLoaded]} {
    174         set choice [tk_messageBox -icon warning -type yesno -title "iRappture: Save Changes?" -message "Changes to the current tool haven't been saved.\n\nSave changes?"]
     176    if {[string length $LastToolXmlLoaded] > 0 && [$ToolXml xml] ne $LastToolXmlLoaded} {
     177puts ">>>>"
     178puts $LastToolXmlLoaded
     179puts "----"
     180puts [$ToolXml xml]
     181puts "<<<<"
     182        set choice [tk_messageBox -icon warning -type yesno -title "Rappture: Save Changes?" -message "Changes to the current tool haven't been saved.\n\nSave changes?"]
    175183        if {$choice == "yes" && ![main_saveas]} {
    176184            return
     
    179187
    180188    if {$what == "-new"} {
    181         set xmlobj [Rappture::LibraryObj ::#auto "<?xml version=\"1.0\"?><run><tool/></run>"]
     189        set xmlobj [Rappture::LibraryObj ::#auto "<?xml version=\"1.0\"?><run/>"]
     190        $xmlobj put tool.command ""
    182191    } else {
    183192        if {$what == "-file"} {
    184             set fname [tk_getOpenFile -title "iRappture: Open Tool" -initialfile "tool.xml" -defaultextension .xml -filetypes { {{XML files} .xml} {{All files} *} }]
     193            set fname [tk_getOpenFile -title "Rappture: Open Tool" -initialfile "tool.xml" -defaultextension .xml -filetypes { {{XML files} .xml} {{All files} *} }]
    185194        } else {
    186195            set fname $what
     
    197206
    198207        if {[catch {Rappture::library $fname} xmlobj]} {
    199             tk_messageBox -icon error -title "iRappture: Error" -message "Error loading tool description: $xmlobj"
     208            tk_messageBox -icon error -title "Rappture: Error" -message "Error loading tool description: $xmlobj"
    200209            return
    201210        }
     
    402411        }
    403412
    404         set choice [tk_messageBox -icon error -type yesno -title "iRappture: Problems with your tool definition" -message "$thereis $phrases for your current tool definition.  Examine and resolve $problem?"]
     413        set choice [tk_messageBox -icon error -type yesno -title "Rappture: Problems with your tool definition" -message "$thereis $phrases for your current tool definition.  Examine and resolve $problem?"]
    405414        if {$choice == "yes"} {
    406415            return 1
     
    582591                return
    583592            }
     593            set win [.func.build.options.panes pane 0]
     594            $win.scrl.skel select none
     595
    584596            # generate now to catch any errors
    585597            main_generate_xml
     598
     599            # get the language choice and update the skeleton program option
     600            set lang ""
     601            set cmd [$ToolXml get tool.command]
     602            if {[string index $cmd 0] == "!"} {
     603                set lang [string range $cmd 1 end]
     604            } else {
     605                # It's hard to reload a real command from a tool.xml file.
     606                # Scan through all languages and treat @@FILENAME@@ as a
     607                # wildcard.  See if any of the languages match.
     608                foreach name [RapptureBuilder::templates::languages] {
     609                    set pat [RapptureBuilder::templates::generate command \
     610                        -language $name -macros {@@FILENAME@@ * @@FILEROOT@@ *}]
     611
     612                    if {[string match $pat $cmd]} {
     613                        set lang $name
     614                        break
     615                    }
     616                }
     617            }
     618            if {$lang ne ""} {
     619                .saveas.opts.prog configure -text "Skeleton program ($lang)" -state normal
     620                .saveas.opts.progv.getfile configure -state normal
     621                set ext [RapptureBuilder::templates::generate extension -language $lang]
     622                .saveas.opts.progv.file configure -text "main$ext"
     623                set SaveAs(lang) $lang
     624                set SaveAs(ext) $ext
     625
     626                # see if there's a makefile for this program
     627                if {[catch {RapptureBuilder::templates::generate makefile -language $lang}]} {
     628                    set SaveAs(make) 0
     629                    .saveas.opts.make configure -state disabled
     630                } else {
     631                    .saveas.opts.make configure -state normal
     632                }
     633            } else {
     634                .saveas.opts.prog configure -text "Skeleton program (select language under Tool section)" -state disabled
     635                .saveas.opts.progv.file configure -text "select a file"
     636                .saveas.opts.progv.getfile configure -state disabled
     637                .saveas.opts.make configure -state disabled
     638                set SaveAs(lang) ?
     639                set SaveAs(ext) ?
     640                set SaveAs(prog) 0
     641                set SaveAs(make) 0
     642            }
     643            main_saveas update
    586644
    587645            # make the saveas dialog big enough and center it on the main win
     
    621679            set pfile [.saveas.opts.progv.file cget -text]
    622680
    623             if {$SaveAs(tool) && ![string equal "select a file" $tfile]} {
     681            if {$SaveAs(tool) && $tfile ne "select a file"} {
     682                set tfile [file normalize $tfile]
     683
     684                if {$SaveAs(prog) && $pfile ne "select a file"} {
     685                    # if we have a tool.xml file, put the program in same dir
     686                    set tail [file tail $pfile]
     687                    set pfile [file join [file dirname $tfile] $tail]
     688                }
     689            }
     690
     691            if {$SaveAs(tool) && $tfile ne "select a file"} {
    624692                # generate again now that we know the file name to get
    625693                # relative file paths for things like <note>'s
    626694                set LastToolXmlFile $tfile
    627695                main_generate_xml
     696
     697                set cmd [$ToolXml get tool.command]
     698                if {[string index $cmd 0] eq "!"} {
     699                    if {$pfile eq "select a file"} {
     700                        set pfile "main$SaveAs(ext)"
     701                    }
     702                    set tail [file tail $pfile]
     703                    set cmd [RapptureBuilder::templates::generate command \
     704                        -language $SaveAs(lang) \
     705                        -macros [list @@FILENAME@@ $tail \
     706                                      @@FILEROOT@@ [file rootname $tail]]]
     707                    $ToolXml put tool.command $cmd
     708                }
    628709
    629710                set cmds {
     
    634715                }
    635716                if {[catch $cmds result]} {
    636                     tk_messageBox -icon error -title "iRappture: Error" -message "Error saving tool description: $result"
     717                    tk_messageBox -icon error -title "Rappture: Error" -message "Error saving tool description: $result"
    637718                    set status "error"
    638719                } else {
     
    641722            }
    642723
    643             if {$SaveAs(prog) && ![string equal "select a file" $pfile]} {
    644                 tk_messageBox -icon error -title "iRappture: Error" -message "Generating script file is not yet implemented"
     724            if {$SaveAs(prog) && $pfile ne "select a file"} {
     725                if {[file exists $pfile]} {
     726                    set choice [tk_messageBox -icon warning -type yesno -title "Rappture: Confirm" -message "File \"$pfile\" already exists.\n\nOverwrite?"]
     727                    if {$choice == "no"} {
     728                        # pop the dialog back up
     729                        wm deiconify .saveas
     730                        raise .saveas
     731                        grab set .saveas
     732                        return
     733                    }
     734                }
     735                set code [RapptureBuilder::templates::generate main \
     736                    -language $SaveAs(lang) -xmlobj $ToolXml]
     737
     738                set cmds {
     739                    set fid [open $pfile w]
     740                    puts -nonewline $fid $code
     741                    close $fid
     742                }
     743                if {[catch $cmds result]} {
     744                    tk_messageBox -icon error -title "Rappture: Error" -message "Error saving skeleton program file: $result"
     745                    set status "error"
     746                }
     747            }
     748
     749            if {$SaveAs(make)} {
     750                if {$pfile eq "select a file"} {
     751                    set pfile "main$SaveAs(ext)"
     752                }
     753                set mfile [file join [file dirname $pfile] Makefile]
     754                if {[file exists $mfile]} {
     755                    set choice [tk_messageBox -icon warning -type yesno -title "Rappture: Confirm" -message "File \"$mfile\" already exists.\n\nOverwrite?"]
     756                    if {$choice == "no"} {
     757                        # pop the dialog back up
     758                        wm deiconify .saveas
     759                        raise .saveas
     760                        grab set .saveas
     761                        return
     762                    }
     763                }
     764
     765                set fname [file tail $pfile]
     766                set dir [file dirname [file dirname $::Rappture::installdir]]
     767                set macros [list @@RAPPTUREDIR@@ $dir]
     768                lappend macros @@FILENAME@@ $fname
     769                lappend macros @@FILEROOT@@ [file rootname $fname]
     770                if {[catch {RapptureBuilder::templates::generate makefile -language $SaveAs(lang) -macros $macros} code] == 0} {
     771                    set cmds {
     772                        set fid [open $mfile w]
     773                        puts -nonewline $fid $code
     774                        close $fid
     775                    }
     776                    if {[catch $cmds result]} {
     777                        tk_messageBox -icon error -title "Rappture: Error" -message "Error saving Makefile: $result"
     778                        set status "error"
     779                    }
     780                }
    645781            }
    646782
     
    650786        update {
    651787            set havefile 0
     788            set missingfile 0
    652789            set tfile [.saveas.opts.toolv.file cget -text]
    653             if {$SaveAs(tool) && ![string equal $tfile "select a file"]} {
    654                 .saveas.opts.toolv.file configure -fg black
    655                 set havefile 1
     790            if {$SaveAs(tool)} {
     791                if {$tfile ne "select a file"} {
     792                    .saveas.opts.toolv.file configure -fg black
     793                    set havefile 1
     794                } else {
     795                    set missingfile 1
     796                }
    656797            } else {
    657798                .saveas.opts.toolv.file configure -fg gray60
     
    659800
    660801            set pfile [.saveas.opts.progv.file cget -text]
    661             if {$SaveAs(prog) && ![string equal $pfile "select a file"]} {
    662                 .saveas.opts.progv.file configure -fg black
    663                 set havefile 1
     802            if {$SaveAs(prog)} {
     803                if {$pfile ne "select a file"} {
     804                    .saveas.opts.progv.file configure -fg black
     805                    set havefile 1
     806                } else {
     807                    set missingfile 1
     808                }
    664809            } else {
    665810                .saveas.opts.progv.file configure -fg gray60
    666811            }
    667812
    668             if {$havefile} {
     813            if {$havefile && !$missingfile} {
    669814                .saveas.cntls.save configure -state normal
    670815            } else {
     
    674819
    675820        gettoolfile {
    676             set fname [tk_getSaveFile -title "iRappture: Save Tool" -parent .saveas -initialfile "tool.xml" -defaultextension .xml -filetypes { {{XML files} .xml} {{All files} *} }]
     821            set fname [tk_getSaveFile -title "Rappture: Save Tool" -parent .saveas -initialfile "tool.xml" -defaultextension .xml -filetypes { {{XML files} .xml} {{All files} *} }]
    677822
    678823            if {"" != $fname} {
     
    684829
    685830        getprogfile {
    686             set ext .tcl
    687             set fname [tk_getSaveFile -title "iRappture: Save Program Skeleton" -parent .saveas -initialfile "wrapper$ext" -defaultextension $ext -filetypes {
    688     {{C programs} .c}
    689     {{C++ programs} .cpp}
    690     {{F77 programs} .f}
    691     {{MATLAB scripts} .m}
    692     {{Perl scripts} .pl}
    693     {{Python scripts} .py}
    694     {{Tcl scripts} .tcl}
    695     {{Ruby scripts} .ruby}
    696     {{All files} *}
    697 }]
     831            set flist ""
     832            lappend flist [list "$SaveAs(lang) files" $SaveAs(ext)]
     833            lappend flist [list "All files" *]
     834
     835            set pfile [.saveas.opts.progv.file cget -text]
     836            if {$pfile eq "select a file"} {
     837                set init ""
     838                set ext ""
     839            } else {
     840                set init $pfile
     841                set ext [file extension $pfile]
     842            }
     843
     844            set fname [tk_getSaveFile -title "Rappture: Save Program Skeleton" -parent .saveas -initialfile $init -defaultextension $ext -filetypes $flist]
    698845
    699846            if {"" != $fname} {
     
    724871        return
    725872    }
     873    set win [.func.build.options.panes pane 0]
     874    $win.scrl.skel select none
     875
    726876    main_generate_xml
    727877
    728     if {![string equal [$ToolXml xml] $LastToolXmlLoaded]} {
    729         set choice [tk_messageBox -icon warning -type yesno -title "iRappture: Save Changes?" -message "Changes to the current tool haven't been saved.\n\nSave changes?"]
     878    if {[$ToolXml xml] ne $LastToolXmlLoaded} {
     879        set choice [tk_messageBox -icon warning -type yesno -title "Rappture: Save Changes?" -message "Changes to the current tool haven't been saved.\n\nSave changes?"]
    730880        if {$choice == "yes" && ![main_saveas]} {
    731881            return
     
    846996# ----------------------------------------------------------------------
    847997wm geometry . 800x600
    848 
    849 # ----------------------------------------------------------------------
    850 # MAIN WINDOW
    851 # ----------------------------------------------------------------------
    852 wm geometry . 600x500
    853998Rappture::Postern .postern
    854999pack .postern -side bottom -fill x
     
    10041149        grid $frame.cntls -row 0 -column 0 -columnspan 2 -sticky nsew
    10051150
    1006         if {![string equal $type "Tool"]} {
     1151        if {$type ne "Tool"} {
    10071152            # can't let people delete the tool info
    10081153            button $frame.cntls.del -text "Delete" -command main_options_delete
     
    10181163        pack $frame.cntls.path -side left -expand yes -fill both
    10191164
    1020         if {[string equal $type "Tool"]} {
     1165        if {$type eq "Tool"} {
    10211166            # if this is a tool, then lose the rename button
    10221167            pack forget [$frame.cntls.path component button]
     
    10651210
    10661211            # if an error was found at this attribute, set focus there
    1067             if {[string equal $name $ErrFocusAttr]} {
     1212            if {$name eq $ErrFocusAttr} {
    10681213                $obj edit
    10691214                set ErrFocusAttr ""
     
    11341279        catch {unset OptionsPanelObjs}
    11351280
    1136         set win [.func.build.options.panes pane 1]
    1137         set frame [$win.vals contents frame]
    1138         foreach win [winfo children $frame] {
    1139             destroy $win
     1281        set bwin [.func.build.options.panes pane 1]
     1282        set frame [$bwin.vals contents frame]
     1283        foreach w [winfo children $frame] {
     1284            destroy $w
    11401285        }
    11411286    }
     
    12181363toplevel .saveas
    12191364pack propagate .saveas off
    1220 wm title .saveas "iRappture: Save As..."
     1365wm title .saveas "Rappture: Save As..."
    12211366wm withdraw .saveas
    12221367wm protocol .saveas WM_DELETE_WINDOW {.saveas.cntls.cancel invoke}
     
    12401385frame .saveas.opts.toolv
    12411386pack .saveas.opts.toolv -anchor w
    1242 label .saveas.opts.toolv.filel -text "File:" -width 12 -anchor e
     1387label .saveas.opts.toolv.filel -text "File:" -width 7 -anchor e
    12431388pack .saveas.opts.toolv.filel -side left
    12441389button .saveas.opts.toolv.getfile -text "Choose..." -command {main_saveas gettoolfile}
     
    12521397frame .saveas.opts.progv
    12531398pack .saveas.opts.progv -anchor w
    1254 label .saveas.opts.progv.filel -text "File:" -width 12 -anchor e
     1399label .saveas.opts.progv.filel -text "File:" -width 7 -anchor e
    12551400pack .saveas.opts.progv.filel -side left
    12561401button .saveas.opts.progv.getfile -text "Choose..." -command {main_saveas getprogfile}
     
    12581403label .saveas.opts.progv.file -text "select a file" -anchor e -fg gray60
    12591404pack .saveas.opts.progv.file -side left -expand yes -fill x
    1260 frame .saveas.opts.progl
    1261 pack .saveas.opts.progl -anchor w
    1262 label .saveas.opts.progl.l -text "Language:" -width 12 -anchor e
    1263 pack .saveas.opts.progl.l -side left
    1264 Rappture::Combobox .saveas.opts.progl.val -width 20 -editable no
    1265 pack .saveas.opts.progl.val -side left -pady {4 0}
    1266 .saveas.opts.progl.val choices insert end \
    1267     .c    "C programs" \
    1268     .cpp  "C++ programs" \
    1269     .f    "F77 programs" \
    1270     .m    "MATLAB scripts" \
    1271     .pl   "Perl scripts" \
    1272     .py   "Python scripts" \
    1273     .tcl  "Tcl scripts" \
    1274     .ruby "Ruby scripts"
    1275 .saveas.opts.progl.val value "Python scripts"
     1405
     1406checkbutton .saveas.opts.make -text "Makefile for building this program" -variable SaveAs(make) -command {main_saveas update}
     1407pack .saveas.opts.make -side top -anchor w -pady {10 0}
    12761408
    12771409# ----------------------------------------------------------------------
  • trunk/builder/scripts/templates.tcl

    r2147 r2153  
    2121# ======================================================================
    2222package require Itcl
    23 
    24 namespace eval RapptureBuilder { # forward declaration }
     23package require RapptureBuilder
     24
    2525namespace eval RapptureBuilder::templates {
    2626    #
     
    4444        $langParser hide $cmd
    4545    }
     46    $langParser alias extension RapptureBuilder::templates::parse_template extension
     47    $langParser alias command RapptureBuilder::templates::parse_template command
     48    $langParser alias makefile RapptureBuilder::templates::parse_template makefile
     49
    4650    $langParser alias main RapptureBuilder::templates::parse_template main
    4751    $langParser alias input RapptureBuilder::templates::parse_pattern input
    4852    $langParser alias output RapptureBuilder::templates::parse_pattern output
     53
    4954    $langParser alias unknown RapptureBuilder::templates::parse_lang_unknown
    5055    proc ::RapptureBuilder::templates::parse_lang_unknown {args} {
     
    110115# ----------------------------------------------------------------------
    111116# USAGE: RapptureBuilder::templates::generate <what> \
    112 #           ?-language name? ?-xmlobj obj?
     117#           ?-language name? ?-xmlobj obj? ?-macros <string-map>?
    113118#
    114119# Builds a string of generated information starting with <what> as
    115 # the main template.  This string may contain other @NAME@ fields,
     120# the main template.  This string may contain other @@NAME@@ fields,
    116121# which are substituted recursively until all substitutions have
    117122# been made.  The -language option specifies which language template
    118 # should be used.  The -xmlobj option gives data for the @NAME@
     123# should be used.  The -xmlobj option gives data for the @@NAME@@
    119124# substitutions.
    120125#
     
    127132        value -language ""
    128133        value -xmlobj ""
     134        value -macros ""
    129135    }
    130136    if {[llength $args] > 0} {
     
    151157    if {$xmlobj ne ""} {
    152158        foreach path [Rappture::entities -as path $xmlobj input] {
    153             append inputs [$langDefs($lang) generate $xmlobj $path]
     159            append inputs [$langDefs($lang) generate $xmlobj $path -code]
    154160        }
    155161    }
     
    159165    if {$xmlobj ne ""} {
    160166        foreach path [Rappture::entities -as path $xmlobj output] {
    161             append outputs [$langDefs($lang) generate $xmlobj $path]
    162         }
    163     }
    164 
    165     set info [string map [list @@INPUTS@@ $inputs @@OUTPUTS@@ $outputs] $info]
     167            append outputs [$langDefs($lang) generate $xmlobj $path -code]
     168        }
     169    }
     170
     171    # produce the @@DECLARATIONS@@ section...
     172    set decls ""
     173    if {$xmlobj ne ""} {
     174        foreach path [Rappture::entities -as path $xmlobj input] {
     175            append decls [$langDefs($lang) generate $xmlobj $path -decl]
     176        }
     177        foreach path [Rappture::entities -as path $xmlobj output] {
     178            append decls [$langDefs($lang) generate $xmlobj $path -decl]
     179        }
     180    }
     181
     182    # handle the @@INPUTS@@ / @@OUTPUTS@@ / @@DECLARATIONS@@ specially
     183    # preserve the indent at the beginning of each line
     184    foreach {macro var} {
     185        @@INPUTS@@ inputs
     186        @@OUTPUTS@@ outputs
     187        @@DECLARATIONS@@ decls
     188    } {
     189        set re [format {(?:^|\n)([ \t]*)%s} $macro]
     190        while {[regexp -indices $re $info match indent]} {
     191            set code [set $var]
     192            foreach {m0 m1} $match break
     193            foreach {i0 i1} $indent break
     194            if {$i1-$i0 > 0} {
     195                set indent [string range $info $i0 $i1]
     196                set newcode ""
     197                foreach line [split $code \n] {
     198                    append newcode $indent $line "\n"
     199                }
     200                set code [string trimright $newcode \n]
     201            }
     202            if {[string index $info $m0] eq "\n"} { set code "\n$code" }
     203            set info [string replace $info $m0 $m1 $code]
     204        }
     205    }
     206
     207    # make substitutions for any remaining macros
     208    set info [string map $params(-macros) $info]
    166209
    167210    # return the generated code
     
    265308    # used to register a script that processes an input/output element
    266309    public method handler {pattern body} {
    267         set i [lsearch $_patterns $pattern]
     310        set i [lsearch -exact $_patterns $pattern]
    268311        if {$i < 0} { lappend _patterns $pattern }
    269312        set _pat2code($pattern) $body
     
    271314
    272315    # used to generate the output for a specific Rappture object in this lang
    273     public method generate {xmlobj path} {
     316    public method generate {xmlobj path {what "-code"}} {
    274317        variable genParser
    275318        variable genOutput ""
     319        variable genDecls ""
    276320        variable genXmlobj $xmlobj
    277321        variable genPath $path
     
    297341        $genParser eval $code
    298342
    299         return $genOutput
     343        switch -- $what {
     344            -code   { return $genOutput }
     345            -decl   { return $genDecls }
     346            default { error "bad option \"$what\": should be -code, -decl" }
     347        }
    300348    }
    301349
     
    309357    #
    310358    private common genParser [interp create -safe]
    311     $genParser alias puts RapptureBuilder::templates::LangDef::cmd_puts
     359    $genParser alias code RapptureBuilder::templates::LangDef::cmd_code
     360    $genParser alias decl RapptureBuilder::templates::LangDef::cmd_decl
    312361    $genParser alias attr RapptureBuilder::templates::LangDef::cmd_attr
    313362
    314     private common genOutput ""  ;# gathers the output from genParser
     363    private common genOutput ""  ;# gathers code output from genParser
     364    private common genDecls ""   ;# gathers declarations from genParser
    315365    private common genXmlobj ""  ;# Rappture tool spec
    316366    private common genPath ""    ;# current path in the genXmlobj data
    317367
    318368    # like the std "puts" command, but adds output to the generated code
    319     proc cmd_puts {args} {
     369    proc cmd_code {args} {
    320370        set nl "\n"
    321371        while {[llength $args] > 1} {
     
    334384    }
    335385
     386    # like the std "puts" command, but adds output to code declarations
     387    proc cmd_decl {args} {
     388        set nl "\n"
     389        while {[llength $args] > 1} {
     390            set opt [lindex $args 0]
     391            set args [lrange $args 1 end]
     392            if {$opt eq "-nonewline"} {
     393                set nl ""
     394            } else {
     395                error "bad option \"$opt\": should be -nonewline"
     396            }
     397        }
     398        if {[llength $args] != 1} {
     399            error "wrong # args: should be \"puts ?-nonewline? string\""
     400        }
     401        append genDecls [lindex $args 0] $nl
     402    }
     403
    336404    # used to query attribute info for the current object
    337405    proc cmd_attr {option name} {
  • trunk/builder/scripts/templates/python.tl

    r2147 r2153  
    99# ======================================================================
    1010language "Python" {
     11  extension ".py"
     12  command {python @tool/@@FILENAME@@ @driver}
     13
    1114  main {# ----------------------------------------------------------------------
    1215#  MAIN PROGRAM - generated by the Rappture Builder
     
    2427@@INPUTS@@
    2528
    26 # : : : : : : : : : : : : : : : : : : : : : : : : : : : :
     29#########################################################
    2730#  Add your code here for the main body of your program
    28 # : : : : : : : : : : : : : : : : : : : : : : : : : : : :
     31#########################################################
    2932
    3033# spit out progress messages as you go along...
     
    4447
    4548  input boolean {
    46     puts "\n# get input value for $path"
    47     puts "# returns value as string \"yes\" or \"no\""
    48     puts "$id = io.get('$path.current')"
     49    code "\n# get input value for $path"
     50    code "# returns value as string \"yes\" or \"no\""
     51    code "$id = io.get('$path.current')"
    4952  }
    5053  input image {
    51     puts "\n# get input value for $path"
    52     puts "# returns base64-encoded image data"
    53     puts "$id = io.get('$path.current')"
     54    code "\n# get input value for $path"
     55    code "# returns base64-encoded image data"
     56    code "$id = io.get('$path.current')"
    5457  }
    5558  input number {
    5659    set units [attr get units]
    5760    if {$units ne ""} {
    58       puts "\n# get input value for $path and convert to $units"
    59       puts "str = io.get('$path.current')"
    60       puts "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")"
     61      code "\n# get input value for $path and convert to $units"
     62      code "str = io.get('$path.current')"
     63      code "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")"
    6164    } else {
    62       puts "\n# get input value for $path"
    63       puts "$id = io.get('$path.current')"
     65      code "\n# get input value for $path"
     66      code "$id = io.get('$path.current')"
    6467    }
    6568  }
    6669  input * {
    67     puts "\n# get input value for $path"
    68     puts "$id = io.get('$path.current')"
     70    code "\n# get input value for $path"
     71    code "$id = io.get('$path.current')"
    6972  }
    7073
    7174  output curve {
    72     puts "\n# save output value for $path"
    73     puts "# this shows just one (x,y) point -- modify as needed"
    74     puts "line = "%g %g\n" % (x, y)"
    75     puts "io.put('$path.component.xy', line, append=1)"
     75    code "\n# save output value for $path"
     76    code "# this shows just one (x,y) point -- modify as needed"
     77    code "line = "%g %g\n" % (x, y)"
     78    code "io.put('$path.component.xy', line, append=1)"
    7679  }
    7780  output histogram {
    78     puts "\n# save output value for $path"
    79     puts "# this shows just one point -- modify as needed"
    80     puts "# (x,h,w) = x-coord, height of bar, and width of bar (optional)"
    81     puts "line = "%g %g %g\n" % (x, h, w)"
    82     puts "io.put('$path.component.xhw', line, append=1)"
     81    code "\n# save output value for $path"
     82    code "# this shows just one point -- modify as needed"
     83    code "# (x,h,w) = x-coord, height of bar, and width of bar (optional)"
     84    code "line = "%g %g %g\n" % (x, h, w)"
     85    code "io.put('$path.component.xhw', line, append=1)"
    8386  }
    8487  output image {
    85     puts "\n# save output value for $path"
    86     puts "# data should be base64-encoded image data"
    87     puts "io.put('$path.current', imdata)"
     88    code "\n# save output value for $path"
     89    code "# data should be base64-encoded image data"
     90    code "io.put('$path.current', imdata)"
    8891  }
    8992  output * {
    90     puts "\n# save output value for $path"
    91     puts "io.put('$path.current',$id)"
     93    code "\n# save output value for $path"
     94    code "io.put('$path.current',$id)"
    9295  }
    9396}
  • trunk/builder/scripts/templates/tcl.tl

    r2147 r2153  
    99# ======================================================================
    1010language "Tcl" {
     11  extension ".tcl"
     12  command {tclsh @tool/@@FILENAME@@ @driver}
     13
    1114  main {# ----------------------------------------------------------------------
    1215#  MAIN PROGRAM - generated by the Rappture Builder
     
    2225@@INPUTS@@
    2326
    24 # : : : : : : : : : : : : : : : : : : : : : : : : : : : :
     27#########################################################
    2528#  Add your code here for the main body of your program
    26 # : : : : : : : : : : : : : : : : : : : : : : : : : : : :
     29#########################################################
    2730
    2831# spit out progress messages as you go along...
     
    4245
    4346  input boolean {
    44     puts "\n# get input value for $path"
    45     puts "# returns value as string \"yes\" or \"no\""
    46     puts "set $id \[\$io get $path.current\]"
     47    code "\n# get input value for $path"
     48    code "# returns value as string \"yes\" or \"no\""
     49    code "set $id \[\$io get $path.current\]"
    4750  }
    4851  input image {
    49     puts "\n# get input value for $path"
    50     puts "# returns base64-encoded image data"
    51     puts "set imdata \[\$io get $path.current\]"
    52     puts "set $id \[image create photo -data \$imdata\]"
     52    code "\n# get input value for $path"
     53    code "# returns base64-encoded image data"
     54    code "set imdata \[\$io get $path.current\]"
     55    code "set $id \[image create photo -data \$imdata\]"
    5356  }
    5457  input number {
    5558    set units [attr get units]
    5659    if {$units ne ""} {
    57       puts "\n# get input value for $path and convert to $units"
    58       puts "set str \[\$io get $path.current\]"
    59       puts "set $id \[Rappture::Units::convert \$str -to $units -units off\]"
     60      code "\n# get input value for $path and convert to $units"
     61      code "set str \[\$io get $path.current\]"
     62      code "set $id \[Rappture::Units::convert \$str -to $units -units off\]"
    6063    } else {
    61       puts "\n# get input value for $path"
    62       puts "set $id \[\$io get $path.current\]"
     64      code "\n# get input value for $path"
     65      code "set $id \[\$io get $path.current\]"
    6366    }
    6467  }
    6568  input * {
    66     puts "\n# get input value for $path"
    67     puts "set $id \[\$io get $path.current\]"
     69    code "\n# get input value for $path"
     70    code "set $id \[\$io get $path.current\]"
    6871  }
    6972
    7073  output curve {
    71     puts "\n# save output value for $path"
    72     puts "# this shows just one (x,y) point -- modify as needed"
    73     puts "\$io put -append yes $path.component.xy \"\$x \$y\\n\""
     74    code "\n# save output value for $path"
     75    code "# this shows just one (x,y) point -- modify as needed"
     76    code "\$io put -append yes $path.component.xy \"\$x \$y\\n\""
    7477  }
    7578  output histogram {
    76     puts "\n# save output value for $path"
    77     puts "# this shows just one point -- modify as needed"
    78     puts "# (x,h,w) = x-coord, height of bar, and width of bar (optional)"
    79     puts "\$io put -append yes $path.component.xy \"\$x \$h \$w\\n\""
     79    code "\n# save output value for $path"
     80    code "# this shows just one point -- modify as needed"
     81    code "# (x,h,w) = x-coord, height of bar, and width of bar (optional)"
     82    code "\$io put -append yes $path.component.xy \"\$x \$h \$w\\n\""
    8083  }
    8184  output image {
    82     puts "\n# save output value for $path"
    83     puts "# this assumes that \$imh is the handle for a Tk photo image"
    84     puts "\$io put $path.current \[\$imh data -format gif\]"
     85    code "\n# save output value for $path"
     86    code "# this assumes that \$imh is the handle for a Tk photo image"
     87    code "\$io put $path.current \[\$imh data -format gif\]"
    8588  }
    8689  output * {
    87     puts "\n# save output value for $path"
    88     puts "\$io put $path.current \$id"
     90    code "\n# save output value for $path"
     91    code "\$io put $path.current \$id"
    8992  }
    9093}
  • trunk/builder/scripts/tool.rp

    r2082 r2153  
    44    attr title -type string -path title
    55    attr description -type string:lines=6 -expand yes -path about
    6     attr command -type string -path command
     6    attr command -title "Program" -type language -path command
    77
    88    check title {
Note: See TracChangeset for help on using the changeset viewer.