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

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

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