source: trunk/gui/apps/driver @ 1399

Last change on this file since 1399 was 1399, checked in by gah, 15 years ago

quick fix for sequence/radiodial

File size: 11.4 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-*
66option add *hubcntls*Button.padX 0 widgetDefault
67option add *hubcntls*Button.padY 0 widgetDefault
68option add *hubcntls*Button.relief flat widgetDefault
69option add *hubcntls*Button.overRelief raised widgetDefault
70option add *hubcntls*Button.borderWidth 1 widgetDefault
71option add *hubcntls*Button.font \
72    -*-helvetica-medium-r-normal-*-8-* widgetDefault
73
74switch $tcl_platform(platform) {
75    unix - windows {
76        event add <<PopupMenu>> <ButtonPress-3>
77    }
78    macintosh {
79        event add <<PopupMenu>> <Control-ButtonPress-1>
80    }
81}
82
83# install a better bug handler
84Rappture::bugreport::install
85
86# fix the "grab" command to support a stack of grab windows
87Rappture::grab::init
88
89#
90# Process command line args to get the names of files to load...
91#
92Rappture::getopts argv params {
93    value -tool tool.xml
94    list  -load ""
95    value -nosim 0
96}
97
98set loadobjs {}
99foreach runfile $params(-load) {
100    if {![file exists $runfile]} {
101        puts stderr "can't find run: \"$runfile\""
102        exit 1
103    }
104    set status [catch {Rappture::library $runfile} result]
105    lappend loadobjs $result
106}
107
108# open the XML file containing the tool parameters
109if {![file exists $params(-tool)]} {
110    # check to see if the user specified any run.xml files to load.
111    # if so, we can use that as the tool.xml. if we can find where
112    # the original application was installed using the xml tag
113    # tool.version.application.directory(top), the user can
114    # run new simulations, otherwise they can only revisualize the
115    # run.xml files they are loading.
116    set pseudotool ""
117    if {0 == [llength $loadobjs]} {
118        puts stderr "can't find tool \"$params(-tool)\""
119        exit 1
120    }
121    # search the loadfiles for the install location
122    # we could just use run.xml files as tool.xml, but
123    # if there are loaders or notes, they will still need
124    # examples/ and docs/ dirs from the install location
125    foreach runobj $loadobjs {
126        set tdir [$runobj get tool.version.application.directory(tool)]
127        if {[file isdirectory $tdir] && \
128            [file exists $tdir/tool.xml]} {
129            set pseudotool $tdir/tool.xml
130            break
131        }
132    }
133    if {![file exists $pseudotool]} {
134        # we didn't find a tool.xml file,
135        # use info from a runfile to build gui
136        # disable simulation, because no tool.xml
137        set pseudotool [lindex $params(-load) 0]
138        array set params [list -nosim true]
139    }
140    if {![file exists $pseudotool]} {
141        puts stderr "can't find tool \"$params(-tool)\""
142        exit 1
143    }
144    array set params [list -tool $pseudotool]
145}
146
147set xmlobj [Rappture::library $params(-tool)]
148
149set installdir [file dirname $params(-tool)]
150if {"." == $installdir} {
151    set installdir [pwd]
152}
153
154set tool [Rappture::Tool ::#auto $xmlobj $installdir]
155
156# ----------------------------------------------------------------------
157# CHECK JOB FAILURE REPORTING
158#
159# If this tool might fail when it launches jobs (i.e., Rappture
160# can't check some inputs, such as strings), then disable the
161# automatic ticket submission for job failures
162# ----------------------------------------------------------------------
163set val [$tool xml get tool.reportJobFailures]
164if {"" != $val} {
165    if {[catch {Rappture::bugreport::shouldReport jobfailures $val} result]} {
166        puts stderr "WARNING for reportJobFailures: $result"
167    }
168}
169
170# ----------------------------------------------------------------------
171# LOAD RESOURCE SETTINGS
172#
173# Try to load the $SESSIONDIR/resources file, which contains
174# middleware settings, such as the application name and the
175# filexfer settings.
176# ----------------------------------------------------------------------
177Rappture::resources::load
178
179# ----------------------------------------------------------------------
180# INITIALIZE THE DESKTOP CONNECTION
181#
182# If there's a SESSION ID, then this must be running within the
183# nanoHUB.  Try to initialize the server handling the desktop
184# connection.
185# ----------------------------------------------------------------------
186Rappture::filexfer::init
187
188# ----------------------------------------------------------------------
189# MAIN WINDOW
190# ----------------------------------------------------------------------
191wm withdraw .
192Rappture::MainWin .main -borderwidth 0
193.main configure -title [$tool xml get tool.title]
194wm withdraw .main
195
196# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
197if {[info exists env(FULLSCREEN)]} {
198    .main configure -mode web
199}
200
201#
202# The main window has a pager that acts as a notebook for the
203# various parts.  This notebook as at least two pages--an input
204# page and an output (analysis) page.  If there are <phase>'s
205# for input, then there are more pages in the notebook.
206#
207set win [.main component app]
208Rappture::Postern $win.postern
209pack $win.postern -side bottom -fill x
210
211Rappture::Pager $win.pager
212pack $win.pager -expand yes -fill both
213
214#
215# Add a place for about/questions in the breadcrumbs area of this pager.
216#
217set app [$tool xml get tool.id]
218set url [Rappture::Tool::resources -huburl]
219if {"" != $url && "" != $app} {
220    set f [$win.pager component breadcrumbarea]
221    frame $f.hubcntls
222    pack $f.hubcntls -side right -padx 4
223    label $f.hubcntls.icon -image [Rappture::icon ask] -highlightthickness 0
224    pack $f.hubcntls.icon -side left
225    button $f.hubcntls.about -text "About this tool" \
226        -command [list Rappture::filexfer::webpage "$url/tools/$app"]
227    pack $f.hubcntls.about -side top -anchor w
228    button $f.hubcntls.questions -text Questions? \
229        -command [list Rappture::filexfer::webpage "$url/resources/$app/questions"]
230    pack $f.hubcntls.questions -side top -anchor w
231}
232
233#
234# Load up the components in the various phases of input.
235#
236set phases [$tool xml children -type phase input]
237if {[llength $phases] > 0} {
238    set plist ""
239    foreach name $phases {
240        lappend plist input.$name
241    }
242    set phases $plist
243} else {
244    set phases input
245}
246
247foreach comp $phases {
248    set title [$tool xml get $comp.about.label]
249    if {$title == ""} {
250        set title "Input #auto"
251    }
252    $win.pager insert end -name $comp -title $title
253
254    #
255    # Build the page of input controls for this phase.
256    #
257    set f [$win.pager page $comp]
258    Rappture::Page $f.cntls $tool $comp
259    pack $f.cntls -expand yes -fill both
260}
261
262# let components (loaders) in the newly created pages settle
263update
264
265# ----------------------------------------------------------------------
266# OUTPUT AREA
267# ----------------------------------------------------------------------
268
269# adjust the title of the page here.
270# to adjust the button text, look in analyzer.tcl
271set simtxt [$xmlobj get tool.action.label]
272if {"" == $simtxt} {
273    set simtxt "Simulate"
274}
275$win.pager insert end -name analyzer -title $simtxt
276set f [$win.pager page analyzer]
277$win.pager page analyzer -command [subst {
278    if { !$params(-nosim) } {
279        $win.pager busy yes
280        update
281        $f.analyze simulate -ifneeded
282        $win.pager busy no
283    }
284}]
285
286Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about
287pack $f.analyze -expand yes -fill both
288
289$tool notify add analyzer * [list $f.analyze reset]
290
291# ----------------------------------------------------------------------
292# Finalize the arrangement
293# ----------------------------------------------------------------------
294if {[llength [$win.pager page]] == 2} {
295    set style [$xmlobj get tool.layout]
296    set screenw [winfo screenwidth .]
297
298    update idletasks
299    set w0 [winfo reqwidth [$win.pager page @0]]
300    set w1 [winfo reqwidth [$win.pager page @1]]
301
302    # if only two windows and they're small enough, put them up side-by-side
303    if {$w0+$w1 < $screenw && $style != "wizard"} {
304        $win.pager configure -arrangement side-by-side
305        $f.analyze configure -holdwindow [$win.pager page @0]
306
307        set type [$tool xml get tool.control]
308        if {$type == ""} {
309            set type [$tool xml get tool.control.type]
310        }
311
312        if {$type == "auto"} {
313            # in "auto" mode, we don't need a simulate button
314            $f.analyze configure -simcontrol off
315        } else {
316            # not in "auto" mode but side-by-side, we always need the button
317            $f.analyze configure -simcontrol on
318        }
319    }
320} elseif {[llength [$win.pager page]] > 2} {
321    # We have phases, so we shouldn't allow the "Simulate" button.
322    # If it pops up, there are two ways to push simulate and duplicate
323    # links for "About" and "Questions?".
324    $f.analyze configure -simcontrol off
325}
326
327# load previous xml runfiles
328if {0 != [llength $params(-load)]} {
329    foreach runobj $loadobjs {
330        # this doesn't seem to work with loaders
331        # loaders seem to get their value after this point
332        # may need to tell loader elements to update its value
333        $tool load $runobj
334        $f.analyze load $runobj
335    }
336    # don't need simulate button if we cannot simulate
337    if {$params(-nosim)} {
338        $f.analyze configure -simcontrol off
339    }
340    $f.analyze configure -notebookpage analyze
341    $win.pager current analyzer
342}
343
344wm deiconify .main
Note: See TracBrowser for help on using the repository browser.