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