source: trunk/gui/scripts/main.tcl @ 2117

Last change on this file since 2117 was 2081, checked in by mmc, 14 years ago

Part 2 of the major reorganization to group all of the rappture utilties
under a single rappture command. Builds better now. Still need to fix
up the builder to work with the objects in a different location now.

File size: 11.5 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#    wish main.tcl ?-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-2011  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# ======================================================================
23package require Itcl
24package require Img
25package require Rappture
26package require RapptureGUI
27
28option add *MainWin.mode desktop startupFile
29option add *MainWin.borderWidth 0 startupFile
30option add *MainWin.anchor fill startupFile
31
32# "web site" look
33option add *MainWin.bgScript {
34    rectangle 0 0 200 <h> -outline "" -fill #5880BB
35    rectangle 200 0 300 <h> -outline "" -fill #425F8B
36    rectangle 300 0 <w> <h> -outline "" -fill #324565
37} startupFile
38
39# "clean" look
40option add *MainWin.bgScript "" startupFile
41option add *MainWin.bgColor white startupFile
42option add *Tooltip.background white
43option add *Editor.background white
44option add *Gauge.textBackground white
45option add *TemperatureGauge.textBackground white
46option add *Switch.textBackground white
47option add *Progress.barColor #ffffcc
48option add *Balloon.titleBackground #6666cc
49option add *Balloon.titleForeground white
50option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-12-*
51option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-12-*
52option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-12-*
53option add *ResultSet.controlbarBackground #6666cc
54option add *ResultSet.controlbarForeground white
55option add *ResultSet.activeControlBackground #ccccff
56option add *ResultSet.activeControlForeground black
57option add *Radiodial.length 3i
58option add *BugReport*banner*foreground white
59option add *BugReport*banner*background #a9a9a9
60option add *BugReport*banner*highlightBackground #a9a9a9
61option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-18-*
62option add *hubcntls*Button.padX 0 widgetDefault
63option add *hubcntls*Button.padY 0 widgetDefault
64option add *hubcntls*Button.relief flat widgetDefault
65option add *hubcntls*Button.overRelief raised widgetDefault
66option add *hubcntls*Button.borderWidth 1 widgetDefault
67option add *hubcntls*Button.font \
68    -*-helvetica-medium-r-normal-*-8-* widgetDefault
69
70switch $tcl_platform(platform) {
71    unix - windows {
72        event add <<PopupMenu>> <ButtonPress-3>
73    }
74    macintosh {
75        event add <<PopupMenu>> <Control-ButtonPress-1>
76    }
77}
78
79# install a better bug handler
80Rappture::bugreport::install
81# fix the "grab" command to support a stack of grab windows
82Rappture::grab::init
83
84#
85# Process command line args to get the names of files to load...
86#
87Rappture::getopts argv params {
88    value -tool tool.xml
89    list  -load ""
90    value -nosim 0
91}
92
93set loadobjs {}
94foreach runfile $params(-load) {
95    if {![file exists $runfile]} {
96        puts stderr "can't find run: \"$runfile\""
97        exit 1
98    }
99    set status [catch {Rappture::library $runfile} result]
100    lappend loadobjs $result
101}
102
103# open the XML file containing the tool parameters
104if {![file exists $params(-tool)]} {
105    # check to see if the user specified any run.xml files to load.
106    # if so, we can use that as the tool.xml. if we can find where
107    # the original application was installed using the xml tag
108    # tool.version.application.directory(top), the user can
109    # run new simulations, otherwise they can only revisualize the
110    # run.xml files they are loading.
111    set pseudotool ""
112    if {0 == [llength $loadobjs]} {
113        puts stderr "can't find tool \"$params(-tool)\""
114        exit 1
115    }
116    # search the loadfiles for the install location
117    # we could just use run.xml files as tool.xml, but
118    # if there are loaders or notes, they will still need
119    # examples/ and docs/ dirs from the install location
120    foreach runobj $loadobjs {
121        set tdir [$runobj get tool.version.application.directory(tool)]
122        if {[file isdirectory $tdir] && \
123            [file exists $tdir/tool.xml]} {
124            set pseudotool $tdir/tool.xml
125            break
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
142set xmlobj [Rappture::library $params(-tool)]
143
144set installdir [file dirname $params(-tool)]
145if {"." == $installdir} {
146    set installdir [pwd]
147}
148
149set 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# ----------------------------------------------------------------------
158set val [$tool xml get tool.reportJobFailures]
159if { "" != $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# ----------------------------------------------------------------------
172Rappture::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# ----------------------------------------------------------------------
181Rappture::filexfer::init
182
183# ----------------------------------------------------------------------
184# MAIN WINDOW
185# ----------------------------------------------------------------------
186wm withdraw .
187Rappture::MainWin .main -borderwidth 0
188.main configure -title [$tool xml get tool.title]
189wm withdraw .main
190
191# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
192if {[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#
202set win [.main component app]
203Rappture::Postern $win.postern
204pack $win.postern -side bottom -fill x
205
206Rappture::Pager $win.pager
207pack $win.pager -expand yes -fill both
208
209#
210# Add a place for about/questions in the breadcrumbs area of this pager.
211#
212set app [$tool xml get tool.id]
213set url [Rappture::Tool::resources -huburl]
214if {"" != $url && "" != $app} {
215    set f [$win.pager component breadcrumbarea]
216    frame $f.hubcntls
217    pack $f.hubcntls -side right -padx 4
218    label $f.hubcntls.icon -image [Rappture::icon ask] -highlightthickness 0
219    pack $f.hubcntls.icon -side left
220    button $f.hubcntls.about -text "About this tool" \
221        -command [list Rappture::filexfer::webpage "$url/tools/$app"]
222    pack $f.hubcntls.about -side top -anchor w
223    button $f.hubcntls.questions -text Questions? \
224        -command [list Rappture::filexfer::webpage "$url/resources/$app/questions"]
225    pack $f.hubcntls.questions -side top -anchor w
226}
227
228#
229# Load up the components in the various phases of input.
230#
231set phases [$tool xml children -type phase input]
232if {[llength $phases] > 0} {
233    set plist ""
234    foreach name $phases {
235        lappend plist input.$name
236    }
237    set phases $plist
238} else {
239    set phases input
240}
241
242foreach comp $phases {
243    set title [$tool xml get $comp.about.label]
244    if {$title == ""} {
245        set title "Input #auto"
246    }
247    $win.pager insert end -name $comp -title $title
248
249    #
250    # Build the page of input controls for this phase.
251    #
252    set f [$win.pager page $comp]
253    Rappture::Page $f.cntls $tool $comp
254    pack $f.cntls -expand yes -fill both
255}
256
257# let components (loaders) in the newly created pages settle
258update
259
260# ----------------------------------------------------------------------
261# OUTPUT AREA
262# ----------------------------------------------------------------------
263
264# adjust the title of the page here.
265# to adjust the button text, look in analyzer.tcl
266set simtxt [$xmlobj get tool.action.label]
267if {"" == $simtxt} {
268    set simtxt "Simulate"
269}
270$win.pager insert end -name analyzer -title $simtxt
271set f [$win.pager page analyzer]
272$win.pager page analyzer -command [subst {
273    if { !$params(-nosim) } {
274        $win.pager busy yes
275        update
276        $f.analyze simulate -ifneeded
277        $win.pager busy no
278    }
279}]
280
281Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about
282pack $f.analyze -expand yes -fill both
283
284$tool notify add analyzer * [list $f.analyze reset]
285
286# ----------------------------------------------------------------------
287# Finalize the arrangement
288# ----------------------------------------------------------------------
289if {[llength [$win.pager page]] == 2} {
290    set style [$xmlobj get tool.layout]
291    set screenw [winfo screenwidth .]
292
293    update idletasks
294    set w0 [winfo reqwidth [$win.pager page @0]]
295    set w1 [winfo reqwidth [$win.pager page @1]]
296
297    if { $style != "wizard" } {
298        # If only two windows and they're small enough, put them up
299        # side-by-side
300        if {$w0+$w1 < $screenw } {
301            $win.pager configure -arrangement side-by-side
302            $f.analyze configure -holdwindow [$win.pager page @0]
303        }
304    }
305    set type [$tool xml get tool.control]
306    if {$type == ""} {
307        set type [$tool xml get tool.control.type]
308    }
309    set arrangement [$win.pager cget -arrangement]
310    if { $type == "" } {
311        if { $arrangement != "side-by-side" } {
312           set type auto
313        }
314    }
315    if { $arrangement != "side-by-side" &&
316            ($type == "manual" || $type == "auto" || $style == "wizard") } {
317        # in "auto" mode, we don't need a simulate button
318        $f.analyze configure -simcontrol off
319    } else {
320        # not in "auto" mode but side-by-side, we always need the button
321        $f.analyze configure -simcontrol on
322    }
323} elseif {[llength [$win.pager page]] > 2} {
324    # We have phases, so we shouldn't allow the "Simulate" button.
325    # If it pops up, there are two ways to push simulate and duplicate
326    # links for "About" and "Questions?".
327    $f.analyze configure -simcontrol off
328}
329
330# load previous xml runfiles
331if {0 != [llength $params(-load)]} {
332    foreach runobj $loadobjs {
333        # this doesn't seem to work with loaders
334        # loaders seem to get their value after this point
335        # may need to tell loader elements to update its value
336        $tool load $runobj
337        $f.analyze load $runobj
338    }
339    # don't need simulate button if we cannot simulate
340    if {$params(-nosim)} {
341        $f.analyze configure -simcontrol off
342    }
343    $f.analyze configure -notebookpage analyze
344    $win.pager current analyzer
345}
346
347wm deiconify .main
Note: See TracBrowser for help on using the repository browser.