source: branches/uq/gui/scripts/main.tcl @ 5121

Last change on this file since 5121 was 5121, checked in by dkearney, 9 years ago

merging updates from 1.3 branch

looks like this branch originally came from the 1.3 branch and then had some
additions from the 1.4-pre branch and then a sync from the 1.3 branch. to get
this branch updated, I am reverting r4797 (additions from 1.4-pre branch),
reverting r4798 (additions from 1.3 branch), then merging in updates from 1.3
branch.

I fixed merge conflicts for the following files:

gui/scripts/gauge.tcl
gui/scripts/main.tcl
gui/scripts/tool.tcl
lang/tcl/scripts/task.tcl

File size: 14.0 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2#!/bin/sh
3# ----------------------------------------------------------------------
4#  USER INTERFACE DRIVER
5#
6#  This driver program loads a tool description from a tool.xml file,
7#  and produces a user interface automatically to drive an application.
8#  The user can set up input, click and button to launch a tool, and
9#  browse through output.
10#
11#  RUN AS FOLLOWS:
12#    wish main.tcl ?-tool <toolfile>?
13#
14#  If the <toolfile> is not specified, it defaults to "tool.xml" in
15#  the current working directory.
16#
17# ======================================================================
18#  AUTHOR:  Michael McLennan, Purdue University
19#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
20#
21#  See the file "license.terms" for information on usage and
22#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
23# ======================================================================
24
25# take the main window down for now, so we can avoid a flash on the screen
26wm withdraw .
27
28package require Itcl
29package require Img
30package require Rappture
31package require RapptureGUI
32
33option add *MainWin.mode desktop startupFile
34option add *MainWin.borderWidth 0 startupFile
35option add *MainWin.anchor fill startupFile
36
37# "web site" look
38option add *MainWin.bgScript {
39    rectangle 0 0 200 <h> -outline "" -fill #5880BB
40    rectangle 200 0 300 <h> -outline "" -fill #425F8B
41    rectangle 300 0 <w> <h> -outline "" -fill #324565
42} startupFile
43
44# "clean" look
45option add *MainWin.bgScript "" startupFile
46option add *MainWin.bgColor white startupFile
47option add *Tooltip.background white
48option add *Editor.background white
49option add *Gauge.textBackground white
50option add *TemperatureGauge.textBackground white
51option add *Switch.textBackground white
52option add *Progress.barColor #ffffcc
53option add *Balloon.titleBackground #6666cc
54option add *Balloon.titleForeground white
55option add *Balloon*Label.font -*-helvetica-medium-r-normal-*-12-*
56option add *Balloon*Radiobutton.font -*-helvetica-medium-r-normal-*-12-*
57option add *Balloon*Checkbutton.font -*-helvetica-medium-r-normal-*-12-*
58option add *ResultSelector.controlbarBackground #6666cc
59option add *ResultSelector.controlbarForeground white
60option add *ResultSelector.activeControlBackground #ccccff
61option add *ResultSelector.activeControlForeground black
62option add *Radiodial.length 3i
63option add *BugReport*banner*foreground white
64option add *BugReport*banner*background #a9a9a9
65option add *BugReport*banner*highlightBackground #a9a9a9
66option add *BugReport*banner*font -*-helvetica-bold-r-normal-*-18-*
67option add *hubcntls*Button.padX 0 widgetDefault
68option add *hubcntls*Button.padY 0 widgetDefault
69option add *hubcntls*Button.relief flat widgetDefault
70option add *hubcntls*Button.overRelief raised widgetDefault
71option add *hubcntls*Button.borderWidth 1 widgetDefault
72option add *hubcntls*Button.font \
73    -*-helvetica-medium-r-normal-*-8-* widgetDefault
74
75switch $tcl_platform(platform) {
76    unix - windows {
77        event add <<PopupMenu>> <ButtonPress-3>
78    }
79    macintosh {
80        event add <<PopupMenu>> <Control-ButtonPress-1>
81    }
82}
83
84# install a better bug handler
85Rappture::bugreport::install
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 -input ""
96    value -nosim 0
97}
98
99# mmh
100puts "main.tcl $argv"
101parray params
102
103proc ReadToolParameters { numTries } {
104    incr numTries -1
105    if { $numTries < 0 } {
106        return
107    }
108    global env
109    set paramsFile $env(TOOL_PARAMETERS)
110    if { ![file readable $paramsFile] } {
111        after 500 ReadToolParmeters $numTries
112        return
113    }
114    catch {
115        set f [open $paramsFile "r"]
116        set contents [read $f]
117        close $f
118        set pattern {^file\((.*)\):(.*)$}
119        foreach line [split $contents "\n"] {
120            if { [regexp $pattern $line match path rest] } {
121                set ::Rappture::parameters($path) $rest
122            }
123        }
124    }
125}
126
127if { [info exists env(TOOL_PARAMETERS)] } {
128    ReadToolParameters 10
129}
130
131set loadobjs {}
132foreach runfile $params(-load) {
133    if {![file exists $runfile]} {
134        puts stderr "can't find run: \"$runfile\""
135        exit 1
136    }
137    set status [catch {Rappture::library $runfile} result]
138    lappend loadobjs $result
139}
140
141set inputobj {}
142if {$params(-input) ne ""} {
143    if {![file exists $params(-input)]} {
144        puts stderr "can't find input file: \"$params(-input)\""
145        exit 1
146    }
147    if {[catch {Rappture::library $params(-input)} result] == 0} {
148        set inputobj $result
149    }
150}
151
152# open the XML file containing the tool parameters
153if {![file exists $params(-tool)]} {
154    # check to see if the user specified any run.xml files to load.
155    # if so, we can use that as the tool.xml. if we can find where
156    # the original application was installed using the xml tag
157    # tool.version.application.directory(top), the user can
158    # run new simulations, otherwise they can only revisualize the
159    # run.xml files they are loading.
160    set pseudotool ""
161    if {[llength $loadobjs] == 0 && $inputobj eq ""} {
162        puts stderr "can't find tool \"$params(-tool)\""
163        exit 1
164    }
165    # search the loadfiles for the install location
166    # we could just use run.xml files as tool.xml, but
167    # if there are loaders or notes, they will still need
168    # examples/ and docs/ dirs from the install location
169    set check [concat $loadobjs $inputobj]
170    foreach runobj $check {
171        set tdir \
172            [string trim [$runobj get tool.version.application.directory(tool)]]
173        if {[file isdirectory $tdir] && \
174            [file exists $tdir/tool.xml]} {
175            set pseudotool $tdir/tool.xml
176            break
177        }
178    }
179    if {![file exists $pseudotool]} {
180        # we didn't find a tool.xml file,
181        # use info from a runfile to build gui
182        # disable simulation, because no tool.xml
183        set pseudotool [lindex $params(-load) 0]
184        array set params [list -nosim true]
185    }
186    if {![file exists $pseudotool]} {
187        puts stderr "can't find tool \"$params(-tool)\""
188        exit 1
189    }
190    array set params [list -tool $pseudotool]
191}
192
193set xmlobj [Rappture::library $params(-tool)]
194
195set installdir [file normalize [file dirname $params(-tool)]]
196$xmlobj put tool.version.application.directory(tool) $installdir
197set tool [Rappture::Tool ::#auto $xmlobj $installdir]
198
199# ----------------------------------------------------------------------
200# CHECK JOB FAILURE REPORTING
201#
202# If this tool might fail when it launches jobs (i.e., Rappture
203# can't check some inputs, such as strings), then disable the
204# automatic ticket submission for job failures
205# ----------------------------------------------------------------------
206set val [string trim [$tool xml get tool.reportJobFailures]]
207if { "" != $val} {
208    if {[catch {Rappture::bugreport::shouldReport jobfailures $val} result]} {
209        puts stderr "WARNING for reportJobFailures: $result"
210    }
211}
212
213# ----------------------------------------------------------------------
214# LOAD RESOURCE SETTINGS
215#
216# Try to load the $SESSIONDIR/resources file, which contains
217# middleware settings, such as the application name and the
218# filexfer settings.
219# ----------------------------------------------------------------------
220Rappture::resources::load
221
222# ----------------------------------------------------------------------
223# START LOGGING
224#
225# If the $RAPPTURE_LOG directory is set to a directory used for
226# logging, then open a log file and start logging.
227# ----------------------------------------------------------------------
228Rappture::Logger::init
229
230# ----------------------------------------------------------------------
231# INITIALIZE THE DESKTOP CONNECTION
232#
233# If there's a SESSION ID, then this must be running within the
234# nanoHUB.  Try to initialize the server handling the desktop
235# connection.
236# ----------------------------------------------------------------------
237Rappture::filexfer::init
238
239# ----------------------------------------------------------------------
240# MAIN WINDOW
241# ----------------------------------------------------------------------
242Rappture::MainWin .main -borderwidth 0
243.main configure -title [string trim [$tool xml get tool.title]]
244wm withdraw .main
245wm protocol .main WM_DELETE_WINDOW {Rappture::Logger::cleanup; exit}
246
247# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
248if {[info exists env(FULLSCREEN)]} {
249    .main configure -mode web
250}
251
252#
253# The main window has a pager that acts as a notebook for the
254# various parts.  This notebook as at least two pages--an input
255# page and an output (analysis) page.  If there are <phase>'s
256# for input, then there are more pages in the notebook.
257#
258set win [.main component app]
259Rappture::Postern $win.postern
260pack $win.postern -side bottom -fill x
261
262Rappture::Pager $win.pager
263pack $win.pager -expand yes -fill both
264
265#
266# Add a place for about/questions in the breadcrumbs area of this pager.
267#
268set app [string trim [$tool xml get tool.id]]
269set url [Rappture::Tool::resources -huburl]
270if {"" != $url && "" != $app} {
271    set f [$win.pager component breadcrumbarea]
272    frame $f.hubcntls
273    pack $f.hubcntls -side right -padx 4
274    label $f.hubcntls.icon -image [Rappture::icon ask] -highlightthickness 0
275    pack $f.hubcntls.icon -side left
276    button $f.hubcntls.about -text "About this tool" -command "
277        [list Rappture::filexfer::webpage $url/tools/$app]
278        Rappture::Logger::log help about
279    "
280    pack $f.hubcntls.about -side top -anchor w
281    button $f.hubcntls.questions -text Questions? -command "
282        [list Rappture::filexfer::webpage $url/resources/$app/questions]
283        Rappture::Logger::log help questions
284    "
285    pack $f.hubcntls.questions -side top -anchor w
286}
287
288#
289# Load up the components in the various phases of input.
290#
291set phases [$tool xml children -type phase input]
292if {[llength $phases] > 0} {
293    set plist ""
294    foreach name $phases {
295        lappend plist input.$name
296    }
297    set phases $plist
298} else {
299    set phases input
300}
301
302foreach comp $phases {
303    set title [string trim [$tool xml get $comp.about.label]]
304    if {$title == ""} {
305        set title "Input #auto"
306    }
307    $win.pager insert end -name $comp -title $title
308
309    #
310    # Build the page of input controls for this phase.
311    #
312    set f [$win.pager page $comp]
313    Rappture::Page $f.cntls $tool $comp
314    pack $f.cntls -expand yes -fill both
315}
316
317# let components (loaders) in the newly created pages settle
318update
319
320# ----------------------------------------------------------------------
321# OUTPUT AREA
322# ----------------------------------------------------------------------
323
324# adjust the title of the page here.
325# to adjust the button text, look in analyzer.tcl
326set simtxt [string trim [$xmlobj get tool.action.label]]
327if {"" == $simtxt} {
328    set simtxt "Simulate"
329}
330$win.pager insert end -name analyzer -title $simtxt
331set f [$win.pager page analyzer]
332$win.pager page analyzer -command [subst {
333    if { !$params(-nosim) } {
334        $win.pager busy yes
335        update
336        $f.analyze simulate -ifneeded
337        $win.pager busy no
338    }
339}]
340
341Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about
342pack $f.analyze -expand yes -fill both
343
344$tool notify add analyzer * [list $f.analyze reset]
345
346# ----------------------------------------------------------------------
347# Finalize the arrangement
348# ----------------------------------------------------------------------
349if {[llength [$win.pager page]] > 2} {
350    # We have phases, so we shouldn't allow the "Simulate" button.
351    # If it pops up, there are two ways to push simulate and duplicate
352    # links for "About" and "Questions?".
353    $f.analyze configure -simcontrol off
354} elseif {[llength [$win.pager page]] == 2} {
355    set style [string trim [$xmlobj get tool.layout]]
356    set screenw [winfo screenwidth .]
357
358    update idletasks
359    set w0 [winfo reqwidth [$win.pager page @0]]
360    set w1 [winfo reqwidth [$win.pager page @1]]
361
362    if { $style != "wizard" } {
363        # If only two windows and they're small enough, put them up
364        # side-by-side
365        if {$w0+$w1 < $screenw } {
366            $win.pager configure -arrangement side-by-side
367            $f.analyze configure -holdwindow [$win.pager page @0]
368        }
369    }
370    set type [string trim [$tool xml get tool.control]]
371    if {$type == ""} {
372        set type [string trim [$tool xml get tool.control.type]]
373    }
374    set arrangement [$win.pager cget -arrangement]
375    if { $type == "" } {
376        if { $arrangement != "side-by-side" } {
377           set type auto
378        }
379    }
380    if { $arrangement != "side-by-side" &&
381            ($type == "manual" || $type == "manual-resim" ||
382             $type == "auto" || $style == "wizard") } {
383        # in "auto" mode, we don't need a simulate button
384        $f.analyze configure -simcontrol off
385    } else {
386        # not in "auto" mode but side-by-side, we always need the button
387        $f.analyze configure -simcontrol on
388    }
389}
390
391# load previous xml runfiles
392if {[llength $params(-load)] > 0} {
393    foreach runobj $loadobjs {
394        $f.analyze load $runobj
395    }
396    # load the inputs for the very last run
397    $tool load $runobj
398
399    # don't need simulate button if we cannot simulate
400    if {$params(-nosim)} {
401        $f.analyze configure -simcontrol off
402    }
403    $f.analyze configure -notebookpage analyze
404    $win.pager current analyzer
405} elseif {$params(-input) ne ""} {
406    $tool load $inputobj
407}
408puts "DONE main.tcl"
409# let components (loaders) settle after the newly loaded runs
410update
411
412foreach path [array names ::Rappture::parameters] {
413    set fname $::Rappture::parameters($path)
414    if {[catch {
415          set fid [open $fname r]
416          set info [read $fid]
417          close $fid}] == 0} {
418
419        set w [$tool widgetfor $path]
420        if {$w ne ""} {
421            if {[catch {$w value [string trim $info]} result]} {
422                puts stderr "WARNING: bad tool parameter value for \"$path\""
423                puts stderr "  $result"
424            }
425        } else {
426            puts stderr "WARNING: can't find control for tool parameter: $path"
427        }
428    }
429}
430
431wm deiconify .main
Note: See TracBrowser for help on using the repository browser.