Changeset 1929 for trunk/gui/scripts/panes.tcl
- Timestamp:
- Oct 22, 2010, 4:06:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/panes.tcl
r1865 r1929 74 74 set pname "pane[incr _counter]" 75 75 itk_component add $pname { 76 76 frame $itk_interior.$pname 77 77 } 78 78 … … 94 94 itcl::body Rappture::Panes::insert {pos args} { 95 95 Rappture::getopts args params { 96 96 value -fraction 0.5 97 97 } 98 98 if {[llength $args] > 0} { 99 99 error "wrong # args: should be \"insert pos ?-fraction f?\"" 100 100 } 101 101 … … 103 103 set sash "${pname}sash" 104 104 itk_component add $sash { 105 105 frame $itk_interior.$sash 106 106 } { 107 108 107 usual 108 rename -cursor -sashcursor sashCursor SashCursor 109 109 } 110 110 bind $itk_component($sash) <Enter> [itcl::code $this hilite on $sash] … … 112 112 113 113 itk_component add ${sash}ridge { 114 114 frame $itk_component($sash).ridge 115 115 } { 116 117 118 119 116 usual 117 rename -cursor -sashcursor sashCursor SashCursor 118 rename -relief -sashrelief sashRelief SashRelief 119 ignore -borderwidth 120 120 } 121 121 if { $orientation == "vertical" } { 122 123 } else { 124 122 pack $itk_component(${sash}ridge) -fill x 123 } else { 124 pack $itk_component(${sash}ridge) -fill y -side left 125 125 } 126 126 foreach comp [list $sash ${sash}ridge] { 127 128 129 130 131 132 127 bind $itk_component($comp) <ButtonPress-1> \ 128 [itcl::code $this _grab $pname %X %Y] 129 bind $itk_component($comp) <B1-Motion> \ 130 [itcl::code $this _drag $pname %X %Y] 131 bind $itk_component($comp) <ButtonRelease-1> \ 132 [itcl::code $this _drop $pname %X %Y] 133 133 } 134 134 135 135 136 136 itk_component add $pname { 137 137 frame $itk_interior.$pname 138 138 } 139 139 set _panes [linsert $_panes $pos $pname] … … 158 158 set pname [lindex $_panes $pos] 159 159 if {[info exists itk_component($pname)]} { 160 160 return $itk_component($pname) 161 161 } 162 162 return "" … … 171 171 itcl::body Rappture::Panes::visibility {pos {newval ""}} { 172 172 if {"" == $newval} { 173 173 return [lindex $_visibility $pos] 174 174 } 175 175 if {![string is boolean $newval]} { 176 176 error "bad value \"$newval\": should be boolean" 177 177 } 178 178 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 179 180 181 } else { 182 179 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 180 $_dispatcher event -idle !layout 181 } else { 182 error "bad index \"$pos\": out of range" 183 183 } 184 184 } … … 192 192 itcl::body Rappture::Panes::fraction {pos {newval ""}} { 193 193 if {"" == $newval} { 194 194 return [lindex $_frac $pos] 195 195 } 196 196 if {![string is double $newval]} { 197 197 error "bad value \"$newval\": should be fraction 0-1" 198 198 } 199 199 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} { 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 } else { 219 200 set len [llength $_frac] 201 set _frac [lreplace $_frac $pos $pos xxx] 202 set total 0 203 foreach f $_frac { 204 if {"xxx" != $f} { 205 set total [expr {$total+$f}] 206 } 207 } 208 for {set i 0} {$i < $len} {incr i} { 209 set f [lindex $_frac $i] 210 if {"xxx" == $f} { 211 set f $newval 212 } else { 213 set f [expr {$f/$total - $newval/double($len-1)}] 214 } 215 set _frac [lreplace $_frac $i $i $f] 216 } 217 $_dispatcher event -idle !layout 218 } else { 219 error "bad index \"$pos\": out of range" 220 220 } 221 221 } … … 230 230 switch -- $itk_option(-sashrelief) { 231 231 sunken { 232 233 234 235 236 232 if {$state} { 233 $itk_component(${sash}ridge) configure -relief raised 234 } else { 235 $itk_component(${sash}ridge) configure -relief sunken 236 } 237 237 } 238 238 raised { 239 240 241 242 243 239 if {$state} { 240 $itk_component(${sash}ridge) configure -relief sunken 241 } else { 242 $itk_component(${sash}ridge) configure -relief raised 243 } 244 244 } 245 245 solid { 246 247 248 249 250 251 246 if {$state} { 247 $itk_component($sash) configure -background black 248 } else { 249 $itk_component($sash) configure \ 250 -background $itk_option(-background) 251 } 252 252 } 253 253 } … … 270 270 itcl::body Rappture::Panes::_drag {pname X Y} { 271 271 if { $orientation == "vertical" } { 272 273 274 275 } else { 276 277 278 272 set realY [expr {$Y-[winfo rooty $itk_component(hull)]}] 273 set Ymax [winfo height $itk_component(hull)] 274 set frac [expr double($realY)/$Ymax] 275 } else { 276 set realX [expr {$X-[winfo rootx $itk_component(hull)]}] 277 set Xmax [winfo width $itk_component(hull)] 278 set frac [expr double($realX)/$Xmax] 279 279 } 280 280 if {$frac < 0.05} { 281 281 set frac 0.05 282 282 } 283 283 if {$frac > 0.95} { 284 284 set frac 0.95 285 285 } 286 286 if {[llength $_frac] == 2} { 287 288 } else { 289 290 291 292 287 set _frac [list $frac [expr {1-$frac}]] 288 } else { 289 set i [expr {[lsearch $_panes $pname]-1}] 290 if {$i >= 0} { 291 set _frac [lreplace $_frac $i $i $frac] 292 } 293 293 } 294 294 _fixLayout … … 314 314 itcl::body Rappture::Panes::_fixLayout {args} { 315 315 if { $orientation == "vertical" } { 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 } else { 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 316 set h [winfo height $itk_component(hull)] 317 318 set plist "" 319 set flist "" 320 foreach p $_panes f $_frac v $_visibility { 321 set sash ${p}sash 322 if {$v} { 323 # this pane is visible -- make room for it 324 lappend plist $p 325 lappend flist $f 326 if {[info exists itk_component($sash)]} { 327 set h [expr {$h - [winfo reqheight $itk_component($sash)]}] 328 } 329 } else { 330 # this pane is not visible -- remove sash 331 if {[info exists itk_component($sash)]} { 332 place forget $itk_component($sash) 333 } 334 place forget $itk_component($p) 335 } 336 } 337 338 # normalize the fractions so they add up to 1 339 set total 0 340 foreach f $flist { set total [expr {$total+$f}] } 341 set newflist "" 342 foreach f $flist { 343 lappend newflist [expr {double($f)/$total}] 344 } 345 set flist $newflist 346 347 # lay out the various panes 348 set y 0 349 foreach p $plist f $flist { 350 set sash ${p}sash 351 if {[info exists itk_component($sash)]} { 352 set sh [winfo reqheight $itk_component($sash)] 353 place $itk_component($sash) -y $y -relx 0.5 -anchor n \ 354 -relwidth 1.0 -height $sh 355 set y [expr {$y + $sh}] 356 } 357 358 set ph [expr {$h*$f}] 359 place $itk_component($p) -y $y -relx 0.5 -anchor n \ 360 -relwidth 1.0 -height $ph 361 set y [expr {$y + $ph}] 362 } 363 } else { 364 set w [winfo width $itk_component(hull)] 365 366 set plist "" 367 set flist "" 368 foreach p $_panes f $_frac v $_visibility { 369 set sash ${p}sash 370 if {$v} { 371 # this pane is visible -- make room for it 372 lappend plist $p 373 lappend flist $f 374 if {[info exists itk_component($sash)]} { 375 set w [expr {$w - [winfo reqwidth $itk_component($sash)]}] 376 } 377 } else { 378 # this pane is not visible -- remove sash 379 if {[info exists itk_component($sash)]} { 380 place forget $itk_component($sash) 381 } 382 place forget $itk_component($p) 383 } 384 } 385 386 # normalize the fractions so they add up to 1 387 set total 0 388 foreach f $flist { set total [expr {$total+$f}] } 389 set newflist "" 390 foreach f $flist { 391 lappend newflist [expr {double($f)/$total}] 392 } 393 set flist $newflist 394 395 # lay out the various panes 396 set x 0 397 foreach p $plist f $flist { 398 set sash ${p}sash 399 if {[info exists itk_component($sash)]} { 400 set sw [winfo reqwidth $itk_component($sash)] 401 place $itk_component($sash) -x $x -rely 0.5 -anchor w \ 402 -relheight 1.0 -width $sw 403 set x [expr {$x + $sw}] 404 } 405 406 set pw [expr {$w*$f}] 407 place $itk_component($p) -x $x -rely 0.5 -anchor w \ 408 -relheight 1.0 -width $pw 409 set x [expr {$x + $pw}] 410 } 411 411 } 412 412 } … … 420 420 itcl::body Rappture::Panes::_fixSashes {args} { 421 421 if { $orientation == "vertical" } { 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 } else { 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 422 set ht [winfo pixels $itk_component(hull) $itk_option(-sashwidth)] 423 set bd [expr {$ht/2}] 424 foreach pane $_panes { 425 set sash "${pane}sashridge" 426 if {[info exists itk_component($sash)]} { 427 $itk_component($sash) configure -height $ht -borderwidth $bd 428 if {$itk_option(-sashrelief) == "solid"} { 429 $itk_component($sash) configure -background black 430 } else { 431 $itk_component($sash) configure \ 432 -background $itk_option(-background) 433 } 434 pack $itk_component($sash) -pady $itk_option(-sashpadding) 435 } 436 } 437 } else { 438 set w [winfo pixels $itk_component(hull) $itk_option(-sashwidth)] 439 set bd [expr {$w/2}] 440 foreach pane $_panes { 441 set sash "${pane}sashridge" 442 if {[info exists itk_component($sash)]} { 443 $itk_component($sash) configure -width $w -borderwidth $bd 444 if {$itk_option(-sashrelief) == "solid"} { 445 $itk_component($sash) configure -background black 446 } else { 447 $itk_component($sash) configure \ 448 -background $itk_option(-background) 449 } 450 pack $itk_component($sash) -padx $itk_option(-sashpadding) \ 451 -side left 452 } 453 } 454 454 } 455 455 }
Note: See TracChangeset
for help on using the changeset viewer.