GRIDPLUS - 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.

Example

This section contains an example which illustrates the main GRIDPLUS Groups facility features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout page. 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) -deletewindow child:action,close]} {
      return
   }

   gridplus grid .child.text -pad 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 -title "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 -pad 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 -title "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) -deletewindow 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 -deletewindow option is executed when the child window receives a "WM_DELETE_WINDOW" event, which occurs when the window is closed. It is strongly recommended that this option be used, and 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 -deletewindow option is still actioned. This allows this command to set a deletewindow procedure for the root (parent) window.

Example: gridplus window . -deletewindow myproc

   gridplus grid .child.text -pad 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 -title "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 -pad 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 -title "Parent Window" {
   .text
   .modal:c
   .action:c
}

pack .main

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


Copyright © 2004 Adrian Davis.