Friday, April 20, 2012

Removing widgets from gnocl::box containers

Hitherto it has been possible to add widgets to a box but not to remove them, perhaps for repacking or hiding. The addition of the remove command to the gnocl::box object will now allow this to be done.  Here's a demo script:

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set title "Shared Buffer"

set tb [gnocl::textBuffer]
set tv(1) [gnocl::text -wrapMode word -buffer $tb]
set tv(2) [gnocl::text -wrapMode word -baseColor #FDFDB3 -buffer $tb]

$tv(1) lorem

# create maincontainer
set box(main) [gnocl::box \
    -orientation vertical \
    -align topLeft]
   
set box(texts) [gnocl::box \
    -orientation vertical \
    -children [list $tv(1)] \
    -fill {1 1} \
    -expand 1]

 # create toolBar
 set split 0
 set toolBar [gnocl::toolBar]
 $toolBar add widget [gnocl::toggleButton \
    -variable split \
    -text "Split" \
    -onToggled {
        if {$split} {
            $box(texts) add $tv(2) -fill {1 1} -expand 1
        } else {
        $box(texts) remove $tv(2)
        } }]

 # pack the main container
 $box(main) add $toolBar -fill {1 0} -expand 0
 $box(main) add $box(texts) -fill {1 1} -expand 1

 set main [gnocl::window \
    -title $title \
    -onDelete { exit } \
    -child $box(main) \
    -defaultWidth 480 \
    -defaultHeight 320]

gnocl::mainLoop



No comments: