source: trunk/gui/apps/driver @ 154

Last change on this file since 154 was 115, checked in by mmc, 17 years ago

Updated all copyright notices.

File size: 5.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#    driver ?-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-2005  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# ======================================================================
23#\
24exec wish "$0" $*
25# ----------------------------------------------------------------------
26# wish executes everything from here on...
27
28package require Rappture
29
30option add *MainWin.mode desktop startupFile
31option add *MainWin.borderWidth 0 startupFile
32option add *MainWin.anchor fill startupFile
33
34# "web site" look
35option add *MainWin.bgScript {
36    rectangle 0 0 200 <h> -outline "" -fill #5880BB
37    rectangle 200 0 300 <h> -outline "" -fill #425F8B
38    rectangle 300 0 <w> <h> -outline "" -fill #324565
39} startupFile
40
41# "clean" look
42option add *MainWin.bgScript "" startupFile
43option add *MainWin.bgColor white startupFile
44option add *Tooltip.background white
45option add *Editor.background white
46option add *Gauge.textBackground white
47option add *TemperatureGauge.textBackground white
48option add *Switch.textBackground white
49option add *Progress.barColor #ffffcc
50
51switch $tcl_platform(platform) {
52    unix - windows {
53        event add <<PopupMenu>> <ButtonPress-3>
54    }
55    macintosh {
56        event add <<PopupMenu>> <Control-ButtonPress-1>
57    }
58}
59
60# fix the "grab" command to support a stack of grab windows
61Rappture::grab::init
62
63#
64# Process command line args to get the names of files to load...
65#
66Rappture::getopts argv params {
67    value -tool tool.xml
68}
69
70# open the XML file containing the tool parameters
71if {![file exists $params(-tool)]} {
72    puts stderr "can't find tool \"$params(-tool)\""
73    exit 1
74}
75set xmlobj [Rappture::library $params(-tool)]
76
77set installdir [file dirname $params(-tool)]
78if {"." == $installdir} {
79    set installdir [pwd]
80}
81
82set tool [Rappture::Tool ::#auto $xmlobj $installdir]
83
84# ----------------------------------------------------------------------
85# INITIALIZE THE DESKTOP CONNECTION
86#
87# If there's a SESSION ID, then this must be running within the
88# nanoHUB.  Try to initialize the server handling the desktop
89# connection.
90# ----------------------------------------------------------------------
91Rappture::filexfer::init
92
93# ----------------------------------------------------------------------
94# MAIN WINDOW
95# ----------------------------------------------------------------------
96wm withdraw .
97Rappture::MainWin .main -borderwidth 0
98.main configure -title [$tool xml get tool.title]
99wm withdraw .main
100
101# if the FULLSCREEN variable is set, then nanoHUB wants us to go full screen
102if {[info exists env(FULLSCREEN)]} {
103    .main configure -mode web
104}
105
106#
107# The main window has a pager that acts as a notebook for the
108# various parts.  This notebook as at least two pages--an input
109# page and an output (analysis) page.  If there are <phase>'s
110# for input, then there are more pages in the notebook.
111#
112set win [.main component app]
113Rappture::Postern $win.postern
114pack $win.postern -side bottom -fill x
115
116Rappture::Pager $win.pager
117pack $win.pager -expand yes -fill both
118
119set phases [$tool xml children -type phase input]
120if {[llength $phases] > 0} {
121    set plist ""
122    foreach name $phases {
123        lappend plist input.$name
124    }
125    set phases $plist
126} else {
127    set phases input
128}
129
130foreach comp $phases {
131    set title [$tool xml get $comp.about.label]
132    if {$title == ""} {
133        set title "Input #auto"
134    }
135    $win.pager insert end -name $comp -title $title
136
137    #
138    # Build the page of input controls for this phase.
139    #
140    set f [$win.pager page $comp]
141    Rappture::Page $f.cntls $tool $comp
142    pack $f.cntls -expand yes -fill both
143}
144
145# ----------------------------------------------------------------------
146# OUTPUT AREA
147# ----------------------------------------------------------------------
148$win.pager insert end -name analyzer -title "Simulate"
149set f [$win.pager page analyzer]
150$win.pager page analyzer -command [list $f.analyze simulate -ifneeded]
151
152Rappture::Analyzer $f.analyze $tool -simcontrol auto
153pack $f.analyze -expand yes -fill both
154
155$tool notify add analyzer * [list $f.analyze reset]
156
157# ----------------------------------------------------------------------
158# Finalize the arrangement
159# ----------------------------------------------------------------------
160if {[llength [$win.pager page]] == 2} {
161    set style [$xmlobj get tool.layout]
162    set screenw [winfo screenwidth .]
163
164    update idletasks
165    set w0 [winfo reqwidth [$win.pager page @0]]
166    set w1 [winfo reqwidth [$win.pager page @1]]
167
168    # if only two windows and they're small enough, put them up side-by-side
169    if {$w0+$w1 < $screenw && $style != "wizard"} {
170        $win.pager configure -arrangement side-by-side
171        $f.analyze configure -holdwindow [$win.pager page @0]
172
173        set type [$tool xml get tool.control]
174        if {$type == ""} {
175            set type [$tool xml get tool.control.type]
176        }
177
178        if {$type == "auto"} {
179            # in "auto" mode, we don't need a simulate button
180            $f.analyze configure -simcontrol off
181        } else {
182            # not in "auto" mode but side-by-side, we always need the button
183            $f.analyze configure -simcontrol on
184        }
185    }
186}
187wm deiconify .main
Note: See TracBrowser for help on using the repository browser.