Gnocl Cookbook‎ > ‎

Paned Popup Menu

The paned widget is really udeful when want to dynamically resize the space allocated to closely related widget layouts. However! Maximizing, Minimizing the panes can be tricky and then how can we easily reset the position to some default? The following code example shows how.

# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set but1 [gnocl::button -text "Button left"]
set but2 [gnocl::button  -text "Button right"]
set paned [gnocl::paned  -orientation horizontal  -children "$but1 $but2" ]

gnocl::window  -title "Paned"  -child $paned -setSize 0.4

$paned configure \
    -default 0.23 \
    -onButtonPress { if { %b == 3 } { panedPopup %w %X %Y } }
# Paned window handle popup-menu, convenient way to mini/maximize panels and reset to defaults.
# Result default proportion is 0.5, but can be modified with the widget's -default option.
# Arguments:
#    wid        paned widget id
#    X        pointer X position within widget (%X)
#    Y        pointer Y position within widget (%Y)
# Returns:
#    none
proc panedPopup { wid X Y} {   
    set menu [gnocl::menu -title "menu"]
    $menu add [gnocl::menuItem -text "Minimize" -data $wid -onClicked { %d configure -proportion 0.0 }]
    $menu add [gnocl::menuItem -text "Maximize" -data $wid -onClicked { %d configure -proportion 1.0 }]
    $menu add [gnocl::menuSeparator]
    $menu add [gnocl::menuItem -text "Reset" -data $wid -onClicked { %d reset }]
    $menu popup $X $Y