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