Ignore:
Timestamp:
Jul 19, 2007 5:21:51 AM (17 years ago)
Author:
mmc
Message:

Added support for a <note> on the output side of an <image> object.
This was needed for app-nsopticsjr. We should experiement a little
more with this, design it properly, and apply the same idea to all
output items.

File:
1 edited

Legend:

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

    r428 r785  
    3333    public method insert {pos args}
    3434    public method pane {pos}
     35    public method visibility {pos {newval ""}}
    3536    public method fraction {pos {newval ""}}
    3637    public method hilite {state sash}
     
    4445    private variable _dispatcher ""  ;# dispatcher for !events
    4546    private variable _panes ""       ;# list of pane frames
     47    private variable _visibility ""  ;# list of visibilities for panes
    4648    private variable _counter 0      ;# counter for auto-generated names
    47     private variable _frac 1.0       ;# list of fractions
     49    private variable _frac 0.0       ;# list of fractions
    4850}
    4951
     
    7476
    7577    lappend _panes $pname
     78    lappend _visibility 1
     79    set _frac 0.5
    7680
    7781    eval itk_initialize $args
     
    128132        frame $itk_interior.$pname
    129133    }
    130     lappend _panes $pname
    131 
    132     # fix the fractional sizes
    133     set f $params(-fraction)
    134     set _frac [list [expr {1-$f}] $f]
     134    set _panes [linsert $_panes $pos $pname]
     135    set _visibility [linsert $_visibility $pos 1]
     136    set _frac [linsert $_frac $pos $params(-fraction)]
    135137
    136138    # fix sash characteristics
     
    157159
    158160# ----------------------------------------------------------------------
     161# USAGE: visibility <pos> ?<newval>?
     162#
     163# Clients use this to get/set the visibility of the pane at position
     164# <pos>.
     165# ----------------------------------------------------------------------
     166itcl::body Rappture::Panes::visibility {pos {newval ""}} {
     167    if {"" == $newval} {
     168        return [lindex $_visibility $pos]
     169    }
     170    if {![string is boolean $newval]} {
     171        error "bad value \"$newval\": should be boolean"
     172    }
     173    if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} {
     174        set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]]
     175        $_dispatcher event -idle !layout
     176    } else {
     177        error "bad index \"$pos\": out of range"
     178    }
     179}
     180
     181# ----------------------------------------------------------------------
    159182# USAGE: fraction <pos> ?<newval>?
    160183#
     
    170193    }
    171194    if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} {
    172         # if there are other panes, adjust their size according to this
    173         if {[llength $_frac] > 1} {
    174             set oldval [lindex $_frac $pos]
    175             set delta [expr {double($oldval-$newval)/([llength $_frac]-1)}]
    176             for {set i 0} {$i < [llength $_frac]} {incr i} {
    177                 set v [lindex $_frac $i]
    178                 set _frac [lreplace $_frac $i $i [expr {$v+$delta}]]
    179             }
    180         }
    181         set _frac [lreplace $_frac $pos $pos $newval]
     195        set len [llength $_frac]
     196        set _frac [lreplace $_frac $pos $pos xxx]
     197        set total 0
     198        foreach f $_frac {
     199            if {"xxx" != $f} {
     200                set total [expr {$total+$f}]
     201            }
     202        }
     203        for {set i 0} {$i < $len} {incr i} {
     204            set f [lindex $_frac $i]
     205            if {"xxx" == $f} {
     206                set f $newval
     207            } else {
     208                set f [expr {$f/$total - $newval/double($len-1)}]
     209            }
     210            set _frac [lreplace $_frac $i $i $f]
     211        }
    182212        $_dispatcher event -idle !layout
    183213    } else {
     
    243273        set frac 0.95
    244274    }
    245 
    246     set _frac [list $frac [expr {1-$frac}]]
     275    if {[llength $_frac] == 2} {
     276        set _frac [list $frac [expr {1-$frac}]]
     277    } else {
     278        set i [expr {[lsearch $_panes $pname]-1}]
     279        if {$i >= 0} {
     280            set _frac [lreplace $_frac $i $i $frac]
     281        }
     282    }
    247283    _fixLayout
    248284
     
    267303itcl::body Rappture::Panes::_fixLayout {args} {
    268304    set h [winfo height $itk_component(hull)]
    269     foreach p [lrange $_panes 1 end] {
    270         set h [expr {$h - [winfo height $itk_component(${p}sash)]}]
    271     }
    272 
     305
     306    set plist ""
     307    set flist ""
     308    foreach p $_panes f $_frac v $_visibility {
     309        set sash ${p}sash
     310        if {$v} {
     311            # this pane is visible -- make room for it
     312            lappend plist $p
     313            lappend flist $f
     314            if {[info exists itk_component($sash)]} {
     315                set h [expr {$h - [winfo height $itk_component($sash)]}]
     316            }
     317        } else {
     318            # this pane is not visible -- remove sash
     319            if {[info exists itk_component($sash)]} {
     320                place forget $itk_component($sash)
     321            }
     322            place forget $itk_component($p)
     323        }
     324    }
     325
     326    # normalize the fractions so they add up to 1
     327    set total 0
     328    foreach f $flist { set total [expr {$total+$f}] }
     329    set newflist ""
     330    foreach f $flist {
     331        lappend newflist [expr {double($f)/$total}]
     332    }
     333    set flist $newflist
     334
     335    # lay out the various panes
    273336    set y 0
    274     foreach p $_panes f $_frac {
     337    foreach p $plist f $flist {
    275338        set sash ${p}sash
    276339        if {[info exists itk_component($sash)]} {
Note: See TracChangeset for help on using the changeset viewer.