Changeset 1342 for trunk/gui/scripts/notebook.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/notebook.tcl
r115 r1342 41 41 private variable _current "" ;# page currently shown 42 42 } 43 43 44 44 itk::usual Notebook { 45 45 keep -background -cursor … … 69 69 set rlist "" 70 70 foreach name $args { 71 72 73 74 75 76 77 78 79 80 81 82 83 84 71 if {[lsearch $_pages $name] >= 0} { 72 error "page \"$name\" already exists" 73 } 74 set pname "page[incr _count]" 75 itk_component add $pname { 76 frame $itk_interior.$pname 77 } 78 set _pages [linsert $_pages $pos $name] 79 set _name2page($name) $itk_component($pname) 80 81 bind $itk_component($pname) <Configure> \ 82 [itcl::code $_dispatcher event -after 100 !fixsize] 83 84 lappend rlist $itk_component($pname) 85 85 } 86 86 return $rlist … … 98 98 itcl::body Rappture::Notebook::delete {args} { 99 99 if {$args == "-all"} { 100 100 set args $_pages 101 101 } 102 102 foreach name $args { 103 104 105 106 107 108 109 103 set i [index $name] 104 set pname [lindex $_pages $i] 105 if {$pname != ""} { 106 set _pages [lreplace $_pages $i $i] 107 destroy $_name2page($pname) 108 unset _name2page($pname) 109 } 110 110 } 111 111 } … … 119 119 set i [lsearch $_pages $name] 120 120 if {$i >= 0} { 121 121 return $i 122 122 } 123 123 if {[regexp {^@([0-9]+)$} $name match i]} { 124 124 return $i 125 125 } 126 126 error "bad page name \"$name\": should be @int or one of [join [lsort $_pages] {, }]" … … 148 148 itcl::body Rappture::Notebook::current {args} { 149 149 switch -- [llength $args] { 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 150 0 { 151 return $_current 152 } 153 1 { 154 set name [lindex $args 0] 155 set index 0 156 if {$name == "next>"} { 157 if {$_current == ""} { 158 set index 0 159 } else { 160 set i [lsearch -exact $_pages $_current] 161 set index [expr {$i+1}] 162 if {$index >= [llength $_pages]} { 163 set index [expr {[llength $_pages]-1}] 164 } 165 } 166 } elseif {$name == "<back"} { 167 if {$_current == ""} { 168 set index end 169 } else { 170 set i [lsearch -exact $_pages $_current] 171 set index [expr {$i-1}] 172 if {$index < 0} { 173 set index 0 174 } 175 } 176 } else { 177 set index [lsearch -exact $_pages $name] 178 if {$index < 0} { 179 error "can't move to page \"$name\"" 180 } 181 } 182 183 set _current [lindex $_pages $index] 184 185 foreach w [pack slaves $itk_component(hull)] { 186 pack forget $w 187 } 188 pack $_name2page($_current) -expand yes -fill both 189 } 190 default { 191 error "wrong # args: should be \"current name|next>|<back\"" 192 } 193 193 } 194 194 } … … 204 204 itcl::body Rappture::Notebook::_fixSize {} { 205 205 if {$itk_option(-width) <= 0} { 206 207 208 209 210 211 206 set maxw 0 207 foreach name $_pages { 208 set w [winfo reqwidth $_name2page($name)] 209 if {$w > $maxw} { set maxw $w } 210 } 211 component hull configure -width $maxw 212 212 } else { 213 213 component hull configure -width $itk_option(-width) 214 214 } 215 215 216 216 if {$itk_option(-height) <= 0} { 217 218 219 220 221 222 217 set maxh 0 218 foreach name $_pages { 219 set h [winfo reqheight $_name2page($name)] 220 if {$h > $maxh} { set maxh $h } 221 } 222 component hull configure -height $maxh 223 223 } else { 224 224 component hull configure -height $itk_option(-height) 225 225 } 226 226 }
Note: See TracChangeset
for help on using the changeset viewer.