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 | #\ |
---|
24 | exec wish "$0" $* |
---|
25 | # ---------------------------------------------------------------------- |
---|
26 | # wish executes everything from here on... |
---|
27 | |
---|
28 | package require Itcl |
---|
29 | package require Rappture |
---|
30 | package require RapptureGUI |
---|
31 | |
---|
32 | option add *MainWin.mode desktop startupFile |
---|
33 | option add *MainWin.borderWidth 0 startupFile |
---|
34 | option add *MainWin.anchor fill startupFile |
---|
35 | |
---|
36 | # "web site" look |
---|
37 | option 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 |
---|
44 | option add *MainWin.bgScript "" startupFile |
---|
45 | option add *MainWin.bgColor white startupFile |
---|
46 | option add *Tooltip.background white |
---|
47 | option add *Editor.background white |
---|
48 | option add *Gauge.textBackground white |
---|
49 | option add *TemperatureGauge.textBackground white |
---|
50 | option add *Switch.textBackground white |
---|
51 | option add *Progress.barColor #ffffcc |
---|
52 | option add *Balloon.titleBackground #6666cc |
---|
53 | option add *Balloon.titleForeground white |
---|
54 | option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-12-* |
---|
55 | option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-12-* |
---|
56 | option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-12-* |
---|
57 | option add *ResultSet.controlbarBackground #6666cc |
---|
58 | option add *ResultSet.controlbarForeground white |
---|
59 | option add *ResultSet.activeControlBackground #ccccff |
---|
60 | option add *ResultSet.activeControlForeground black |
---|
61 | option add *Radiodial.length 3i |
---|
62 | option add *BugReport*banner*foreground white |
---|
63 | option add *BugReport*banner*background #a9a9a9 |
---|
64 | option add *BugReport*banner*highlightBackground #a9a9a9 |
---|
65 | option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-18-* |
---|
66 | |
---|
67 | switch $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 |
---|
77 | Rappture::bugreport::install |
---|
78 | |
---|
79 | # fix the "grab" command to support a stack of grab windows |
---|
80 | Rappture::grab::init |
---|
81 | |
---|
82 | # |
---|
83 | # Process command line args to get the names of files to load... |
---|
84 | # |
---|
85 | Rappture::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 |
---|
92 | array set params [list -load [split $params(-load) ","]] |
---|
93 | |
---|
94 | set loadobjs {} |
---|
95 | foreach 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 |
---|
105 | if {![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 | set lflen [llength $loadobjs)] |
---|
114 | if {0 == $lflen} { |
---|
115 | puts stderr "can't find tool \"$params(-tool)\"" |
---|
116 | exit 1 |
---|
117 | } |
---|
118 | if {!$params(-nosim)} { |
---|
119 | foreach runobj $loadobjs { |
---|
120 | set tdir [$runobj get tool.version.application.directory(tool)] |
---|
121 | if {[file isdirectory $tdir] && \ |
---|
122 | [file exists $tdir/tool.xml]} { |
---|
123 | set pseudotool $tdir/tool.xml |
---|
124 | break |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | if {![file exists $pseudotool]} { |
---|
129 | # we didn't find a tool.xml file, |
---|
130 | # use info from a runfile to build gui |
---|
131 | # disable simulation, because no tool.xml |
---|
132 | set pseudotool [lindex $params(-load) 0] |
---|
133 | array set params [list -nosim true] |
---|
134 | } |
---|
135 | if {![file exists $pseudotool]} { |
---|
136 | puts stderr "can't find tool \"$params(-tool)\"" |
---|
137 | exit 1 |
---|
138 | } |
---|
139 | array set params [list -tool $pseudotool] |
---|
140 | } |
---|
141 | |
---|
142 | set xmlobj [Rappture::library $params(-tool)] |
---|
143 | |
---|
144 | set installdir [file dirname $params(-tool)] |
---|
145 | if {"." == $installdir} { |
---|
146 | set installdir [pwd] |
---|
147 | } |
---|
148 | |
---|
149 | set tool [Rappture::Tool ::#auto $xmlobj $installdir] |
---|
150 | |
---|
151 | # ---------------------------------------------------------------------- |
---|
152 | # CHECK JOB FAILURE REPORTING |
---|
153 | # |
---|
154 | # If this tool might fail when it launches jobs (i.e., Rappture |
---|
155 | # can't check some inputs, such as strings), then disable the |
---|
156 | # automatic ticket submission for job failures |
---|
157 | # ---------------------------------------------------------------------- |
---|
158 | set val [$tool xml get tool.reportJobFailures] |
---|
159 | if {"" != $val} { |
---|
160 | if {[catch {Rappture::bugreport::shouldReport jobfailures $val} result]} { |
---|
161 | puts stderr "WARNING for reportJobFailures: $result" |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | # ---------------------------------------------------------------------- |
---|
166 | # LOAD RESOURCE SETTINGS |
---|
167 | # |
---|
168 | # Try to load the $SESSIONDIR/resources file, which contains |
---|
169 | # middleware settings, such as the application name and the |
---|
170 | # filexfer settings. |
---|
171 | # ---------------------------------------------------------------------- |
---|
172 | Rappture::resources::load |
---|
173 | |
---|
174 | # ---------------------------------------------------------------------- |
---|
175 | # INITIALIZE THE DESKTOP CONNECTION |
---|
176 | # |
---|
177 | # If there's a SESSION ID, then this must be running within the |
---|
178 | # nanoHUB. Try to initialize the server handling the desktop |
---|
179 | # connection. |
---|
180 | # ---------------------------------------------------------------------- |
---|
181 | Rappture::filexfer::init |
---|
182 | |
---|
183 | # ---------------------------------------------------------------------- |
---|
184 | # MAIN WINDOW |
---|
185 | # ---------------------------------------------------------------------- |
---|
186 | wm withdraw . |
---|
187 | Rappture::MainWin .main -borderwidth 0 |
---|
188 | .main configure -title [$tool xml get tool.title] |
---|
189 | wm withdraw .main |
---|
190 | |
---|
191 | # if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen |
---|
192 | if {[info exists env(FULLSCREEN)]} { |
---|
193 | .main configure -mode web |
---|
194 | } |
---|
195 | |
---|
196 | # |
---|
197 | # The main window has a pager that acts as a notebook for the |
---|
198 | # various parts. This notebook as at least two pages--an input |
---|
199 | # page and an output (analysis) page. If there are <phase>'s |
---|
200 | # for input, then there are more pages in the notebook. |
---|
201 | # |
---|
202 | set win [.main component app] |
---|
203 | Rappture::Postern $win.postern |
---|
204 | pack $win.postern -side bottom -fill x |
---|
205 | |
---|
206 | Rappture::Pager $win.pager |
---|
207 | pack $win.pager -expand yes -fill both |
---|
208 | |
---|
209 | set phases [$tool xml children -type phase input] |
---|
210 | if {[llength $phases] > 0} { |
---|
211 | set plist "" |
---|
212 | foreach name $phases { |
---|
213 | lappend plist input.$name |
---|
214 | } |
---|
215 | set phases $plist |
---|
216 | } else { |
---|
217 | set phases input |
---|
218 | } |
---|
219 | |
---|
220 | foreach comp $phases { |
---|
221 | set title [$tool xml get $comp.about.label] |
---|
222 | if {$title == ""} { |
---|
223 | set title "Input #auto" |
---|
224 | } |
---|
225 | $win.pager insert end -name $comp -title $title |
---|
226 | |
---|
227 | # |
---|
228 | # Build the page of input controls for this phase. |
---|
229 | # |
---|
230 | set f [$win.pager page $comp] |
---|
231 | Rappture::Page $f.cntls $tool $comp |
---|
232 | pack $f.cntls -expand yes -fill both |
---|
233 | } |
---|
234 | |
---|
235 | # ---------------------------------------------------------------------- |
---|
236 | # OUTPUT AREA |
---|
237 | # ---------------------------------------------------------------------- |
---|
238 | set simtxt [$xmlobj get tool.action.label] |
---|
239 | if {"" == $simtxt} { |
---|
240 | set simtxt "Simulate" |
---|
241 | } |
---|
242 | $win.pager insert end -name analyzer -title $simtxt |
---|
243 | set f [$win.pager page analyzer] |
---|
244 | $win.pager page analyzer -command [subst { |
---|
245 | $win.pager busy yes |
---|
246 | update |
---|
247 | $f.analyze simulate -ifneeded |
---|
248 | $win.pager busy no |
---|
249 | }] |
---|
250 | |
---|
251 | # can we call analyzer without specifying -notebookpage? |
---|
252 | Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about |
---|
253 | pack $f.analyze -expand yes -fill both |
---|
254 | |
---|
255 | $tool notify add analyzer * [list $f.analyze reset] |
---|
256 | |
---|
257 | # ---------------------------------------------------------------------- |
---|
258 | # Finalize the arrangement |
---|
259 | # ---------------------------------------------------------------------- |
---|
260 | if {[llength [$win.pager page]] == 2} { |
---|
261 | set style [$xmlobj get tool.layout] |
---|
262 | set screenw [winfo screenwidth .] |
---|
263 | |
---|
264 | update idletasks |
---|
265 | set w0 [winfo reqwidth [$win.pager page @0]] |
---|
266 | set w1 [winfo reqwidth [$win.pager page @1]] |
---|
267 | |
---|
268 | # if only two windows and they're small enough, put them up side-by-side |
---|
269 | if {$w0+$w1 < $screenw && $style != "wizard"} { |
---|
270 | $win.pager configure -arrangement side-by-side |
---|
271 | $f.analyze configure -holdwindow [$win.pager page @0] |
---|
272 | |
---|
273 | set type [$tool xml get tool.control] |
---|
274 | if {$type == ""} { |
---|
275 | set type [$tool xml get tool.control.type] |
---|
276 | } |
---|
277 | |
---|
278 | if {$type == "auto"} { |
---|
279 | # in "auto" mode, we don't need a simulate button |
---|
280 | $f.analyze configure -simcontrol off |
---|
281 | } else { |
---|
282 | # not in "auto" mode but side-by-side, we always need the button |
---|
283 | $f.analyze configure -simcontrol on |
---|
284 | } |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | # load previous xml runfiles |
---|
289 | if {0 != [llength $params(-load)]} { |
---|
290 | foreach runobj $loadobjs { |
---|
291 | $f.analyze load $runobj |
---|
292 | } |
---|
293 | $f.analyze configure -notebookpage analyze |
---|
294 | if {$params(-nosim)} { |
---|
295 | $f.analyze configure -simcontrol off |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | wm deiconify .main |
---|