GRIDPLUS2 - Window
Home Reference Manpage Examples Download License Contact

GRIDPLUS Toplevel Windows

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS window command mode. This can be used to create both normal and modal toplevel windows.

The window command mode can also be used to create and put windows into container within another window.

Example

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

The following example assumes that the reader is familiar with the contents of the Grid/Layout and Widget pages. Information given on that page will not be duplicated here.

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


Window Example

Window:

When the "Display Child Window" button is pressed the following toplevel (child) window is also displayed:-

Note: If the "Child Window/Modal?/Yes" radiobutton is selected a modal toplevel window is created.

Source Code:

#======================#
# Display Child Window #
#======================#

proc action,display_child {} {
   global {}

   if {! [gridplus window .child -modal $(.modal) -windowcommand child:action,close]} {
      return
   }

   gridplus grid .child.text -padding 30 -relief theme {
      {"^This Is The Child Window"}
   }

   gridplus entry .child.data -size 20 {
      {"Field One " .field1}
      {"Field Two " .field2}
   }

   gridplus button .child.action {
      {"Close Child Window" .close 25}
   }

   gridplus layout .child.main -wtitle "Child Window" {
      .child.text
      .child.data:c
      .child.action:c
   }

   pack .child.main
}

#====================#
# Close Child Window #
#====================#

proc child:action,close {} {

   gridplus clear .child

   destroy .child
}

#==============================#
# Display Main (Parent) Window #
#==============================#

gridplus grid .text -padding 30 -relief theme {
   {"^This Is The Parent Window"}
}

gridplus button .action {
   {"Display Child Window" .display_child 25}
}

gridplus radiobutton .modal -title "Child Window" {
   {"^Modal?"} {.no "No" +0} {.yes "Yes" -1}
}

gridplus layout .main -wtitle "Parent Window" {
   .text
   .modal:c
   .action:c
}

pack .main

Comments:

#======================#
# Display Child Window #
#======================#

proc action,display_child {} {
   global {}

Creates a procedure called "action,display_child" and makes the null array global.
if {! [gridplus window .child -modal $(.modal) -windowcommand child:action,close]} {
      return
   }

Creates a toplevel window called ".child". The -modal option is set to the value of the ".modal" radio button in the root (parent) window.

The procedure named in the -windowcommand option is executed when the child window receives a "WM_DELETE_WINDOW" event, which occurs when the window is closed.

The default for the -windowcommand option is to clear the window ("gridplus clear .child") and then destroy it ("destroy .child"). Obviously in the case of this example the -windowcommand option is not actually required but has been included as an example of the usage. It is strongly recommended that when this option be used that it references a procedure which calls "gridplus clear" for the toplevel window. This will ensure that the necessary housekeeping (clearing values in the null array etc.) are performed.

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 the window already exists the -windowcommand option is still actioned. This allows this command to set a windowcommand procedure for the root (parent) window.

Example: gridplus window . -windowcommand myproc

   gridplus grid .child.text -padding 30 -relief groove {
      {"^This Is The Child Window"}
   }

   gridplus entry .child.data -size 20 {
      {"Field One " .field1}
      {"Field Two " .field2}
   }

   gridplus button .child.action {
      {"Close Child Window" .close 25}
   }

   gridplus layout .child.main -wtitle "Child Window" {
      .child.text
      .child.data:c
      .child.action:c
   }

   pack .child.main
}

Creates and arranges some GRIDPLUS widget Grids in the ".child" toplevel window.

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

The values of the two entry fields will be in the null array as ".child.data,field1" and ".child.data,field2" respectively.

#====================#
# Close Child Window #
#====================#

proc child:action,close {} {

   gridplus clear .child

   destroy .child
}

Creates a procedure called "child:action,close". This procedure is called when either the "Close Child Window" button is pressed -or- when the "Child Window" is closed using window manager options, such as the "X" button at the top right of the window (Microsoft Windows).

This procedure uses the clear command mode to make sure that all references to the ".child" window are cleared from GRIDPLUS.

#==============================#
# Display Root (Parent) Window #
#==============================#

gridplus grid .text -padding 30 -relief groove {
   {"^This Is The Parent Window"}
}

gridplus button .action {
   {"Display Child Window" .display_child 25}
}

gridplus radiobutton .modal -title "Child Window" {
   {"^Modal?"} {.no "No" +0} {.yes "Yes" -1}
}

gridplus layout .main -wtitle "Parent Window" {
   .text
   .modal:c
   .action:c
}

pack .main

Creates and arranges some GRIDPLUS widget Grids in the root (parent) window.


Copyright © 2010 Adrian Davis.