GRIDPLUS - Example 1
Home Reference Manpage Examples Download License Contact

A Simple Example

Window:


Source Code:

package require gridplus 1.0
namespace import gridplus::*

gridplus entry .employee -size 8 -state disabled -title Employee { 
   {ID     .id + >} 
   {Name   .name 25} 
   {Age    .age 3} 
   {Salary .salary} 
} 

gridplus button .buttons { 
   {Find .find} {Exit .exit}
} 

gridplus layout .main -title "Test Application" { 
   .employee
   .buttons:ew
} 

pack .main 


Comments:

package require gridplus 1.0
namespace import gridplus::*
Loads the GRIDPLUS package and imports the commands.
gridplus entry .employee -size 8 -state disabled -title Employee { 
   {ID     .id + >} 
   {Name   .name 25} 
   {Age    .age 3} 
   {Salary .salary} 
} 

Creates a grid of GRIDPLUS entry widgets named ".employee". The default for entry size is set to "8" characters and state to "disabled". The title of the group is set to "Employee". By default, when the title option is specified, a groove style border is also added.

Four entry widgets are created: Generally for GRIDPLUS entry the first two items of each entry detail are the label text and the widget Identifier. The rest of the items are for options specific to the entry.

For Example: "{ID .id + >}".

"ID" is the label text to be associated with an entry with Identifier ".id". The entry widget is actually created with the name ".employee,id". The item begining with a dot (".") is considered to be the entry Identifier. In this case the leftmost item is the label and the next the Identifier. This causes the label to be to the left of the associated entry. If the items were reversed the label would be to the right of the entry. The "+" option gives this entry focus. The ">" option overrides the "disabled" default and forces the entry to be created with a normal state.

The number options "25" and "3" for widgets ".name" and ".age", override the default size and sets these entries to have a sizes of 25 and 3 characters respectively.

The layout of the entry widgets in the window matches the layout of the entry details in the code. In this case they are one above the other (vertical) and will appear in the window accordingly as a single column.

gridplus button .buttons { 
   {Find .find} {Exit .exit}
}

Creates a grid of GRIDPLUS button widgets named ".buttons. The default width for a button is 8 characters.

Two button widgets are created: Generally for GRIDPLUS button the first two items of each button detail are the button text and the widget Identifier. The rest of the items are for options specific to the button.

For Example: "{Find .find}".

"Find" is the text to be displayed on a button with with Identifier ".find". The button widget is actually created with the name ".buttons,find".

Note: Widget Identifiers can contain the following characters "A-Z", "a-z", "0-9" or "_".

The layout of the button widgets in the window matches the layout of the button details in the code. In this case they are one next to the other (horizontal) and will appear in the window accordingly as a single row.

When the button is activated a procedure called "buttons,find" will be invoked.

gridplus layout .main -title "Test Application" { 
   .employee
   .buttons:ew
} 
Layout the previously created GRIDPLUS widgets in a Layout called ".main". As with GRIDPLUS grids the title option would normally add a titled border around its contents, but if the name of the Layout ends width ".main" the title option sets the window title instead.

The ":ew" suffix on ".buttons:ew" causes the space between the widgets in the ".buttons" Grid to stretch in an east/west (horizontal) direction to match the width of the ".employee" Grid.

The layout of the Grids in the window matches the layout of the Grid details in the code. In this case they are one above the other (vertical) and will appear in the window accordingly.

pack .main
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 ".name" in the ".employee" Grid is referenced as "$(.employee,name)".

The values of most GRIDPLUS widgets can be set simply by using the TCL "set" command.

For Example:

set (.employee,name) "Mary Jones"

However GRIDPLUS provides a "gpset" command. This can be used to set single or multiple widget values and is the supported method to set GRIDPLUS text and tablelist widget values.

For Example:

gpset .employee,name "Mary Jones"

...or...

gpset {
   .employee,name "Mary Jones"
   .employee,age  35
}


Copyright © 2004
Adrian Davis.