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

Last change on this file since 3656 was 3656, checked in by gah, 11 years ago

fix assorted automatic tickets: bad data in curve, more trim space, move image creation before errors in constructor

File size: 12.4 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 -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 \
127            [string trim [$runobj get tool.version.application.directory(tool)]]
128        if {[file isdirectory $tdir] && \
129            [file exists $tdir/tool.xml]} {
130            set pseudotool $tdir/tool.xml
131            break
132        }
133    }
134    if {![file exists $pseudotool]} {
135        # we didn't find a tool.xml file,
136        # use info from a runfile to build gui
137        # disable simulation, because no tool.xml
138        set pseudotool [lindex $params(-load) 0]
139        array set params [list -nosim true]
140    }
141    if {![file exists $pseudotool]} {
142        puts stderr "can't find tool \"$params(-tool)\""
143        exit 1
144    }
145    array set params [list -tool $pseudotool]
146}
147
148set xmlobj [Rappture::library $params(-tool)]
149
150set installdir [file normalize [file dirname $params(-tool)]]
151$xmlobj put tool.version.application.directory(tool) $installdir
152
153set tool [Rappture::Tool ::#auto $xmlobj $installdir]
154
155# ----------------------------------------------------------------------
156# CHECK JOB FAILURE REPORTING
157#
158# If this tool might fail when it launches jobs (i.e., Rappture
159# can't check some inputs, such as strings), then disable the
160# automatic ticket submission for job failures
161# ----------------------------------------------------------------------
162set val [string trim [$tool xml get tool.reportJobFailures]]
163if { "" != $val} {
164    if {[catch {Rappture::bugreport::shouldReport jobfailures $val} result]} {
165        puts stderr "WARNING for reportJobFailures: $result"
166    }
167}
168
169# ----------------------------------------------------------------------
170# LOAD RESOURCE SETTINGS
171#
172# Try to load the $SESSIONDIR/resources file, which contains
173# middleware settings, such as the application name and the
174# filexfer settings.
175# ----------------------------------------------------------------------
176Rappture::resources::load
177
178# ----------------------------------------------------------------------
179# START LOGGING
180#
181# If the $RAPPTURE_LOG directory is set to a directory used for
182# logging, then open a log file and start logging.
183# ----------------------------------------------------------------------
184Rappture::Logger::init
185
186# ----------------------------------------------------------------------
187# INITIALIZE THE DESKTOP CONNECTION
188#
189# If there's a SESSION ID, then this must be running within the
190# nanoHUB.  Try to initialize the server handling the desktop
191# connection.
192# ----------------------------------------------------------------------
193Rappture::filexfer::init
194
195# ----------------------------------------------------------------------
196# MAIN WINDOW
197# ----------------------------------------------------------------------
198Rappture::MainWin .main -borderwidth 0
199.main configure -title [string trim [$tool xml get tool.title]]
200wm withdraw .main
201wm protocol .main WM_DELETE_WINDOW {Rappture::Logger::cleanup; exit}
202
203# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
204if {[info exists env(FULLSCREEN)]} {
205    .main configure -mode web
206}
207
208#
209# The main window has a pager that acts as a notebook for the
210# various parts.  This notebook as at least two pages--an input
211# page and an output (analysis) page.  If there are <phase>'s
212# for input, then there are more pages in the notebook.
213#
214set win [.main component app]
215Rappture::Postern $win.postern
216pack $win.postern -side bottom -fill x
217
218Rappture::Pager $win.pager
219pack $win.pager -expand yes -fill both
220
221#
222# Add a place for about/questions in the breadcrumbs area of this pager.
223#
224set app [string trim [$tool xml get tool.id]]
225set url [Rappture::Tool::resources -huburl]
226if {"" != $url && "" != $app} {
227    set f [$win.pager component breadcrumbarea]
228    frame $f.hubcntls
229    pack $f.hubcntls -side right -padx 4
230    label $f.hubcntls.icon -image [Rappture::icon ask] -highlightthickness 0
231    pack $f.hubcntls.icon -side left
232    button $f.hubcntls.about -text "About this tool" -command "
233        [list Rappture::filexfer::webpage $url/tools/$app]
234        Rappture::Logger::log help about
235    "
236    pack $f.hubcntls.about -side top -anchor w
237    button $f.hubcntls.questions -text Questions? -command "
238        [list Rappture::filexfer::webpage $url/resources/$app/questions]
239        Rappture::Logger::log help questions
240    "
241    pack $f.hubcntls.questions -side top -anchor w
242}
243
244#
245# Load up the components in the various phases of input.
246#
247set phases [$tool xml children -type phase input]
248if {[llength $phases] > 0} {
249    set plist ""
250    foreach name $phases {
251        lappend plist input.$name
252    }
253    set phases $plist
254} else {
255    set phases input
256}
257
258foreach comp $phases {
259    set title [string trim [$tool xml get $comp.about.label]]
260    if {$title == ""} {
261        set title "Input #auto"
262    }
263    $win.pager insert end -name $comp -title $title
264
265    #
266    # Build the page of input controls for this phase.
267    #
268    set f [$win.pager page $comp]
269    Rappture::Page $f.cntls $tool $comp
270    pack $f.cntls -expand yes -fill both
271}
272
273# let components (loaders) in the newly created pages settle
274update
275
276# ----------------------------------------------------------------------
277# OUTPUT AREA
278# ----------------------------------------------------------------------
279
280# adjust the title of the page here.
281# to adjust the button text, look in analyzer.tcl
282set simtxt [string trim [$xmlobj get tool.action.label]]
283if {"" == $simtxt} {
284    set simtxt "Simulate"
285}
286$win.pager insert end -name analyzer -title $simtxt
287set f [$win.pager page analyzer]
288$win.pager page analyzer -command [subst {
289    if { !$params(-nosim) } {
290        $win.pager busy yes
291        update
292        $f.analyze simulate -ifneeded
293        $win.pager busy no
294    }
295}]
296
297Rappture::Analyzer $f.analyze $tool -simcontrol auto -notebookpage about
298pack $f.analyze -expand yes -fill both
299
300$tool notify add analyzer * [list $f.analyze reset]
301
302# ----------------------------------------------------------------------
303# Finalize the arrangement
304# ----------------------------------------------------------------------
305if {[llength [$win.pager page]] > 2} {
306    # We have phases, so we shouldn't allow the "Simulate" button.
307    # If it pops up, there are two ways to push simulate and duplicate
308    # links for "About" and "Questions?".
309    $f.analyze configure -simcontrol off
310} elseif {[llength [$win.pager page]] == 2} {
311    set style [string trim [$xmlobj get tool.layout]]
312    set screenw [winfo screenwidth .]
313
314    update idletasks
315    set w0 [winfo reqwidth [$win.pager page @0]]
316    set w1 [winfo reqwidth [$win.pager page @1]]
317
318    if { $style != "wizard" } {
319        # If only two windows and they're small enough, put them up
320        # side-by-side
321        if {$w0+$w1 < $screenw } {
322            $win.pager configure -arrangement side-by-side
323            $f.analyze configure -holdwindow [$win.pager page @0]
324        }
325    }
326    set type [string trim [$tool xml get tool.control]]
327    if {$type == ""} {
328        set type [string trim [$tool xml get tool.control.type]]
329    }
330    set arrangement [$win.pager cget -arrangement]
331    if { $type == "" } {
332        if { $arrangement != "side-by-side" } {
333           set type auto
334        }
335    }
336    if { $arrangement != "side-by-side" &&
337            ($type == "manual" || $type == "manual-resim" ||
338             $type == "auto" || $style == "wizard") } {
339        # in "auto" mode, we don't need a simulate button
340        $f.analyze configure -simcontrol off
341    } else {
342        # not in "auto" mode but side-by-side, we always need the button
343        $f.analyze configure -simcontrol on
344    }
345}
346
347# load previous xml runfiles
348if {0 != [llength $params(-load)]} {
349    foreach runobj $loadobjs {
350        # this doesn't seem to work with loaders
351        # loaders seem to get their value after this point
352        # may need to tell loader elements to update its value
353        $tool load $runobj
354        $f.analyze load $runobj
355    }
356    # don't need simulate button if we cannot simulate
357    if {$params(-nosim)} {
358        $f.analyze configure -simcontrol off
359    }
360    $f.analyze configure -notebookpage analyze
361    $win.pager current analyzer
362}
363
364wm deiconify .main
Note: See TracBrowser for help on using the repository browser.