source: trunk/gui/apps/driver @ 365

Last change on this file since 365 was 365, checked in by dkearney, 19 years ago

fixes for tcl bindings.

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