Gnocl Cookbook‎ > ‎

Tearing off Notebook Pages



# test-notebook-tearoff.tcl
#!/bin/sh \
exec tclsh "$0" "$@"

package require Gnocl

global tabNo 0

# button callback handlers
# add page
proc startWidgetCB { nb } {

    global tabNo

    set txt [gnocl::text -wrapMode word]
    set id [$nb addPage $txt TAB-[incr tabNo]]
    $nb currentPage $id

    return $id
}


# button callback handlers -endWidget
# removepage
proc endWidgetCB {nb } {

    $nb removePage [$nb currentPage]

}

# re-use the callbacks as commands
interp alias {} addPage {} startWidgetCB
interp alias {} removePage {} endWidgetCB

# notebook creator
proc tabbed {} {

    set but1 [gnocl::button -icon %#Add \
        -onClicked { startWidgetCB %d }]   

    set but2 [gnocl::button -icon %#Remove \
        -onClicked { endWidgetCB %d } ]   

    # a full cream notebook
    set notebook [gnocl::notebook \
        -detachable 1 \
        -reorderable 1 \
        -groupId 1 \
        -onCreateWindow {
            # this option in necessary to handle the creation of tear-off windows
            %t configure -title %c
            %w configure -tabPosition left
            #puts "%w "
             } \
        -homogeneous 1 \
        -startWidget $but1 \
        -endWidget $but2 \
        -enablePopup 1 \
        -scrollable 1]


    # use -data to keep names of data such as wids
    $but1 configure -data $notebook
    $but2 configure -data $notebook

    addPage $notebook
    addPage $notebook

    return $notebook
}


set myNB [tabbed]


gnocl::window \
    -title "Notebook" \
    -child $myNB \
    -setSize 0.2

# Which text widget is currently displayed? Get the child of the currentPage
puts currentPage=[$myNB currentPage]
[$myNB nthPage [$myNB currentPage]] lorem


# writing directly to the hidden notebook pages contents can be achieved with this proc
proc nb_set_text {w i str} {
    [$w nthPage $i] set $str
}


nb_set_text $myNB 1 "How Now Brown Cow."







Comments