GRIDPLUS2 - Define
Home Reference Manpage Examples Download License Contact

GRIDPLUS Widget Definitions

The GRIDPLUS define command provides a facility to allow GRIDPLUS widget grid widgets to be defined separately from the widget grids.

For example: From a code maintenance point of view, it would be possible to define all of an applications widgets in one place using a single define command. In addition, it can make code more readable.

Use of the define command is entirely optional. It is simply a matter of preferred coding style whether or not this facility should be used.

Command Syntax

gridplus define {name definition ... ...}

For Example:

gridplus define {
   myentry  {&e "My Entry" .myentry}
   mybutton {&b "My Button" .mybutton}
}

Creates two widget definitions named "myentry" and "mybutton". The definitions of the widgets is exactly how the widget would normally be specified in a widget grid.

To use the defined widgets in a widget grid the name of the defined widget is prefixed with "@". This is the same syntax used to insert another widget/grid/layout. If a widget/grid/layout with the specified name exists, then this will be inserted, otherwise it is assumed to be the name of a "defined" widget.

For example:

gridplus widget .mywidgets {
   @mentry
   @mybutton
}

If "myentry" and "mybutton" are defined as above, then this is equivalent to:-

gridplus widget .mywidgets {
   {&e "My Entry" .myentry}
   {&b "My Button" .mybutton}
}

The defined widget can also accept parameters. These use percent (%) substitutions named "%1, %2, %3 ... %9" (See the example below).

The parameters may be used either in subsequent widget definitions -or- in a GRIDPLUS widget grid item.

Example

This section contains an example which illustrates the GRIDPLUS widget definition facility.

The following example assumes that the reader is familiar with the contents of the Grid/Layout, Button, Dropdown, and Entry 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.


Define Example

Window:

Source Code:

gridplus define {
   test1 {&b .button1 "Mybutton"}
   test2 {&e "%1" .%2 25/25}
   test3 {@test2 "Entry Two" entry2}

   # {=================ADDRESS=====================}

   building {&e "Building Number/Name" .building 30}
   street   {&e "Street Name"          .street 30}
   city     {&e "City/Town"            .city 30}
   state    {&d "State"                .state 3
             "+AL AK AS AZ AR CA CO CT DE DC FM FL
               GA GU HI ID IL IN IA KS KY LA ME MH
               MD MA MI MN MS MO MT NE NV NH NJ NM
               NY NC ND MP OH OK OR PW PA PR RI SC
               SD TN TX UT VT VI VA WA WV WI WY"}
   zip      {&e "Zip"                  .zip 8}
}

gridplus widget .mygrid -title "MyGrid" {
   {@test1}
   {@test2 "Entry One" entry1}
   {@test3}
}

gridplus widget .home -title "Home Address" {
  @building
  @street
  @city
  @state
  @zip
}

gridplus widget .delivery -title "Delivery Address" {
  @building
  @street
  @city
  @state
  @zip
}

gridplus layout .addresses -wtitle "Define Example" {
   .mygrid
   .home
   .delivery
}

pack .addresses

Comments:

gridplus define {
   test1 {&b .button1 "Mybutton"}
   test2 {&e "%1" .%2 25/25}
   test3 {@test2 "Entry Two" entry2}

   # {=================ADDRESS=====================}

   building {&e "Building Number/Name" .building 30}
   street   {&e "Street Name"          .street 30}
   city     {&e "City/Town"            .city 30}
   state    {&d "State"                .state 3
             "+AL AK AS AZ AR CA CO CT DE DC FM FL
               GA GU HI ID IL IN IA KS KY LA ME MH
               MD MA MI MN MS MO MT NE NV NH NJ NM
               NY NC ND MP OH OK OR PW PA PR RI SC
               SD TN TX UT VT VI VA WA WV WI WY"}
   zip      {&e "Zip"                  .zip 8}
}

Creates the following widget definitions:-

test1- A button called ".button1" with label text "Mybutton".
test2- An entry with its name defined by parameter "%2", 25 characters width, allowing a maximum of 25 characters with label text defined by parameter "%1".
test3- An entry using the "test2" definition (defined above) with two parameters: "Entry Two as %1 and "entry2" as %2.
#- This is the recommended method to insert comments into a definition. The comment text should be enclosed in braces.
building- An entry called ".building", 30 characters in size with label text "Building Number/Name".
street- An entry called ".street", 30 characters in size with label text "Street Name".
city- An entry called ".city", 30 characters in size with label text "City/Town".
state- A dropdown (combobox) called ".state", 3 characters in size with label text "State". The dropdown list options are set to a list of US state codes.
zip- An entry called ".zip", 8 characters in size with label text "Zip".

gridplus widget .mygrid -title "MyGrid" {
   {@test1}
   {@test2 "Entry One" entry1}
   {@test3}
}

Creates a widget grid named ".mygrid" width title "MyGrid".

This widget grid uses three defined widgets; "test1", "test2" and "test3".

{test1} is replaced with {&b .button1 "Mybutton"}

{test2 "Entry One" entry1} has two percent subsitution parameters. "%1" becomes "Entry One" and "%2" becomes "entry1". The final replacement is {&e "Entry One" .entry1 25/25}. This demonstrates how the parameters can be used in a GRIDPLUS widget grid item.

{test3} is replaced with {&e "Entry Two" .entry2 25/25}.

gridplus widget .home -title "Home Address" {
  @building
  @street
  @city
  @state
  @zip
}

Creates a widget grid named ".home" width title "Home Address".

Using the widget definitions created above this is equivqlent to:-

gridplus widget .home -title "Home Address" {
   {&e "Building Number/Name" .building 30}
   {&e "Street Name"          .street 30}
   {&e "City/Town"            .city 30}
   {&d "State"                .state 3
      AL AK AS AZ AR CA CO CT DE DC FM FL
      GA GU HI ID IL IN IA KS KY LA ME MH
      MD MA MI MN MS MO MT NE NV NH NJ NM
      NY NC ND MP OH OK OR PW PA PR RI SC
      SD TN TX UT VT VI VA WA WV WI WY"}
   {&e "Zip"                  .zip 8}
}

gridplus widget .delivery -title "Delivery Address" {
  @building
  @street
  @city
  @state
  @zip
}

Creates a widget grid named ".delivery" width title "Delivery Address".

Using the widget definitions created above this is equivqlent to:-

gridplus widget .delivery -title "Delivery Address" {
   {&e "Building Number/Name" .building 30}
   {&e "Street Name"          .street 30}
   {&e "City/Town"            .city 30}
   {&d "State"                .state 3
      AL AK AS AZ AR CA CO CT DE DC FM FL
      GA GU HI ID IL IN IA KS KY LA ME MH
      MD MA MI MN MS MO MT NE NV NH NJ NM
      NY NC ND MP OH OK OR PW PA PR RI SC
      SD TN TX UT VT VI VA WA WV WI WY"}
   {&e "Zip"                  .zip 8}
}


Copyright © 2009 Adrian Davis.