Ignore:
Timestamp:
Oct 22, 2010, 4:06:10 PM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/panes.tcl

    r1865 r1929  
    7474    set pname "pane[incr _counter]"
    7575    itk_component add $pname {
    76         frame $itk_interior.$pname
     76        frame $itk_interior.$pname
    7777    }
    7878
     
    9494itcl::body Rappture::Panes::insert {pos args} {
    9595    Rappture::getopts args params {
    96         value -fraction 0.5
     96        value -fraction 0.5
    9797    }
    9898    if {[llength $args] > 0} {
    99         error "wrong # args: should be \"insert pos ?-fraction f?\""
     99        error "wrong # args: should be \"insert pos ?-fraction f?\""
    100100    }
    101101
     
    103103    set sash "${pname}sash"
    104104    itk_component add $sash {
    105         frame $itk_interior.$sash
     105        frame $itk_interior.$sash
    106106    } {
    107         usual
    108         rename -cursor -sashcursor sashCursor SashCursor
     107        usual
     108        rename -cursor -sashcursor sashCursor SashCursor
    109109    }
    110110    bind $itk_component($sash) <Enter> [itcl::code $this hilite on $sash]
     
    112112
    113113    itk_component add ${sash}ridge {
    114         frame $itk_component($sash).ridge
     114        frame $itk_component($sash).ridge
    115115    } {
    116         usual
    117         rename -cursor -sashcursor sashCursor SashCursor
    118         rename -relief -sashrelief sashRelief SashRelief
    119         ignore -borderwidth
     116        usual
     117        rename -cursor -sashcursor sashCursor SashCursor
     118        rename -relief -sashrelief sashRelief SashRelief
     119        ignore -borderwidth
    120120    }
    121121    if { $orientation == "vertical" } {
    122         pack $itk_component(${sash}ridge) -fill x
    123     } else {
    124         pack $itk_component(${sash}ridge) -fill y -side left
     122        pack $itk_component(${sash}ridge) -fill x
     123    } else {
     124        pack $itk_component(${sash}ridge) -fill y -side left
    125125    }
    126126    foreach comp [list $sash ${sash}ridge] {
    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]
     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]
    133133    }
    134134
    135135
    136136    itk_component add $pname {
    137         frame $itk_interior.$pname
     137        frame $itk_interior.$pname
    138138    }
    139139    set _panes [linsert $_panes $pos $pname]
     
    158158    set pname [lindex $_panes $pos]
    159159    if {[info exists itk_component($pname)]} {
    160         return $itk_component($pname)
     160        return $itk_component($pname)
    161161    }
    162162    return ""
     
    171171itcl::body Rappture::Panes::visibility {pos {newval ""}} {
    172172    if {"" == $newval} {
    173         return [lindex $_visibility $pos]
     173        return [lindex $_visibility $pos]
    174174    }
    175175    if {![string is boolean $newval]} {
    176         error "bad value \"$newval\": should be boolean"
     176        error "bad value \"$newval\": should be boolean"
    177177    }
    178178    if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} {
    179         set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]]
    180         $_dispatcher event -idle !layout
    181     } else {
    182         error "bad index \"$pos\": out of range"
     179        set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]]
     180        $_dispatcher event -idle !layout
     181    } else {
     182        error "bad index \"$pos\": out of range"
    183183    }
    184184}
     
    192192itcl::body Rappture::Panes::fraction {pos {newval ""}} {
    193193    if {"" == $newval} {
    194         return [lindex $_frac $pos]
     194        return [lindex $_frac $pos]
    195195    }
    196196    if {![string is double $newval]} {
    197         error "bad value \"$newval\": should be fraction 0-1"
     197        error "bad value \"$newval\": should be fraction 0-1"
    198198    }
    199199    if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} {
    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"
     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"
    220220    }
    221221}
     
    230230    switch -- $itk_option(-sashrelief) {
    231231      sunken {
    232         if {$state} {
    233             $itk_component(${sash}ridge) configure -relief raised
    234         } else {
    235             $itk_component(${sash}ridge) configure -relief sunken
    236         }
     232        if {$state} {
     233            $itk_component(${sash}ridge) configure -relief raised
     234        } else {
     235            $itk_component(${sash}ridge) configure -relief sunken
     236        }
    237237      }
    238238      raised {
    239         if {$state} {
    240             $itk_component(${sash}ridge) configure -relief sunken
    241         } else {
    242             $itk_component(${sash}ridge) configure -relief raised
    243         }
     239        if {$state} {
     240            $itk_component(${sash}ridge) configure -relief sunken
     241        } else {
     242            $itk_component(${sash}ridge) configure -relief raised
     243        }
    244244      }
    245245      solid {
    246         if {$state} {
    247             $itk_component($sash) configure -background black
    248         } else {
    249             $itk_component($sash) configure \
    250                 -background $itk_option(-background)
    251         }
     246        if {$state} {
     247            $itk_component($sash) configure -background black
     248        } else {
     249            $itk_component($sash) configure \
     250                -background $itk_option(-background)
     251        }
    252252      }
    253253    }
     
    270270itcl::body Rappture::Panes::_drag {pname X Y} {
    271271    if { $orientation == "vertical" } {
    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]
     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]
    279279    }
    280280    if {$frac < 0.05} {
    281         set frac 0.05
     281        set frac 0.05
    282282    }
    283283    if {$frac > 0.95} {
    284         set frac 0.95
     284        set frac 0.95
    285285    }
    286286    if {[llength $_frac] == 2} {
    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         }
     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        }
    293293    }
    294294    _fixLayout
     
    314314itcl::body Rappture::Panes::_fixLayout {args} {
    315315    if { $orientation == "vertical" } {
    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         }
     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        }
    411411    }   
    412412}
     
    420420itcl::body Rappture::Panes::_fixSashes {args} {
    421421    if { $orientation == "vertical" } {
    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         }
     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        }
    454454    }
    455455}
Note: See TracChangeset for help on using the changeset viewer.