Sliding panel

EKB This is a simple sliding panel widget (implemented as a Snit widget).

Here's what the output looks like with three stacked sliding panel widgets. First, with all panes closed:

http://www.kb-creative.net/screenshots/slidepanes_closed.gif

Then with one of them open:

http://www.kb-creative.net/screenshots/slidepanes_open.gif

Here's the code, with the three-panel sample at the end. This is NOL - the "no obligation license".

    package require snit
    
    image create photo slidepane_uparrow -data {
       R0lGODlhDwAQAIMAAPwCBARCZKze7IzK3ITC1Hy6zHSuzGSmxFyevAAAAAAA
       AAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAPABAAAAQ1EMhJq70428A1
       CEIYZOBgDuMmEGybTmAhG3Pxgkau7yN4/MDgj4MoGo/GHmfJXHqe0KjHHgEA
       If5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2
       ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDov
       L3d3dy5kZXZlbGNvci5jb20AOw==
    }
    
    image create photo slidepane_downarrow -data {
       R0lGODlhDwAQAIMAAPwCBARCZKza5Kze7JzO3JTG1IS61HyyzGyivEyOtESG
       rDx+pCxynCRqlBxejAAAACH5BAEAAAAALAAAAAAPABAAAAQ8EMhJq704axu6
       /x4QCAMpnARRGAfSJXAsx4Go3Hiu1FKw/EAgbxJgGI+MISXQaDqSmYBjqryE
       Ntis1h4BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41
       DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4N
       Cmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs=
    }
    
    snit::widget slidepane {
        hulltype frame
        
        option -text ""
        option -font {Helvetica 8 italic}
        option -relief flat
        option -bd 0
        option -barrelief groove
        option -barlocation top
        
        variable closebutton
        variable openbutton
        variable buttonpath
        variable panestate
        variable panepath
        
        constructor {args} {
            $self configurelist $args
    
            frame $win.bar -relief $options(-barrelief)  -bd 2
            pack $win.bar -side $options(-barlocation) -fill x
            label $win.bar.l -text $options(-text) -font $options(-font)
            pack $win.bar.l -side left -fill x
            set panepath [frame $win.main -bd $options(-bd) -relief $options(-relief)]
            pack $win.main -fill both
            
            if {$options(-barlocation) == "top"} {
                set closebutton slidepane_uparrow
                set openbutton slidepane_downarrow
            } else {
                set closebutton slidepane_downarrow
                set openbutton slidepane_uparrow
            }
            set buttonpath [button $win.bar.b -image $closebutton -command [mymethod toggle]\
                -relief flat]
            set panestate visible
            pack $buttonpath -side right
            
        }
        
        method toggle {} {
            if {$panestate == "visible"} {
                pack forget $panepath
                $buttonpath config -image $openbutton
                set panestate hidden
            } else {
                pack $panepath -fill both
                $buttonpath config -image $closebutton
                set panestate visible
            }
        }
        
        method pane {} {
            return $panepath
        }
    }
    
    ## An example
    wm geometry . 50x200
    slidepane .pane1 -text "Top"
    label [.pane1 pane].l -text "Hi, there!"
    pack [.pane1 pane].l -side left
    pack .pane1 -side top -fill both
    
    slidepane .pane2 -text "Middle"
    checkbutton [.pane2 pane].c -text "Is it true?"
    pack [.pane2 pane].c -side top -anchor w
    button [.pane2 pane].b -text "OK"
    pack [.pane2 pane].b -side top
    pack .pane2 -side top -fill both
    
    slidepane .pane3 -text "Bottom"
    label [.pane3 pane].l -text "Peep bo!"
    pack [.pane3 pane].l -side left
    pack .pane3 -side top -fill both

Good!! -- ming


See also: wrapframe