Changeset 5060 for branches/1.4
- Timestamp:
- Mar 3, 2015, 2:21:49 PM (10 years ago)
- Location:
- branches/1.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.4
- Property svn:mergeinfo changed
/trunk merged: 5044,5056
- Property svn:mergeinfo changed
-
branches/1.4/gui/scripts/analyzer.tcl
r4760 r5060 315 315 316 316 itk_component add results { 317 Rappture::Panes $w.pane -sashwidth 1 -sashrelief solid -sashpadding {4 0} 317 Rappture::Panes $w.pane \ 318 -sashwidth 2 -sashrelief solid -sashpadding {2 0} 319 } { 320 usual 321 ignore -sashwidth -sashrelief -sashpadding 318 322 } 319 323 pack $itk_component(results) -expand yes -fill both -
branches/1.4/gui/scripts/imageresult.tcl
r3844 r5060 72 72 pack propagate $itk_component(hull) no 73 73 74 Rappture::Panes $itk_interior.panes -sashwidth 1 -sashrelief solid -sashpadding 2 74 Rappture::Panes $itk_interior.panes \ 75 -sashwidth 2 -sashrelief solid -sashpadding 1 76 75 77 pack $itk_interior.panes -expand yes -fill both 76 78 set main [$itk_interior.panes pane 0] -
branches/1.4/gui/scripts/panes.tcl
r3330 r5060 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 3 2 # ---------------------------------------------------------------------- 4 3 # COMPONENT: Panes - creates a series of adjustable panes … … 9 8 # ====================================================================== 10 9 # AUTHOR: Michael McLennan, Purdue University 11 # Copyright (c) 2004-201 2HUBzero Foundation, LLC10 # Copyright (c) 2004-2015 HUBzero Foundation, LLC 12 11 # 13 12 # See the file "license.terms" for information on usage and … … 21 20 option add *Panes.sashWidth 2 widgetDefault 22 21 option add *Panes.sashPadding 4 widgetDefault 23 option add *Panes. sashCursor sb_v_double_arrow22 option add *Panes.orientation vertical widgetDefault 24 23 25 24 itcl::class Rappture::Panes { 26 25 inherit itk::Widget 27 26 28 itk_option define -sashcursor sashCursor SashCursor ""29 27 itk_option define -sashrelief sashRelief SashRelief "" 30 28 itk_option define -sashwidth sashWidth SashWidth 0 31 29 itk_option define -sashpadding sashPadding SashPadding 0 30 itk_option define -orientation orientation Orientation "" 32 31 33 32 constructor {args} { # defined below } … … 35 34 public method insert {pos args} 36 35 public method pane {pos} 37 public method visibility {pos {newval ""}}38 public method fraction {pos {newval ""}}36 public method visibility {pos args} 37 public method fraction {pos args} 39 38 public method hilite {state sash} 39 public method size {} 40 40 41 41 protected method _grab {pane X Y} … … 49 49 private variable _visibility "" ;# list of visibilities for panes 50 50 private variable _counter 0 ;# counter for auto-generated names 51 private variable _frac 0.0 ;# list of fractions 52 public variable orientation "vertical" 51 private variable _reqfrac 0.0 ;# requested fraction size of each pane 52 private variable _dragfrom 0 ;# starting coordinate of drag operation 53 private variable _dragfrac 0 ;# limit on fraction of drag operation 53 54 } 54 55 55 56 itk::usual Panes { 56 keep -background -cursor 57 keep -background -cursor -sashwidth -sashrelief 57 58 } 58 59 … … 80 81 lappend _panes $pname 81 82 lappend _visibility 1 82 set _ frac 0.583 set _reqfrac 0.5 83 84 84 85 eval itk_initialize $args … … 107 108 } { 108 109 usual 109 rename -cursor -sashcursor sashCursor SashCursor110 ignore -cursor 110 111 } 111 112 bind $itk_component($sash) <Enter> [itcl::code $this hilite on $sash] … … 116 117 } { 117 118 usual 118 rename -cursor -sashcursor sashCursor SashCursor119 119 rename -relief -sashrelief sashRelief SashRelief 120 120 ignore -borderwidth 121 121 } 122 if { $orientation == "vertical"} {122 if {$itk_option(-orientation) eq "vertical"} { 123 123 pack $itk_component(${sash}ridge) -fill x 124 $itk_component($sash) configure -cursor sb_v_double_arrow 125 $itk_component(${sash}ridge) configure -cursor sb_v_double_arrow 124 126 } else { 125 127 pack $itk_component(${sash}ridge) -fill y -side left 128 $itk_component($sash) configure -cursor sb_h_double_arrow 129 $itk_component(${sash}ridge) configure -cursor sb_h_double_arrow 126 130 } 127 131 foreach comp [list $sash ${sash}ridge] { … … 140 144 set _panes [linsert $_panes $pos $pname] 141 145 set _visibility [linsert $_visibility $pos 1] 142 set _ frac [linsert $_frac $pos $params(-fraction)]146 set _reqfrac [linsert $_reqfrac $pos $params(-fraction)] 143 147 144 148 # fix sash characteristics … … 165 169 166 170 # ---------------------------------------------------------------------- 167 # USAGE: visibility <pos> ?<newval>? 171 # USAGE: visibility <pos> ?<newval>? ?<pos> <newval> ...? 168 172 # 169 173 # Clients use this to get/set the visibility of the pane at position 170 # <pos>. 171 # ---------------------------------------------------------------------- 172 itcl::body Rappture::Panes::visibility {pos {newval ""}} { 173 if {"" == $newval} { 174 # <pos>. Can also be used to set the visibility for multiple panes 175 # if multiple <pos>/<newval> pairs are specified in the same command. 176 # ---------------------------------------------------------------------- 177 itcl::body Rappture::Panes::visibility {pos args} { 178 if {[llength $args] == 0} { 174 179 return [lindex $_visibility $pos] 175 180 } 176 if {![string is boolean $newval]} { 177 error "bad value \"$newval\": should be boolean" 178 } 179 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 180 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 181 $_dispatcher event -idle !layout 182 } else { 183 error "bad index \"$pos\": out of range" 184 } 185 } 186 187 # ---------------------------------------------------------------------- 188 # USAGE: fraction <pos> ?<newval>? 181 if {[llength $args] % 2 == 0} { 182 error "wrong # args: should be \"visibility pos ?val pos val ...?\"" 183 } 184 185 set args [linsert $args 0 $pos] 186 foreach {pos newval} $args { 187 if {![string is boolean -strict $newval]} { 188 error "bad value \"$newval\": should be boolean" 189 } 190 if {$pos eq "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 191 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 192 $_dispatcher event -idle !layout 193 } else { 194 error "bad index \"$pos\": out of range" 195 } 196 } 197 } 198 199 # ---------------------------------------------------------------------- 200 # USAGE: fraction <pos> ?<newval>? ?<pos> <newval> ...? 189 201 # 190 202 # Clients use this to get/set the fraction of real estate associated 191 # with the pane at position <pos>. 192 # ---------------------------------------------------------------------- 193 itcl::body Rappture::Panes::fraction {pos {newval ""}} { 194 if {"" == $newval} { 195 return [lindex $_frac $pos] 196 } 197 if {![string is double $newval]} { 198 error "bad value \"$newval\": should be fraction 0-1" 199 } 200 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} { 201 set len [llength $_frac] 202 set _frac [lreplace $_frac $pos $pos xxx] 203 set total 0 204 foreach f $_frac { 205 if {"xxx" != $f} { 206 set total [expr {$total+$f}] 207 } 208 } 209 for {set i 0} {$i < $len} {incr i} { 210 set f [lindex $_frac $i] 211 if {"xxx" == $f} { 212 set f $newval 213 } else { 214 set f [expr {$f/$total - $newval/double($len-1)}] 215 } 216 set _frac [lreplace $_frac $i $i $f] 217 } 218 $_dispatcher event -idle !layout 219 } else { 220 error "bad index \"$pos\": out of range" 203 # with the pane at position <pos>. Can also be used to set the 204 # fractions for multiple panes if multiple <pos>/<newval> pairs 205 # are specified in the same command. 206 # ---------------------------------------------------------------------- 207 itcl::body Rappture::Panes::fraction {pos args} { 208 if {[llength $args] == 0} { 209 return [lindex $_reqfrac $pos] 210 } 211 if {[llength $args] % 2 == 0} { 212 error "wrong # args: should be \"fraction pos ?val pos val ...?\"" 213 } 214 215 set args [linsert $args 0 $pos] 216 foreach {pos newval} $args { 217 if {![string is double -strict $newval]} { 218 error "bad value \"$newval\": should be fraction 0-1" 219 } 220 if {$pos eq "end" || ($pos >= 0 && $pos < [llength $_reqfrac])} { 221 set _reqfrac [lreplace $_reqfrac $pos $pos $newval] 222 $_dispatcher event -idle !layout 223 } else { 224 error "bad index \"$pos\": out of range" 225 } 221 226 } 222 227 } … … 230 235 itcl::body Rappture::Panes::hilite {state sash} { 231 236 switch -- $itk_option(-sashrelief) { 237 flat { 238 if {$state} { 239 $itk_component(${sash}ridge) configure -background black 240 } else { 241 $itk_component(${sash}ridge) configure -background $itk_option(-background) 242 } 243 } 232 244 sunken { 233 245 if {$state} { … … 256 268 257 269 # ---------------------------------------------------------------------- 270 # USAGE: size 271 # 272 # Returns the number of panes in this widget. That makes it easier 273 # to index the various panes, since indices run from 0 to size-1. 274 # ---------------------------------------------------------------------- 275 itcl::body Rappture::Panes::size {} { 276 return [llength $_panes] 277 } 278 279 # ---------------------------------------------------------------------- 258 280 # USAGE: _grab <pane> <X> <Y> 259 281 # … … 262 284 # ---------------------------------------------------------------------- 263 285 itcl::body Rappture::Panes::_grab {pname X Y} { 286 set pos [lsearch $_panes $pname] 287 if {$pos < 0} return 288 set frac0 [lindex $_reqfrac [expr {$pos-1}]] 289 set frac1 [lindex $_reqfrac $pos] 290 set _dragfrac [expr {$frac0+$frac1}] 291 292 if {$itk_option(-orientation) eq "vertical"} { 293 set _dragfrom $Y 294 } else { 295 set _dragfrom $X 296 } 264 297 } 265 298 … … 270 303 # ---------------------------------------------------------------------- 271 304 itcl::body Rappture::Panes::_drag {pname X Y} { 272 if { $orientation == "vertical" } { 273 set realY [expr {$Y-[winfo rooty $itk_component(hull)]}] 305 set pos [lsearch $_panes $pname] 306 if {$pos < 0} return 307 set frac [lindex $_reqfrac $pos] 308 309 if {$itk_option(-orientation) eq "vertical"} { 310 set delY [expr {$_dragfrom-$Y}] 274 311 set Ymax [winfo height $itk_component(hull)] 275 set frac [expr double($realY)/$Ymax] 312 set delta [expr {double($delY)/$Ymax}] 313 set frac [expr {$frac + $delta}] 314 set _dragfrom $Y 276 315 } else { 277 set realX [expr {$X-[winfo rootx $itk_component(hull)]}]316 set delX [expr {$_dragfrom-$X}] 278 317 set Xmax [winfo width $itk_component(hull)] 279 set frac [expr double($realX)/$Xmax] 280 } 318 set delta [expr {double($delX)/$Xmax}] 319 set frac [expr {$frac + $delta}] 320 set _dragfrom $X 321 } 322 if {$delta == 0.0} { 323 return 324 } 325 326 # set limits so the pane can't get too large or too small 281 327 if {$frac < 0.05} { 282 328 set frac 0.05 283 329 } 284 if {$frac > 0.95} { 285 set frac 0.95 286 } 287 if {[llength $_frac] == 2} { 288 set _frac [list $frac [expr {1-$frac}]] 289 } else { 290 set i [expr {[lsearch $_panes $pname]-1}] 291 if {$i >= 0} { 292 set _frac [lreplace $_frac $i $i $frac] 293 } 294 } 330 if {$frac > $_dragfrac-0.05} { 331 set frac [expr {$_dragfrac-0.05}] 332 } 333 334 # replace the fractions for this pane and the one before it 335 set prevfrac [expr {$_dragfrac-$frac}] 336 set _reqfrac [lreplace $_reqfrac [expr {$pos-1}] $pos $prevfrac $frac] 337 338 # normalize all fractions and fix the layout 295 339 _fixLayout 296 340 … … 314 358 # ---------------------------------------------------------------------- 315 359 itcl::body Rappture::Panes::_fixLayout {args} { 316 if { $orientation == "vertical" } { 360 # normalize the fractions for all panes to they add to 1.0 361 set total 0 362 foreach f $_reqfrac v $_visibility { 363 if {$v && $f > 0} { 364 set total [expr {$total + $f}] 365 } 366 } 367 if {$total == 0.0} { set total 1 } 368 369 set normfrac "" 370 foreach f $_reqfrac v $_visibility { 371 if {$v} { 372 lappend normfrac [expr {double($f)/$total}] 373 } else { 374 lappend normfrac [expr {double($f)/$total}] 375 } 376 } 377 378 # note that sash padding can be a single number or different on each side 379 if {[llength $itk_option(-sashpadding)] == 1} { 380 set pad [expr {2*$itk_option(-sashpadding)}] 381 } else { 382 set pad [expr [join $itk_option(-sashpadding) +]] 383 } 384 385 if {$itk_option(-orientation) eq "vertical"} { 317 386 set h [winfo height $itk_component(hull)] 387 set sh [expr {$itk_option(-sashwidth) + $pad}] 318 388 319 389 set plist "" 320 390 set flist "" 321 foreach p $_panes f $ _frac v $_visibility {391 foreach p $_panes f $normfrac v $_visibility { 322 392 set sash ${p}sash 323 393 if {$v} { … … 326 396 lappend flist $f 327 397 if {[info exists itk_component($sash)]} { 328 set h [expr {$h - [winfo reqheight $itk_component($sash)]}]398 set h [expr {$h - $sh}] 329 399 } 330 400 } else { … … 336 406 } 337 407 } 338 339 # normalize the fractions so they add up to 1 340 set total 0 341 foreach f $flist { set total [expr {$total+$f}] } 342 set newflist "" 343 foreach f $flist { 344 lappend newflist [expr {double($f)/$total}] 345 } 346 set flist $newflist 347 408 348 409 # lay out the various panes 349 410 set y 0 … … 351 412 set sash ${p}sash 352 413 if {[info exists itk_component($sash)]} { 353 set sh [winfo reqheight $itk_component($sash)]354 414 place $itk_component($sash) -y $y -relx 0.5 -anchor n \ 355 415 -relwidth 1.0 -height $sh … … 364 424 } else { 365 425 set w [winfo width $itk_component(hull)] 426 set sw [expr {$itk_option(-sashwidth) + $pad}] 366 427 367 428 set plist "" 368 429 set flist "" 369 foreach p $_panes f $ _frac v $_visibility {430 foreach p $_panes f $normfrac v $_visibility { 370 431 set sash ${p}sash 371 432 if {$v} { … … 374 435 lappend flist $f 375 436 if {[info exists itk_component($sash)]} { 376 set w [expr {$w - [winfo reqwidth $itk_component($sash)]}]437 set w [expr {$w - $sw}] 377 438 } 378 439 } else { … … 384 445 } 385 446 } 386 387 # normalize the fractions so they add up to 1 388 set total 0 389 foreach f $flist { set total [expr {$total+$f}] } 390 set newflist "" 391 foreach f $flist { 392 lappend newflist [expr {double($f)/$total}] 393 } 394 set flist $newflist 395 447 396 448 # lay out the various panes 397 449 set x 0 … … 399 451 set sash ${p}sash 400 452 if {[info exists itk_component($sash)]} { 401 set sw [winfo reqwidth $itk_component($sash)]402 453 place $itk_component($sash) -x $x -rely 0.5 -anchor w \ 403 454 -relheight 1.0 -width $sw … … 420 471 # ---------------------------------------------------------------------- 421 472 itcl::body Rappture::Panes::_fixSashes {args} { 422 if { $orientation == "vertical"} {473 if {$itk_option(-orientation) eq "vertical"} { 423 474 set ht [winfo pixels $itk_component(hull) $itk_option(-sashwidth)] 424 475 set bd [expr {$ht/2}] … … 426 477 set sash "${pane}sashridge" 427 478 if {[info exists itk_component($sash)]} { 428 $itk_component($sash) configure -height $ht -borderwidth $bd 429 if {$itk_option(-sashrelief) == "solid"} { 430 $itk_component($sash) configure -background black 431 } else { 432 $itk_component($sash) configure \ 433 -background $itk_option(-background) 434 } 435 pack $itk_component($sash) -pady $itk_option(-sashpadding) 479 $itk_component($sash) configure -height $ht \ 480 -borderwidth $bd -relief $itk_option(-sashrelief) 481 pack $itk_component($sash) -pady $itk_option(-sashpadding) \ 482 -side top 436 483 } 437 484 } … … 442 489 set sash "${pane}sashridge" 443 490 if {[info exists itk_component($sash)]} { 444 $itk_component($sash) configure -width $w -borderwidth $bd 445 if {$itk_option(-sashrelief) == "solid"} { 446 $itk_component($sash) configure -background black 447 } else { 448 $itk_component($sash) configure \ 449 -background $itk_option(-background) 450 } 491 $itk_component($sash) configure -width $w \ 492 -borderwidth $bd -relief $itk_option(-sashrelief) 451 493 pack $itk_component($sash) -padx $itk_option(-sashpadding) \ 452 494 -side left … … 474 516 # ---------------------------------------------------------------------- 475 517 itcl::configbody Rappture::Panes::sashpadding { 518 set count 0 519 foreach val $itk_option(-sashpadding) { 520 if {![string is integer -strict $val]} { 521 error "bad padding value \"$val\": should be integer" 522 } 523 incr count 524 } 525 if {$count < 1 || $count > 2} { 526 error "bad padding value \"$itk_option(-sashpadding)\": should be \"#\" or \"# #\"" 527 } 476 528 $_dispatcher event -idle !sashes 477 529 } 530 531 # ---------------------------------------------------------------------- 532 # CONFIGURATION OPTION: -orientation 533 # ---------------------------------------------------------------------- 534 itcl::configbody Rappture::Panes::orientation { 535 foreach pname $_panes { 536 set sash "${pname}sash" 537 if {$itk_option(-orientation) eq "vertical"} { 538 place $itk_component($pname) -x 0 -relx 0.5 -relwidth 1 \ 539 -y 0 -rely 0 -relheight 0 540 541 if {[info exists itk_component($sash)]} { 542 place $itk_component($sash) -x 0 -relx 0.5 -relwidth 1 \ 543 -y 0 -rely 0 -relheight 0 544 $itk_component($sash) configure \ 545 -cursor sb_v_double_arrow 546 547 pack $itk_component(${sash}ridge) -fill x -side top 548 $itk_component(${sash}ridge) configure \ 549 -cursor sb_v_double_arrow 550 } 551 } else { 552 place $itk_component($pname) -y 0 -rely 0.5 -relheight 1 \ 553 -x 0 -relx 0 -relwidth 0 554 555 if {[info exists itk_component($sash)]} { 556 place $itk_component($sash) -y 0 -rely 0.5 -relheight 1 \ 557 -x 0 -relx 0 -relwidth 0 558 $itk_component($sash) configure \ 559 -cursor sb_h_double_arrow 560 561 pack $itk_component(${sash}ridge) -fill y -side left 562 $itk_component(${sash}ridge) configure \ 563 -cursor sb_h_double_arrow 564 } 565 } 566 } 567 568 # fix sash characteristics 569 $_dispatcher event -idle !sashes 570 571 # make sure we fix up the layout at some point 572 $_dispatcher event -idle !layout 573 }
Note: See TracChangeset
for help on using the changeset viewer.