GRIDPLUS2 - Container | ![]() |
||||||
|
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.
Window:
Selecting the "Win2" radiobutton displays the following window:-
Source Code:
Comments:
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").
Note: The GRIDPLUS Grid/Layout names are prefixed with the name of the toplevel window.
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.
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").
Note: The GRIDPLUS Grid/Layout names are prefixed with the name of the toplevel window.
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.
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.
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.
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.
Container Example 1
#=========================================#
# 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
#=========================================#
# 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 layout .main -wtitle "Container Example" {
.select
=
.mycont
=
.action:ew
}
pack .main
Copyright © 2007 Adrian Davis.