source: trunk/gui/apps/driver @ 12

Last change on this file since 12 was 12, checked in by mmc, 19 years ago

Fixed a new nits to so that the pntoy works
better. The <tool><control>auto</control></tool>
mode is now truly automatic, and the Simulate
button no longer appears in that mode.

File size: 4.6 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  Purdue Research Foundation, West Lafayette, IN
19# ======================================================================
20#\
21exec wish "$0" $*
22# ----------------------------------------------------------------------
23# wish executes everything from here on...
24
25package require Rappture
26
27option add *MainWin.mode desktop startupFile
28option add *MainWin.borderWidth 0 startupFile
29option add *MainWin.anchor center startupFile
30
31# "web site" look
32option add *MainWin.bgScript {
33    rectangle 0 0 200 <h> -outline "" -fill #5880BB
34    rectangle 200 0 300 <h> -outline "" -fill #425F8B
35    rectangle 300 0 <w> <h> -outline "" -fill #324565
36} startupFile
37
38# "clean" look
39option add *MainWin.bgScript "" startupFile
40option add *MainWin.bgColor white startupFile
41option add *Tooltip.background white
42option add *Editor.background white
43option add *Gauge.textBackground white
44option add *TemperatureGauge.textBackground white
45
46#
47# Process command line args to get the names of files to load...
48#
49Rappture::getopts argv params {
50    value -tool tool.xml
51}
52
53# open the XML file containing the tool parameters
54if {![file exists $params(-tool)]} {
55    puts stderr "can't find tool \"$params(-tool)\""
56    exit 1
57}
58set xmlobj [Rappture::library $params(-tool)]
59
60set installdir [file dirname $params(-tool)]
61if {"." == $installdir} {
62    set installdir [pwd]
63}
64
65set tool [Rappture::Tool ::#auto $xmlobj $installdir]
66
67# ----------------------------------------------------------------------
68# MAIN WINDOW
69# ----------------------------------------------------------------------
70wm withdraw .
71Rappture::MainWin .main -borderwidth 0
72.main configure -title [$tool xml get tool.title]
73wm withdraw .main
74
75#
76# The main window has a pager that acts as a notebook for the
77# various parts.  This notebook as at least two pages--an input
78# page and an output (analysis) page.  If there are <phase>'s
79# for input, then there are more pages in the notebook.
80#
81set win [.main component app]
82Rappture::Pager $win.pager
83pack $win.pager -expand yes -fill both
84
85set phases [$tool xml children -type phase input]
86if {[llength $phases] > 0} {
87    set plist ""
88    foreach name $phases {
89        lappend plist input.$name
90    }
91    set phases $plist
92} else {
93    set phases input
94}
95
96foreach comp $phases {
97    set title [$tool xml get $comp.about.label]
98    if {$title == ""} {
99        set title "Input #auto"
100    }
101    $win.pager insert end -name $comp -title $title
102
103    #
104    # Build the page of input controls for this phase.
105    #
106    set f [$win.pager page $comp]
107    Rappture::Page $f.cntls $tool $comp
108    pack $f.cntls -expand yes -fill both
109}
110
111# ----------------------------------------------------------------------
112# OUTPUT AREA
113# ----------------------------------------------------------------------
114$win.pager insert end -name analyzer -title "Results"
115set f [$win.pager page analyzer]
116$win.pager page analyzer -command [list $f.analyze simulate -ifneeded]
117
118Rappture::Analyzer $f.analyze $tool -simcontrol auto
119pack $f.analyze -expand yes -fill both
120
121$tool configure -analyzer $f.analyze
122
123# ----------------------------------------------------------------------
124# Finalize the arrangement
125# ----------------------------------------------------------------------
126if {[llength [$win.pager page]] == 2} {
127    set style [$xmlobj get tool.layout]
128    set screenw [winfo screenwidth .]
129
130    update idletasks
131    set w0 [winfo reqwidth [$win.pager page @0]]
132    set w1 [winfo reqwidth [$win.pager page @1]]
133
134    # if only two windows and they're small enough, put them up side-by-side
135    if {$w0+$w1 < $screenw && $style != "wizard"} {
136        $win.pager configure -arrangement side-by-side
137        $f.analyze configure -holdwindow [$win.pager page @0]
138
139        if {[$tool xml get tool.control] == "auto"} {
140            # in "auto" mode, we don't need a simulate button
141            $f.analyze configure -simcontrol off
142        } else {
143            # not in "auto" mode but side-by-side, we always need the button
144            $f.analyze configure -simcontrol on
145        }
146    }
147}
148wm deiconify .main
Note: See TracBrowser for help on using the repository browser.