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