GRIDPLUS2 - Example 3
Home Reference Manpage Examples Download License Contact

An Example Using a Toplevel Window

This example uses a toplevel window to create a "Find" dialog box similar to that of Internet Explorer.

Window:


Source Code:

package require gridplus 2.10
namespace import gridplus::*

gridplus window .find -wtitle Find

gridplus checkbutton .find.match -padding 0 {
   {.word "Match whole word only"}
   {.case "Match case"}
}

gridplus radiobutton .find.direction -title Direction {
   {. Up -up} {. Down +down}
}

gridplus button .find.action {
   {&e "Find What: " .string 38 + >next} {"Find Next" .next < %next}
   {@find.match |> @find.direction}      {"Cancel" .cancel}
}

pack .find.action


Comments:

package require gridplus 2.10
namespace import gridplus::*
Loads the GRIDPLUS package and imports the commands.
gridplus window .find -wtitle Find

Creates a toplevel window called ".find". The "-wtitle Find" option sets the title of the window to be "Find".

Note: For toplevel windows it is important to make sure that the appropriate tidy-up actions are taken if the window is closed using window manager facilites - For example: pressing the "X" button on the title bar. The -windowcommand can be used for this purpose. The minimum requirement is to call "gridplus clear" specifying the toplevel window, followed by Tk destroy command. As this is the default action it is not neccessary to use -windowcommand for this particular example.

gridplus checkbutton .find.match -padding 0 {
   {.word "Match whole word only"}
   {.case "Match case"}
}

Creates a GRIDPLUS with two checkbuttons. The checkbuttons are one above the other, as this is the order in which they are specified.

"Match case" is the label text to be associated with the checkbutton with Identifier ".case". The checkbutton widget is actually created with the name ".find.match,case". The item begining with a dot (".") is considered to be the checkbutton Identifier. In this case the rightmost item is the label and the next the Identifier. This causes the label to be to the right of the associated checkbutton. If the items were reversed the label would be to the right of the checkbutton. The value of the checkbutton can be accessed as "$(.find.match,case)".

gridplus radiobutton .find.direction -title Direction {
   {. Up -up} {. Down +down}
}

Creates a GRIDPLUS with two associated radiobuttons. The radiobuttons are to the left of the labels and one next to the other, as this is the order in which they are specified.

The "-title Direction" option creates a "theme" style border around the radiobuttons with the title "Direction".

"Down" is the label text to be associated with the radiobutton with Identifier ".". In this case the rightmost item is the label and the next the Identifier. This causes the label to be to the right of the associated radiobutton. If the items were reversed the label would be to the right of the radiobutton. The value of the radiobuttons can be accessed as "$(.find.direction)".

The item begining "+" specifies the value ("down") of the radiobutton group when this button ("Down") is selected. The "+" also indicates that this button will be selected when the group/grid is created. To create the button which is not selected when created the value must be prefixed with "-" (For example: "-up").

gridplus button .find.action {
   {&e "Find What: " .string 38 + >next} {"Find Next" .next < %next}
   {@find.match |> @find.direction}      {"Cancel" .cancel}
}

Creates a grid of GRIDPLUS button widgets named ".find.action".

The "&e" in "{&e "Find What: " .string 38 + >next}" overrides the default widget type (button) to create an entry with Identifier ".string" which is "38" characters wide. The "+" specifies that this widget gets keyboeard focus. ">next" will set the widgets which belong to group "next" to normal/enabled when the contents of the widget are updated. In this case the "Find Next" button will be enabled when something is typed into the entry widget.

Two buttons are created; "Find Next" width Identifier ".next" and "Cancel" with Identifier ".cancel". The "Find Next" button is created as disabled ("<") and is assigned to the "next" group ("%next"). This button will be enabled when data is entered into the ".string" widget. The command invoked when this button is pressed is "find:action,next".

The "{@find.match |> @find.direction}" creates an Embedded Widget Grid This widget grid has the "find.match" and "find.direction" grids embedded. Embedding this grids into another grid allows them to have a different column layout than the other widgets in the "find.action" grid.

pack .find.action
Displays the window contents.

Setting and Reading GRIDPLUS Widget Values

The values of the GRIDPLUS widgets are stored in a global array with a null name.

For Example:

global {}

For GRIDPLUS entry and checkbutton widgets the array element has the same name as the widget: Thus the value of ".word" in the ".find.match" Grid is referenced as "$(.find.match,word)".

For GRIDPLUS radiobuttons the array element has the same name as the radiobutton grid: Thus the value of ".find.direction" radiobuttons is referenced as "$(.find.direction)".


Copyright © 2013 Adrian Davis.