source: trunk/gui/scripts/notebook.tcl @ 23

Last change on this file since 23 was 11, checked in by mmc, 19 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.1 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: notebook - series of pages, but only one packed at a time
3#
4#  This widget acts as the core of a tabbed notebook, without the tabs.
5#  It allows you to create a series of pages, and display one page at
6#  time.  The overall widget is just big enough to accommodate all of
7#  the pages within it.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005
11#  Purdue Research Foundation, West Lafayette, IN
12# ======================================================================
13package require Itk
14
15option add *Notebook.width 0 widgetDefault
16option add *Notebook.height 0 widgetDefault
17
18itcl::class Rappture::Notebook {
19    inherit itk::Widget
20
21    itk_option define -width width Width 0
22    itk_option define -height height Height 0
23
24    constructor {args} { # defined below }
25    destructor { # defined below }
26
27    public method insert {pos args}
28    public method delete {args}
29    public method index {name}
30    public method page {name}
31    public method current {args}
32
33    protected method _fixSize {}
34
35    private variable _count 0       ;# counter for unique names
36    private variable _dispatcher "" ;# dispatcher for !events
37    private variable _pages ""      ;# list of page frames
38    private variable _name2page     ;# maps name => frame for page
39    private variable _current ""    ;# page currently shown
40}
41                                                                               
42itk::usual Notebook {
43    keep -background -cursor
44}
45
46# ----------------------------------------------------------------------
47# CONSTRUCTOR
48# ----------------------------------------------------------------------
49itcl::body Rappture::Notebook::constructor {args} {
50    pack propagate $itk_component(hull) no
51
52    Rappture::dispatcher _dispatcher
53    $_dispatcher register !fixsize
54    $_dispatcher dispatch $this !fixsize "[itcl::code $this _fixSize]; list"
55
56    eval itk_initialize $args
57}
58
59# ----------------------------------------------------------------------
60# USAGE: insert <pos> ?<name> <name>...?
61#
62# Used to insert one or more pages in the notebook.  Each page is
63# identified by its <name>.  Returns the widget name for each
64# page created.
65# ----------------------------------------------------------------------
66itcl::body Rappture::Notebook::insert {pos args} {
67    set rlist ""
68    foreach name $args {
69        if {[lsearch $_pages $name] >= 0} {
70            error "page \"$name\" already exists"
71        }
72        set pname "page[incr _count]"
73        itk_component add $pname {
74            frame $itk_interior.$pname
75        }
76        set _pages [linsert $_pages $pos $name]
77        set _name2page($name) $itk_component($pname)
78
79        bind $itk_component($pname) <Configure> \
80            [itcl::code $_dispatcher event -after 100 !fixsize]
81
82        lappend rlist $itk_component($pname)
83    }
84    return $rlist
85}
86
87# ----------------------------------------------------------------------
88# USAGE: delete -all
89# USAGE: delete ?<name> <name>...?
90#
91# Used to delete one or more pages from the notebook.  With the -all
92# flag, it deletes all pages.  Otherwise, it deletes each page
93# by name.  You can also delete a page by using an index of the
94# form "@n".
95# ----------------------------------------------------------------------
96itcl::body Rappture::Notebook::delete {args} {
97    if {$args == "-all"} {
98        set args $_pages
99    }
100    foreach name $args {
101        set i [index $name]
102        set pname [lindex $_pages $i]
103        if {$pname != ""} {
104            set _pages [lreplace $_pages $i $i]
105            destroy $_name2page($pname)
106            unset _name2page($pname)
107        }
108    }
109}
110
111# ----------------------------------------------------------------------
112# USAGE: index <name>|@n
113#
114# Used to convert a page <name> to its corresponding integer index.
115# ----------------------------------------------------------------------
116itcl::body Rappture::Notebook::index {name} {
117    set i [lsearch $_pages $name]
118    if {$i >= 0} {
119        return $i
120    }
121    if {[regexp {^@([0-9]+)$} $name match i]} {
122        return $i
123    }
124    error "bad page name \"$name\": should be @int or one of [join [lsort $_pages] {, }]"
125}
126
127# ----------------------------------------------------------------------
128# USAGE: page <name>|@n
129#
130# Used to convert a page <name> to its corresponding frame.
131# ----------------------------------------------------------------------
132itcl::body Rappture::Notebook::page {name} {
133    set i [index $name]
134    set name [lindex $_pages $i]
135    return $_name2page($name)
136}
137
138# ----------------------------------------------------------------------
139# USAGE: current ?<name>|next>|<back?
140#
141# Used to query/set the current page in the notebook.  With no args,
142# it returns the name of the current page.  Otherwise, it sets the
143# current page.  The special token "next>" is used to set the notebook
144# to the next logical page, and "<back" sets to the previous.
145# ----------------------------------------------------------------------
146itcl::body Rappture::Notebook::current {args} {
147    switch -- [llength $args] {
148        0 {
149            return $_current
150        }
151        1 {
152            set name [lindex $args 0]
153            set index 0
154            if {$name == "next>"} {
155                if {$_current == ""} {
156                    set index 0
157                } else {
158                    set i [lsearch -exact $_pages $_current]
159                    set index [expr {$i+1}]
160                    if {$index >= [llength $_pages]} {
161                        set index [expr {[llength $_pages]-1}]
162                    }
163                }
164            } elseif {$name == "<back"} {
165                if {$_current == ""} {
166                    set index end
167                } else {
168                    set i [lsearch -exact $_pages $_current]
169                    set index [expr {$i-1}]
170                    if {$index < 0} {
171                        set index 0
172                    }
173                }
174            } else {
175                set index [lsearch -exact $_pages $name]
176                if {$index < 0} {
177                    error "can't move to page \"$name\""
178                }
179            }
180
181            set _current [lindex $_pages $index]
182
183            foreach w [pack slaves $itk_component(hull)] {
184                pack forget $w
185            }
186            pack $_name2page($_current) -expand yes -fill both
187        }
188        default {
189            error "wrong # args: should be \"current name|next>|<back\""
190        }
191    }
192}
193
194# ----------------------------------------------------------------------
195# USAGE: _fixSize
196#
197# Invoked automatically whenever a page changes size or the -width
198# or -height options change.  When the -width/-height are zero, this
199# method computes the minimum size needed to accommodate all pages.
200# Otherwise, it passes the size request onto the hull.
201# ----------------------------------------------------------------------
202itcl::body Rappture::Notebook::_fixSize {} {
203    if {$itk_option(-width) <= 0} {
204        set maxw 0
205        foreach name $_pages {
206            set w [winfo reqwidth $_name2page($name)]
207            if {$w > $maxw} { set maxw $w }
208        }
209        component hull configure -width $maxw
210    } else {
211        component hull configure -width $itk_option(-width)
212    }
213
214    if {$itk_option(-height) <= 0} {
215        set maxh 0
216        foreach name $_pages {
217            set h [winfo reqheight $_name2page($name)]
218            if {$h > $maxh} { set maxh $h }
219        }
220        component hull configure -height $maxh
221    } else {
222        component hull configure -height $itk_option(-height)
223    }
224}
225
226# ----------------------------------------------------------------------
227# OPTION: -width
228# ----------------------------------------------------------------------
229itcl::configbody Rappture::Notebook::width {
230    $_dispatcher event -idle !fixsize
231}
232
233# ----------------------------------------------------------------------
234# OPTION: -height
235# ----------------------------------------------------------------------
236itcl::configbody Rappture::Notebook::height {
237    $_dispatcher event -idle !fixsize
238}
Note: See TracBrowser for help on using the repository browser.