GRIDPLUS2 - Radiobutton Grid
Home Reference Manpage Examples Download License Contact

GRIDPLUS Radiobutton Grid

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS radiobutton command mode. This command mode is a "short cut" method to invoke the GRIDPLUS widget command mode with the default widget set create radiobuttons. All of the normal widget command mode functionality can be used. For example creating other widget types.

This uses a simple syntax to create a grid of radiobuttons. The syntax is closely based on the GRIDPLUS Grid and Widget.

GRIDPLUS Radiobutton Specific Item Options/Functionality

+value
Specifies that the radiobutton should be created in selected mode. The value when selected is value.

-value
Specifies that the radiobutton should be created in deselected mode. The value when selected is value.

~command
Specifies that a command is invoked when the radiobutton is selected. The command name is optional. If not specified command name is based on the name of the radiobutton.

*groupname
Specifies that the radiobutton widget belongs to a group called groupname.
(See Radiobutton Example 2 and Reading and Setting GRIDPLUS Radiobutton Values.)

Invoking Commands When a Radiobutton is Selected

There are two ways to specify commands to be invoked when a radiobutton is selected:-

  1. Specifying the -radiobuttoncommand (Alias -rcmd) option when creating a widget grid containing radiobuttons. This option invokes the specified command for all radiobuttons in the grid.
  2. Specifying commands for specific radiobuttons by using the ~command widget option.

Notes:

Example

This section contains an example which illustrates the main GRIDPLUS radiobutton 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 those pages will not be duplicated here.

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


Radiobutton Example 1

Window:

Source Code:

gridplus radiobutton .mygrid1 -title "My Grid 1" {
  {"Label1" . +myval1} {"Label2" . -myval2} {"Label3" . -myval3}
  {"Label4" . -myval4} {"Label5" . -myval5} {"Label6" . -myval6}
  {"Label7" . -myval7} {"Label8" . -myval8} {"Label9" . -myval9}
}


gridplus radiobutton .mygrid2 -title "My Grid 2" {
  {. "Option1" +myval1}
  {. "Option2" -myval2}
  {. "Option3" -myval3}
  {. "Option4" -myval4}
}

gridplus radiobutton .mygrid3 -title "My Grid 3" {
  {}         {"Label A"}    {"Label B"}
  {"Label1"} {.:c +myval1A} {.:c -myval1B}
  {"Label2"} {.:c -myval2A} {.:c -myval2B}
  {"Label3"} {.:c -myval3A} {.:c -myval3B}
  {"Label4"} {.:c -myval4A} {.:c -myval4B}
}

gridplus layout .main -wtitle "Radiobutton Example" {
   .mygrid1:ew  -
   .mygrid2:ns  .mygrid3:ew
}

pack .main

Comments:

When using the GRIDPLUS radiobutton command mode the "label" defines the text that will appear as a label to the associated radiobutton. Although it is possible to specify the names for each of the radiobutton widgets, knowing the names is not (generally) useful. It is recommended that a dot only (".") be used to specify the position of the widget relative to the text label. When a widget is not given a name GRIDPLUS will generate one automatically (based on the name of the grid).

The cell definition must also specify the value the radiobutton group will have when the associated radiobutton is "selected". A string with a "+" (Selected) or "-" (Deselected) prefix is used to indicate the value. If more than one "selected" value is specified for a radiobutton group the last one will take effect.

In ".mygrid2" the widget IDs are to the left of the label text. This will create radiobuttons which are to the left of the label text.

In ".mygrid3" each cell definition contains only a widget ID or label text. In this example a "matrix" of radiobuttons is created, each row and each column has one label. A "null" cell definition is used to create an empty cell in the top left of the Grid. The widget IDs have a :c suffix - This causes the radiobuttons to be centred in the containing cell.


Radiobutton Example 2

Window:

Source Code:

gridplus radiobutton .mygrid -wtitle "Group Example" {
  {"Default1" . +default1} {"GroupA1" . +groupa1 *groupa} {"GroupB1" . +groupb1 *groupb}
  {"Default2" . -default2} {"GroupA2" . -groupa2 *groupa} {"GroupB2" . -groupb2 *groupb}
  {"Default3" . -default3} {"GroupA3" . -groupa3 *groupa} {"GroupB3" . -groupb3 *groupb}
}

pack .mygrid

Comments:

Creates three radiobutton groups:-

"Default1", "Default2" and "Default3" belong to the default group. The value for these is accessed as "$(.mygrid)".

"GroupA1", "GroupA2" and "GroupA3" belong to the "groupa" group. The value for these is accessed as "$(.mygrid,groupa)".

"GroupB1", "GroupB2" and "GroupB3" belong to the "groupb" group. The value for these is accessed as "$(.mygrid,groupb)".

Reading and Setting GRIDPLUS Radiobutton Values

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

For Example:

global {}

For GRIDPLUS radiobutton widgets in the default group the array element has the same name as the radiobutton Grid: Thus the value of the ".mygrid1" radiobutton group is referenced as "$(.mygrid1)".

For radiobutton widgets that are part of a specified group the array element name is based on a combination of the name of the radiobutton Grid and the name of the group: Thus the value of a ".mygrid2" grid radiobutton in a group called "mygroup" is referenced as "$(.mygrid2,mygroup)".

The value will be that specified for the currently selected radiobutton. If no button is selected the value will be null.

The recommended method to set GRIDPLUS radiobutton values is to use the gpset command.

For Example:

gpset .mygrid1 myval2

...or...

gpset .mygrid2,mygroup myval3


Copyright © 2009 Adrian Davis.