gnocl::paned

WJG(12/03/18) Gnocl offers a wide range of containers and one which I find especially useful is the gnocl::paned widget. Here the paned contained contains two child widgets which are automatically resized with their parent. The relative proportions of each within the container is controllable through dragging the sash separating the two panes or by script control. Here's an example of it in use. The upper pane contains a tree consisting of the matches based upon a grep search and the lower pane a text widget showing the selected match in the document.

WikiDBImage GnoclPaned

Recently the sash control has obtained a couple of new features, -default which specifies the position of the sash in the container, and the -onButtonPress signal handler to enable script configurable options such popup menus to be implemented. The following example shows how this can be done.

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "[email protected]"

package require Gnocl

set but1 [gnocl::button -text "Left" -widthRequest 100]
set but2 [gnocl::button  -text "Right" -widthRequest 100]
set paned [gnocl::paned  -orientation horizontal  -children "$but1 $but2" ]

gnocl::window  -title "Paned"  -child $paned -height 100
$paned configure \
        -default 0.5 \
        -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
}