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

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

merge (by hand) with Rappture1.2 branch

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