GRIDPLUS2 - Container
Home Reference Manpage Examples Download License Contact

GRIDPLUS Container

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS container command mode. This is used to create a container which allows toplevel windows to be embedded in GRIDPLUS layouts.

This facility makes it easy to create a fixed sized area within a layout, the contents of which can be created and destroyed without effecting any other part of the window. The standard GRIDPLUS window and clear command modes are used for this purpose. Toplevel windows can also have contained windows.

To simplify the use of contained windows, whenever a container (or the window containing the container) is cleared using the GRIDPLUS clear command mode, the -windowcommand for any contained windows are invoked. This command must at the very least clear the window and destroy it - which is the default action for a -windowcommand.

Example

This section contains an example which illustrates the main GRIDPLUS container command mode features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout, Button, Entry, and Radiobutton pages. Information given on those pages will not be duplicated here.

Note: The example assumes that the GRIDPLUS package has already been "required" and the commands imported.


Container Example 1

Window:

Selecting the "Win2" radiobutton displays the following window:-

Source Code:

#=========================================#
# Procedure create and display "Window 1" #
#=========================================#
proc display_win1 {} {

if {! [gridplus window .win1 -in .mycont]} {return}

gridplus entry .win1.entry -relief raised {
   {"Entry One " .one} {"Entry Three " .three}
   {"Entry Two " .two} {}
}

gridplus layout .win1.main {
   .win1.entry:nsew
}

pack .win1.main -expand 1 -fill both

}

#=========================================#
# Procedure create and display "Window 2" #
#=========================================#
proc display_win2 {} {

if {! [gridplus window .win2 -in .mycont]} {return}

gridplus radiobutton .win2.radiobutton -relief raised -attach w {
   {"Radio One " .one +one}
   {"Radio Two " .two -two}
}

gridplus layout .win2.main {
   .win2.radiobutton:nsew
}

pack .win2.main -expand 1 -fill both

}

#===================================================#
# Procedure to clear the contents of the container. #
#===================================================#
proc action,clear {} {
   gridplus clear .mycont
}

#============================================#
# Procedure to exit the example application. #
#============================================#
proc action,exit {} {
   gridplus clear .
   exit
}

#================================================#
# Create and display "Container Example" window. #
#================================================#
gridplus radiobutton .select {
   {"Win1" .win1 +one ~display_win1} {"Win2" .win2 -two ~display_win2}
}

gridplus container .mycont -height 150 -width 350 -title "Container" -sticky new

gridplus button .action {
   {"Clear" .clear} {"Exit" .exit}
}

gridplus layout .main -wtitle "Container Example" {
   .select
   =
   .mycont
   =
   .action:ew
}

pack .main

Comments:

#=========================================#
# Procedure create and display "Window 1" #
#=========================================#

proc display_win1 {} {

Creates a procedure called "display_win1".
if {! [gridplus window .win1 -in .mycont]} {return}

Creates a toplevel window called ".win1". The -in option is set to put the window into the ".mycont" container.

The "gridplus window" command returns "1" if the window already exists, otherwise it returns "0". The "if" check in this example skips the rest of this procedure if the window already exists.

Note: If there is already another window in the specified container the -windowcommand for that window is invoked. It is assumed that this will at a minimum clear the window and then destroy it. The "new" window is then put into the container.

The default for the -windowcommand option is to clear the window ("gridplus clear .win1") and then destroy it ("destroy .win1").

gridplus entry .win1.entry -relief raised {
   {"Entry One " .one} {"Entry Three " .three}
   {"Entry Two " .two} {}
}

Creates a GRIDPLUS entry Grid in the ".win1" toplevel window.

Note: The GRIDPLUS Grid/Layout names are prefixed with the name of the toplevel window.

gridplus layout .win1.main {
   .win1.entry:nsew
}

pack .win1.main -expand 1 -fill both

Arranges and displays the contents of ".win1" in the container.

Note: It is recommended that the contents of the "gridplus layout" have a "nsew" sticky indicator -and- the "pack" has the "-expand 1 -fill both" options. This allows the GRIDPLUS container -sticky option to control the positioning of the container contents. This may not always be the best method, but it is a good starting point.

#=========================================#
# Procedure create and display "Window 2" #
#=========================================#

proc display_win2 {} {

Creates a procedure called "display_win2".
if {! [gridplus window .win2 -in .mycont]} {return}

Creates a toplevel window called ".win2". The -in option is set to put the window into the ".mycont" container.

The "gridplus window" command returns "1" if the window already exists, otherwise it returns "0". The "if" check in this example skips the rest of this procedure if the window already exists.

Note: If there is already another window in the specified container the -windowcommand for that window is invoked. It is assumed that this will at a minimum clear the window and then destroy it. The "new" window is then put into the container.

The default for the -windowcommand option is to clear the window ("gridplus clear .win2") and then destroy it ("destroy .win2").

gridplus radiobutton .win2.radiobutton -relief raised -attach w {
   {"Radio One " .one +one}
   {"Radio Two " .two -two}
}

Creates a GRIDPLUS radiobutton Grid in the ".win2" toplevel window. As there is only one column of widgets in the ".win2.radiobutton" grid, the "-attach w" option cause the radiobutton widgets to be left (west) justified.

Note: The GRIDPLUS Grid/Layout names are prefixed with the name of the toplevel window.

gridplus layout .win2.main {
   .win2.radiobutton:nsew
}

pack .win2.main -expand 1 -fill both

Arranges and displays the contents of ".win2" in the container.

Note: It is recommended that the contents of the "gridplus layout" have a "nsew" sticky indicator -and- the "pack" has the "-expand 1 -fill both" options. This allows the GRIDPLUS container -sticky option to control the positioning of the container contents. This may not always be the best method, but it is a good starting point.

#===================================================#
# Procedure to clear the contents of the container. #
#===================================================#
proc action,clear {} {
   gridplus clear .mycont
}

Creates a procedure called "action,clear" to clear the contents of the ".mycont" container. This procedure is invoked when the "Clear" button is pressed.

Note: When "gridplus clear" is used to clear a container the -windowcommand of the window in the container is invoked. It is assumed that this will at a minimum clear the window and then destroy it.

#============================================#
# Procedure to exit the example application. #
#============================================#
proc action,exit {} {
   gridplus clear .
   exit
}

Creates a procedure called "action,exit" to clear the main window and exit the example application.
#================================================#
# Create and display "Container Example" window. #
#================================================#
gridplus radiobutton .select {
   {"Win1" .win1 +one ~display_win1} {"Win2" .win2 -two ~display_win2}
}

This section of the script creates and displays the example application window.

Creates a GRIDPLUS radiobutton Grid called ".select". Two buttons are created, "Win1" and "Win2". These buttons invoke the "display_win1" and "display_win2" procedures respectively. The "Win1" button is selected when the grid is created.

gridplus container .mycont -height 150 -width 350 -title "Container" -sticky new

Creates a GRIDPLUS container called ".mycont". The container has a height of "150" and a width of "350" units (Pixels).

By default, when the -title option is specified, the container will be surrounded by a labelled border of a style defined by the current theme.

The "-sticky new" option causes the container content to be anchored to the top, left and right.

gridplus layout .main -wtitle "Container Example" {
   .select
   =
   .mycont
   =
   .action:ew
}

pack .main

Lays out and displays the example application window.


Copyright © 2007 Adrian Davis.