source: trunk/gui/scripts/mainwin.tcl @ 11

Last change on this file since 11 was 11, checked in by mmc, 16 years ago

Major reorganization of the entire package. The config.xml file
is now irrelevant. All the action is in the tool.xml file. The
main program now organizes all input into 1) side-by-side pages,
2) input/result (wizard-style) pages, or 3) a series of wizard-
style pages. The <input> can have <phase> parts representing
the various pages.

Added a new ContourResult? widget based on Swaroop's vtk plotting
code.

Also, added easymesh and showmesh to the "tools" directory.
We need these for Eric Polizzi's code.

File size: 8.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: mainwin - main application window for Rappture
3#
4#  This widget acts as the main window for a Rappture application.
5#  It can be configured to run in two modes:  1) normal desktop
6#  application, and 2) web-based application.  In web-based mode,
7#  the application window runs inside a VNC window, and it takes
8#  the full screen and blends in with the web page.
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2005
12#  Purdue Research Foundation, West Lafayette, IN
13# ======================================================================
14package require Itk
15
16option add *MainWin.mode desktop widgetDefault
17option add *MainWin.borderWidth 0 widgetDefault
18option add *MainWin.relief raised widgetDefault
19option add *MainWin.anchor center widgetDefault
20option add *MainWin.titleFont \
21    -*-helvetica-bold-o-normal-*-*-140-* widgetDefault
22
23itcl::class Rappture::MainWin {
24    inherit itk::Toplevel
25
26    itk_option define -mode mode Mode ""
27    itk_option define -anchor anchor Anchor "center"
28    itk_option define -bgscript bgScript BgScript ""
29
30    constructor {args} { # defined below }
31
32    public method draw {option args}
33
34    protected method _redraw {}
35
36    private variable _contents ""  ;# frame containing app
37    private variable _bgscript ""  ;# script of background drawing cmds
38    private variable _bgparser ""  ;# parser for bgscript
39}
40                                                                               
41itk::usual MainWin {
42    keep -background -cursor foreground -font
43}
44
45# ----------------------------------------------------------------------
46# CONSTRUCTOR
47# ----------------------------------------------------------------------
48itcl::body Rappture::MainWin::constructor {args} {
49    itk_component add area {
50        canvas $itk_interior.area
51    } {
52        usual
53        rename -background -bgcolor bgColor Background
54    }
55    pack $itk_component(area) -expand yes -fill both
56    bind $itk_component(area) <Configure> [itcl::code $this _redraw]
57
58    itk_component add app {
59        frame $itk_component(area).app
60    } {
61        usual
62        keep -borderwidth -relief
63    }
64    bind $itk_component(app) <Configure> "
65        after cancel [itcl::code $this _redraw]
66        after idle [itcl::code $this _redraw]
67    "
68
69    itk_component add menu {
70        menu $itk_interior.menu
71    }
72    itk_component add filemenu {
73        menu $itk_component(menu).file
74    }
75    $itk_component(menu) add cascade -label "File" -underline 0 \
76        -menu $itk_component(filemenu)
77    $itk_component(filemenu) add command -label "Exit" -underline 1 \
78        -command exit
79
80    #
81    # Create a parser for the -bgscript option that can
82    # execute drawing commands on the canvas.  This allows
83    # us to draw a background that blends in with web pages.
84    #
85    set _bgparser [interp create -safe]
86    $_bgparser alias rectangle [itcl::code $this draw rectangle]
87    $_bgparser alias oval [itcl::code $this draw oval]
88    $_bgparser alias line [itcl::code $this draw line]
89    $_bgparser alias polygon [itcl::code $this draw polygon]
90    $_bgparser alias text [itcl::code $this draw text]
91    $_bgparser alias image [itcl::code $this draw image]
92
93    eval itk_initialize $args
94
95    bind RapptureMainWin <Destroy> { exit }
96    set btags [bindtags $itk_component(hull)]
97    bindtags $itk_component(hull) [lappend btags RapptureMainWin]
98}
99
100# ----------------------------------------------------------------------
101# USAGE: draw <option> ?<arg> <arg>...?
102#
103# Used by the -bgscript to draw items in the background area behind
104# the app when "-mode web" is active.  This allows an application
105# to create a background that blends seamlessly with the underlying
106# web page.
107# ----------------------------------------------------------------------
108itcl::body Rappture::MainWin::draw {option args} {
109    set w $itk_component(hull)
110    regsub -all {<w>} $args [winfo screenwidth $w] args
111    regsub -all {<h>} $args [winfo screenheight $w] args
112    eval $itk_component(area) create $option $args
113}
114
115# ----------------------------------------------------------------------
116# USAGE: _redraw
117#
118# Used internally to redraw the widget whenever it changes size.
119# This matters only when "-mode web" is active, when the background
120# area is actually visible.
121# ----------------------------------------------------------------------
122itcl::body Rappture::MainWin::_redraw {} {
123    $itk_component(area) delete all
124    if {$itk_option(-mode) == "web"} {
125        if {[catch {$_bgparser eval $itk_option(-bgscript)} result]} {
126            bgerror "$result\n    (while redrawing application background)"
127        }
128
129        set sw [winfo width $itk_component(area)]
130        set sh [winfo height $itk_component(area)]
131
132        set clip 0
133        set w [winfo reqwidth $itk_component(app)]
134        set h [winfo reqheight $itk_component(app)]
135        if {$w > $sw} {
136            set $w $sw
137            set clip 1
138        }
139
140        set titleh 0
141        set fnt [option get $itk_component(hull) titleFont Font]
142        if {$itk_option(-title) != "" && $fnt != ""} {
143            set titleh [expr {[font metrics $fnt -linespace]+2}]
144        }
145        if {$h+$titleh > $sh} {
146            set $h [expr {$sh-$titleh}]
147            set clip 1
148        }
149
150        switch -- $itk_option(-anchor) {
151            n {
152                set x [expr {$sw/2}]
153                set y $titleh
154                set tx [expr {$x-$w/2}]
155                set ty $titleh
156            }
157            s {
158                set x [expr {$sw/2}]
159                set y $sh
160                set tx [expr {$x-$w/2}]
161                set ty [expr {$sh-$h}]
162            }
163            center {
164                set x [expr {$sw/2}]
165                set y [expr {$sh/2}]
166                set tx [expr {$x-$w/2}]
167                set ty [expr {$y-$h/2}]
168            }
169            w {
170                set x 0
171                set y [expr {$sh/2}]
172                set tx 0
173                set ty [expr {$y-$h/2}]
174            }
175            e {
176                set x $sw
177                set y [expr {$sh/2}]
178                set tx [expr {$sw-$w}]
179                set ty [expr {$y-$h/2}]
180            }
181            nw {
182                set x 0
183                set y $titleh
184                set tx 0
185                set ty $titleh
186            }
187            ne {
188                set x $sw
189                set y $titleh
190                set tx [expr {$sw-$w}]
191                set ty $titleh
192            }
193            sw {
194                set x 0
195                set y $sh
196                set tx 0
197                set ty [expr {$sh-$h}]
198            }
199            se {
200                set x $sw
201                set y $sh
202                set tx [expr {$sw-$w}]
203                set ty [expr {$sh-$h}]
204            }
205        }
206
207        # if the app is too big, use w/h. otherwise, 0,0 for default size
208        if {!$clip} {
209            set w 0
210            set h 0
211        }
212
213        $itk_component(area) create window $x $y \
214            -anchor $itk_option(-anchor) -window $itk_component(app) \
215            -width $w -height $h
216
217        if {$itk_option(-title) != "" && $fnt != ""} {
218            $itk_component(area) create text $tx [expr {$ty-2}] \
219                -anchor sw -text $itk_option(-title) -font $fnt
220        }
221    }
222}
223
224# ----------------------------------------------------------------------
225# OPTION: -mode
226# ----------------------------------------------------------------------
227itcl::configbody Rappture::MainWin::mode {
228    switch -- $itk_option(-mode) {
229        desktop {
230            component hull configure -menu $itk_component(hull).menu
231            pack $itk_component(app) -expand yes -fill both
232            wm geometry $itk_component(hull) ""
233        }
234        web {
235            component hull configure -menu ""
236            pack forget $itk_component(app)
237            set wx [winfo screenwidth $itk_component(hull)]
238            set wy [winfo screenheight $itk_component(hull)]
239            wm geometry $itk_component(hull) ${wx}x${wy}+0+0
240            _redraw
241        }
242        default {
243            error "bad value \"$itk_option(-mode)\": should be desktop or web"
244        }
245    }
246}
247
248# ----------------------------------------------------------------------
249# OPTION: -bgscript
250# ----------------------------------------------------------------------
251itcl::configbody Rappture::MainWin::bgscript {
252    _redraw
253}
254
255# ----------------------------------------------------------------------
256# OPTION: -anchor
257# ----------------------------------------------------------------------
258itcl::configbody Rappture::MainWin::anchor {
259    if {[lsearch {n s e w ne nw se sw center} $itk_option(-anchor)] < 0} {
260        error "bad anchor \"$itk_option(-anchor)\""
261    }
262    _redraw
263}
Note: See TracBrowser for help on using the repository browser.