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

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

Many improvements, including a new energy level viewer
for Huckel-IV. Added support for a new <boolean> type.
Fixed the cloud/field stuff so that when a cloud is 1D,
it reverts to BLT vectors so it will plot correctly.
Fixed the install script to work better on Windows.

File size: 7.5 KB
RevLine 
[1]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]11#  Copyright (c) 2004-2005
12#  Purdue Research Foundation, West Lafayette, IN
[1]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        switch -- $itk_option(-anchor) {
141            n {
142                set x [expr {$sw/2}]
[13]143                set y 0
[1]144            }
145            s {
146                set x [expr {$sw/2}]
147                set y $sh
148            }
149            center {
150                set x [expr {$sw/2}]
151                set y [expr {$sh/2}]
152            }
153            w {
154                set x 0
155                set y [expr {$sh/2}]
156            }
157            e {
158                set x $sw
159                set y [expr {$sh/2}]
160            }
161            nw {
162                set x 0
[13]163                set y 0
[1]164            }
165            ne {
166                set x $sw
[13]167                set y 0
[1]168            }
169            sw {
170                set x 0
171                set y $sh
172            }
173            se {
174                set x $sw
175                set y $sh
176            }
177        }
178
179        # if the app is too big, use w/h. otherwise, 0,0 for default size
180        if {!$clip} {
181            set w 0
182            set h 0
183        }
184
185        $itk_component(area) create window $x $y \
186            -anchor $itk_option(-anchor) -window $itk_component(app) \
187            -width $w -height $h
188    }
189}
190
191# ----------------------------------------------------------------------
192# OPTION: -mode
193# ----------------------------------------------------------------------
194itcl::configbody Rappture::MainWin::mode {
195    switch -- $itk_option(-mode) {
196        desktop {
197            component hull configure -menu $itk_component(hull).menu
198            pack $itk_component(app) -expand yes -fill both
199            wm geometry $itk_component(hull) ""
200        }
201        web {
202            component hull configure -menu ""
203            pack forget $itk_component(app)
204            set wx [winfo screenwidth $itk_component(hull)]
205            set wy [winfo screenheight $itk_component(hull)]
206            wm geometry $itk_component(hull) ${wx}x${wy}+0+0
207            _redraw
208        }
209        default {
210            error "bad value \"$itk_option(-mode)\": should be desktop or web"
211        }
212    }
213}
214
215# ----------------------------------------------------------------------
216# OPTION: -bgscript
217# ----------------------------------------------------------------------
218itcl::configbody Rappture::MainWin::bgscript {
219    _redraw
220}
221
222# ----------------------------------------------------------------------
223# OPTION: -anchor
224# ----------------------------------------------------------------------
225itcl::configbody Rappture::MainWin::anchor {
226    if {[lsearch {n s e w ne nw se sw center} $itk_option(-anchor)] < 0} {
227        error "bad anchor \"$itk_option(-anchor)\""
228    }
229    _redraw
230}
Note: See TracBrowser for help on using the repository browser.