source: trunk/gui/apps/driver @ 1

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

initial import

File size: 6.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 a UI configuration from a config.xml file, and produces a
7#  user interface automatically to drive an application.  The user
8#  can set up input, click and button to launch a tool, and browse
9#  through output.
10#
11#  RUN AS FOLLOWS:
12#    driver ?-tool <toolfile>? ?-config <configfile>?
13#
14#  If the <toolfile> is not specified, this program looks for a
15#  file called "tool.xml" in the current directory.  If the <configfile>
16#  is not specified, it looks for "config.xml" in the current directory.
17#
18# ======================================================================
19#  AUTHOR:  Michael McLennan, Purdue University
20#  Copyright (c) 2004  Purdue Research Foundation, West Lafayette, IN
21# ======================================================================
22#\
23exec wish "$0" $*
24# ----------------------------------------------------------------------
25# wish executes everything from here on...
26
27package require Rappture
28
29option add *MainWin.mode web startupFile
30option add *MainWin.borderWidth 0 startupFile
31option add *MainWin.anchor center startupFile
32
33# "web site" look
34option add *MainWin.bgScript {
35    rectangle 0 0 200 <h> -outline "" -fill #5880BB
36    rectangle 200 0 300 <h> -outline "" -fill #425F8B
37    rectangle 300 0 <w> <h> -outline "" -fill #324565
38} startupFile
39
40# "clean" look
41option add *MainWin.bgScript "" startupFile
42option add *MainWin.bgColor white startupFile
43
44image create photo in2out \
45    -file [file join $Rappture::installdir scripts images in2out.gif]
46
47#
48# Process command line args to get the names of files to load...
49#
50set toolfile "tool.xml"
51set configfile "config.xml"
52
53while {[llength $argv] > 0} {
54    set first [lindex $argv 0]
55    set argv [lrange $argv 1 end]
56
57    switch -- $first {
58        -tool {
59            if {[llength $argv] > 0} {
60                set toolfile [lindex $argv 0]
61                set argv [lrange $argv 1 end]
62            } else {
63                puts stderr "$argv0: missing value for -tool"
64                exit 1
65            }
66        }
67        -config {
68            if {[llength $argv] > 0} {
69                set configfile [lindex $argv 0]
70                set argv [lrange $argv 1 end]
71            } else {
72                puts stderr "$argv0: missing value for -tool"
73                exit 1
74            }
75        }
76        default {
77            puts stderr "usage: $argv0 ?-tool file? ?-config file?"
78            exit 1
79        }
80    }
81}
82
83# open the XML file containing the material library
84set lib [Rappture::Library::open -std library.xml]
85                                                                               
86# open the XML file containing the tool parameters
87if {![file exists $toolfile]} {
88    puts stderr "tool file \"$toolfile\" doesn't exist"
89    exit 1
90}
91set tool [Rappture::Library::open $toolfile]
92                                                                               
93# open the XML file containing the configuration for this application
94if {![file exists $configfile]} {
95    puts stderr "config file \"$configfile\" doesn't exist"
96    exit 1
97}
98set config [Rappture::Library::open $configfile]
99
100# ----------------------------------------------------------------------
101# From here on, run in the directory containing the tool.xml file,
102# so driver.xml files, etc., are created there
103# ----------------------------------------------------------------------
104cd [file dirname $toolfile]
105
106# ----------------------------------------------------------------------
107# USAGE: main_device_select
108#
109# Invoked automatically when a user selects a new device from the
110# "Devices:" combobox.  Plugs the new device into the device viewer.
111# ----------------------------------------------------------------------
112proc main_device_select {} {
113    set win [.main component app]
114    set val [$win.input.devsel.dev value]
115    set val [$win.input.devsel.dev translate $val]
116    $win.input.device configure -device $val
117    $win.output.analyze configure -device $val
118}
119
120# ----------------------------------------------------------------------
121# MAIN WINDOW
122# ----------------------------------------------------------------------
123wm withdraw .
124Rappture::MainWin .main -borderwidth 0
125
126#.main configure -title [$config get title]
127
128# build everything inside this main window
129set win [.main component app]
130$win configure -background #a6a6a6
131
132frame $win.input -borderwidth 12 -relief flat
133pack $win.input -side left -expand yes -fill both -padx {0 5}
134
135frame $win.output -borderwidth 12 -relief flat
136pack $win.output -side left -expand yes -fill both -padx {5 0}
137
138# make an arrow that goes from input to output side
139label $win.arrow -borderwidth 0 -image in2out
140place $win.arrow -y 2 -anchor n
141bind $win.input <Configure> [list align_arrow $win]
142proc align_arrow {win} {
143    place $win.arrow -x [expr {[winfo width $win.input]+5}]
144}
145
146# ----------------------------------------------------------------------
147# INPUT AREA
148# ----------------------------------------------------------------------
149set w $win.input
150set ndevs [$config get -count controls.device]
151if {$ndevs > 0} {
152    for {set i 0} {$i < $ndevs} {incr i} {
153        set obj [$config get -object controls.device$i]
154        set name [$obj get label]
155        set devs($name) $obj
156    }
157    set devlist [lsort [array names devs]]
158
159    if {$ndevs > 1} {
160        frame $w.devsel
161        pack $w.devsel -side top -fill x
162        label $w.devsel.l -text "Device:"
163        pack $w.devsel.l -side left
164        Rappture::Combobox $w.devsel.dev -width 30 -editable no
165        pack $w.devsel.dev -side left
166        bind $w.devsel.dev <<Value>> main_device_select
167
168        foreach name $devlist {
169            $w.devsel.dev choices insert end $devs($name) $name
170        }
171        $w.devsel.dev value [lindex $devlist 0]
172    }
173
174    set first [lindex $devlist 0]
175    Rappture::DeviceViewer1D $w.device -device $devs($first) \
176        -tool $tool -library $lib
177    pack $w.device -expand yes -fill both
178
179    bind $w.device <<Edit>> [list $win.output.analyze reset]
180}
181
182# ----------------------------------------------------------------------
183# OUTPUT AREA
184# ----------------------------------------------------------------------
185set w $win.output
186Rappture::Analyzer $w.analyze -holdwindow $win.input \
187    -tool $tool -analysis [$config get -object analysis] \
188    -device $devs($first)
189pack $w.analyze -expand yes -fill both
190
191# ----------------------------------------------------------------------
192# HOOK UP ANY CONTROLS CALLED OUT IN CONFIG.XML
193# ----------------------------------------------------------------------
194set ncntls [$config get -count controls.access]
195for {set i 0} {$i < $ncntls} {incr i} {
196    set name [$config get access$i]
197    switch -glob -- $name {
198        parameters.ambient* - device* {
199            $win.input.device controls add $name
200        }
201    }
202}
Note: See TracBrowser for help on using the repository browser.