Ignore:
Timestamp:
Jan 29, 2015, 6:55:17 PM (10 years ago)
Author:
mmc
Message:

Fixed the way that Rappture handles tool parameters. When Rappture starts
up, it looks for the TOOL_PARAMETERS environment variable and loads values
from that file. Any "file" parameters are used to load driver files, run
files, or data into controls. See http://rappture.org/wiki/RapptureApi
for details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/main.tcl

    r3700 r4961  
    9393    value -tool tool.xml
    9494    list  -load ""
     95    value -input ""
    9596    value -nosim 0
    96 }
    97 
    98 proc ReadToolParameters { numTries } {
    99     incr numTries -1
    100     if { $numTries < 0 } {
    101         return
    102     }
    103     global env
    104     set paramsFile $env(TOOL_PARAMETERS)
    105     if { ![file readable $paramsFile] } {
    106         after 500 ReadToolParmeters $numTries
    107         return
    108     }
    109     catch {
    110         set f [open $paramsFile "r"]
    111         set contents [read $f]
    112         close $f
    113         set pattern {^file\((.*)\):(.*)$}
    114         foreach line [split $contents "\n"] {
    115             if { [regexp $pattern $line match path rest] } {
    116                 set ::Rappture::parameters($path) $rest
    117             }
    118         }
    119     }
    120 }
    121 
    122 if { [info exists env(TOOL_PARAMETERS)] } {
    123     ReadToolParameters 10
    12497}
    12598
     
    132105    set status [catch {Rappture::library $runfile} result]
    133106    lappend loadobjs $result
     107}
     108
     109set inputobj {}
     110if {$params(-input) ne ""} {
     111    if {![file exists $params(-input)]} {
     112        puts stderr "can't find input file: \"$params(-input)\""
     113        exit 1
     114    }
     115    if {[catch {Rappture::library $params(-input)} result] == 0} {
     116        set inputobj $result
     117    }
    134118}
    135119
     
    143127    # run.xml files they are loading.
    144128    set pseudotool ""
    145     if {0 == [llength $loadobjs]} {
     129    if {[llength $loadobjs] == 0 && $inputobj eq ""} {
    146130        puts stderr "can't find tool \"$params(-tool)\""
    147131        exit 1
     
    151135    # if there are loaders or notes, they will still need
    152136    # examples/ and docs/ dirs from the install location
    153     foreach runobj $loadobjs {
     137    set check [concat $loadobjs $inputobj]
     138    foreach runobj $check {
    154139        set tdir \
    155140            [string trim [$runobj get tool.version.application.directory(tool)]]
     
    374359
    375360# load previous xml runfiles
    376 if {0 != [llength $params(-load)]} {
     361if {[llength $params(-load)] > 0} {
    377362    foreach runobj $loadobjs {
    378         # this doesn't seem to work with loaders
    379         # loaders seem to get their value after this point
    380         # may need to tell loader elements to update its value
    381         $tool load $runobj
    382363        $f.analyze load $runobj
    383364    }
     365    # load the inputs for the very last run
     366    $tool load $runobj
     367
    384368    # don't need simulate button if we cannot simulate
    385369    if {$params(-nosim)} {
     
    388372    $f.analyze configure -notebookpage analyze
    389373    $win.pager current analyzer
     374} elseif {$params(-input) ne ""} {
     375    $tool load $inputobj
     376}
     377
     378# let components (loaders) settle after the newly loaded runs
     379update
     380
     381foreach path [array names ::Rappture::parameters] {
     382    set fname $::Rappture::parameters($path)
     383    if {[catch {
     384          set fid [open $fname r]
     385          set info [read $fid]
     386          close $fid}] == 0} {
     387
     388        set w [$tool widgetfor $path]
     389        if {$w ne ""} {
     390            if {[catch {$w value [string trim $info]} result]} {
     391                puts stderr "WARNING: bad tool parameter value for \"$path\""
     392                puts stderr "  $result"
     393            }
     394        } else {
     395            puts stderr "WARNING: can't find control for tool parameter: $path"
     396        }
     397    }
    390398}
    391399
Note: See TracChangeset for help on using the changeset viewer.