source: trunk/gui/apps/driver @ 1206

Last change on this file since 1206 was 1206, checked in by dkearney, 16 years ago

moving about.tcl to about.in.
moving simsim.tcl to simsim.in.
adding xmldiff, a script to give you teh text differences between two xml files.
reorganized simsim's flags, comparison of xmlfiles works, still need to check creating random inputs for driver files.
adding -nosim flag to rerun to avoid simulations while rerunning a run file. this flag should stay set until we get the "load and continue simulating" functionality working.
adding xmldiff to configure and makefiles

File size: 10.0 KB
Line 
1#!/bin/sh
2# ----------------------------------------------------------------------
3#  USER INTERFACE DRIVER
4#
5#  This driver program loads a tool description from a tool.xml file,
6#  and produces a user interface automatically to drive an application.
7#  The user can set up input, click and button to launch a tool, and
8#  browse through output.
9#
10#  RUN AS FOLLOWS:
11#    driver ?-tool <toolfile>?
12#
13#  If the <toolfile> is not specified, it defaults to "tool.xml" in
14#  the current working directory.
15#
16# ======================================================================
17#  AUTHOR:  Michael McLennan, Purdue University
18#  Copyright (c) 2004-2005  Purdue Research Foundation
19#
20#  See the file "license.terms" for information on usage and
21#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
22# ======================================================================
23#\
24exec wish "$0" $*
25# ----------------------------------------------------------------------
26# wish executes everything from here on...
27
28package require Itcl
29package require Rappture
30package require RapptureGUI
31
32option add *MainWin.mode desktop startupFile
33option add *MainWin.borderWidth 0 startupFile
34option add *MainWin.anchor fill startupFile
35
36# "web site" look
37option add *MainWin.bgScript {
38    rectangle 0 0 200 <h> -outline "" -fill #5880BB
39    rectangle 200 0 300 <h> -outline "" -fill #425F8B
40    rectangle 300 0 <w> <h> -outline "" -fill #324565
41} startupFile
42
43# "clean" look
44option add *MainWin.bgScript "" startupFile
45option add *MainWin.bgColor white startupFile
46option add *Tooltip.background white
47option add *Editor.background white
48option add *Gauge.textBackground white
49option add *TemperatureGauge.textBackground white
50option add *Switch.textBackground white
51option add *Progress.barColor #ffffcc
52option add *Balloon.titleBackground #6666cc
53option add *Balloon.titleForeground white
54option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-12-*
55option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-12-*
56option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-12-*
57option add *ResultSet.controlbarBackground #6666cc
58option add *ResultSet.controlbarForeground white
59option add *ResultSet.activeControlBackground #ccccff
60option add *ResultSet.activeControlForeground black
61option add *Radiodial.length 3i
62option add *BugReport*banner*foreground white
63option add *BugReport*banner*background #a9a9a9
64option add *BugReport*banner*highlightBackground #a9a9a9
65option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-18-*
66
67switch $tcl_platform(platform) {
68    unix - windows {
69        event add <<PopupMenu>> <ButtonPress-3>
70    }
71    macintosh {
72        event add <<PopupMenu>> <Control-ButtonPress-1>
73    }
74}
75
76# install a better bug handler
77Rappture::bugreport::install
78
79# fix the "grab" command to support a stack of grab windows
80Rappture::grab::init
81
82#
83# Process command line args to get the names of files to load...
84#
85Rappture::getopts argv params {
86    value -tool tool.xml
87    value -load ""
88    value -nosim 0
89}
90
91# rewrite out params(-load) variable with a properly split list of files
92array set params [list -load [split $params(-load) ","]]
93
94set loadobjs {}
95foreach runfile $params(-load) {
96    if {![file exists $runfile]} {
97        puts stderr "can't find run: \"$runfile\""
98        exit 1
99    }
100    set status [catch {Rappture::library $runfile} result]
101    lappend loadobjs $result
102}
103
104# open the XML file containing the tool parameters
105if {![file exists $params(-tool)]} {
106    # check to see if the user specified any run.xml files to load.
107    # if so, we can use that as the tool.xml. if we can find where
108    # the original application was installed using the xml tag
109    # tool.version.application.directory(top), the user can
110    # run new simulations, otherwise they can only revisualize the
111    # run.xml files they are loading.
112    set pseudotool ""
113    if {0 == [llength $loadobjs]} {
114        puts stderr "can't find tool \"$params(-tool)\""
115        exit 1
116    }
117    # search the loadfiles for the install location
118    # we could just use run.xml files as tool.xml, but
119    # if there are loaders or notes, they will still need
120    # examples/ and docs/ dirs from the install location
121    foreach runobj $loadobjs {
122        set tdir [$runobj get tool.version.application.directory(tool)]
123        if {[file isdirectory $tdir] && \
124            [file exists $tdir/tool.xml]} {
125            set pseudotool $tdir/tool.xml
126            break
127        }
128    }
129    if {![file exists $pseudotool]} {
130        # we didn't find a tool.xml file,
131        # use info from a runfile to build gui
132        # disable simulation, because no tool.xml
133        set pseudotool [lindex $params(-load) 0]
134        array set params [list -nosim true]
135    }
136    if {![file exists $pseudotool]} {
137        puts stderr "can't find tool \"$params(-tool)\""
138        exit 1
139    }
140    array set params [list -tool $pseudotool]
141}
142
143set xmlobj [Rappture::library $params(-tool)]
144
145set installdir [file dirname $params(-tool)]
146if {"." == $installdir} {
147    set installdir [pwd]
148}
149
150set tool [Rappture::Tool ::#auto $xmlobj $installdir]
151
152# ----------------------------------------------------------------------
153# CHECK JOB FAILURE REPORTING
154#
155# If this tool might fail when it launches jobs (i.e., Rappture
156# can't check some inputs, such as strings), then disable the
157# automatic ticket submission for job failures
158# ----------------------------------------------------------------------
159set val [$tool xml get tool.reportJobFailures]
160if {"" != $val} {
161    if {[catch {Rappture::bugreport::shouldReport jobfailures $val} result]} {
162        puts stderr "WARNING for reportJobFailures: $result"
163    }
164}
165
166# ----------------------------------------------------------------------
167# LOAD RESOURCE SETTINGS
168#
169# Try to load the $SESSIONDIR/resources file, which contains
170# middleware settings, such as the application name and the
171# filexfer settings.
172# ----------------------------------------------------------------------
173Rappture::resources::load
174
175# ----------------------------------------------------------------------
176# INITIALIZE THE DESKTOP CONNECTION
177#
178# If there's a SESSION ID, then this must be running within the
179# nanoHUB.  Try to initialize the server handling the desktop
180# connection.
181# ----------------------------------------------------------------------
182Rappture::filexfer::init
183
184# ----------------------------------------------------------------------
185# MAIN WINDOW
186# ----------------------------------------------------------------------
187wm withdraw .
188Rappture::MainWin .main -borderwidth 0
189.main configure -title [$tool xml get tool.title]
190wm withdraw .main
191
192# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
193if {[info exists env(FULLSCREEN)]} {
194    .main configure -mode web
195}
196
197#
198# The main window has a pager that acts as a notebook for the
199# various parts.  This notebook as at least two pages--an input
200# page and an output (analysis) page.  If there are <phase>'s
201# for input, then there are more pages in the notebook.
202#
203set win [.main component app]
204Rappture::Postern $win.postern
205pack $win.postern -side bottom -fill x
206
207Rappture::Pager $win.pager
208pack $win.pager -expand yes -fill both
209
210set phases [$tool xml children -type phase input]
211if {[llength $phases] > 0} {
212    set plist ""
213    foreach name $phases {
214        lappend plist input.$name
215    }
216    set phases $plist
217} else {
218    set phases input
219}
220
221foreach comp $phases {
222    set title [$tool xml get $comp.about.label]
223    if {$title == ""} {
224        set title "Input #auto"
225    }
226    $win.pager insert end -name $comp -title $title
227
228    #
229    # Build the page of input controls for this phase.
230    #
231    set f [$win.pager page $comp]
232    Rappture::Page $f.cntls $tool $comp
233    pack $f.cntls -expand yes -fill both
234}
235
236# ----------------------------------------------------------------------
237# OUTPUT AREA
238# ----------------------------------------------------------------------
239set simtxt [$xmlobj get tool.action.label]
240if {"" == $simtxt} {
241    set simtxt "Simulate"
242}
243$win.pager insert end -name analyzer -title $simtxt
244set f [$win.pager page analyzer]
245$win.pager page analyzer -command [subst {
246    if { !$params(-nosim) } {
247        $win.pager busy yes
248        update
249        $f.analyze simulate -ifneeded
250        $win.pager busy no
251    }
252}]
253
254Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about
255pack $f.analyze -expand yes -fill both
256
257$tool notify add analyzer * [list $f.analyze reset]
258
259# ----------------------------------------------------------------------
260# Finalize the arrangement
261# ----------------------------------------------------------------------
262if {[llength [$win.pager page]] == 2} {
263    set style [$xmlobj get tool.layout]
264    set screenw [winfo screenwidth .]
265
266    update idletasks
267    set w0 [winfo reqwidth [$win.pager page @0]]
268    set w1 [winfo reqwidth [$win.pager page @1]]
269
270    # if only two windows and they're small enough, put them up side-by-side
271    if {$w0+$w1 < $screenw && $style != "wizard"} {
272        $win.pager configure -arrangement side-by-side
273        $f.analyze configure -holdwindow [$win.pager page @0]
274
275        set type [$tool xml get tool.control]
276        if {$type == ""} {
277            set type [$tool xml get tool.control.type]
278        }
279
280        if {$type == "auto"} {
281            # in "auto" mode, we don't need a simulate button
282            $f.analyze configure -simcontrol off
283        } else {
284            # not in "auto" mode but side-by-side, we always need the button
285            $f.analyze configure -simcontrol on
286        }
287    }
288}
289
290# load previous xml runfiles
291if {0 != [llength $params(-load)]} {
292    foreach runobj $loadobjs {
293        # this doesn't seem to work with loaders
294        # loaders seem to get their value after this point
295        # may need to tell loader elements to update its value
296        $tool load $runobj
297        $f.analyze load $runobj
298    }
299    # don't need simulate button if we cannot simulate
300    if {$params(-nosim)} {
301        $f.analyze configure -simcontrol off
302    }
303    $f.analyze configure -notebookpage analyze
304    $win.pager current analyzer
305}
306
307wm deiconify .main
Note: See TracBrowser for help on using the repository browser.