GRIDPLUS2 - Variable and Command Substitution in Grid/Layout and Notebook
Home Reference Manpage Examples Download License Contact

GRIDPLUS Variable Substitution in Grid/Layout and Notebook

It is possible to refer to elements in the global null named array inside a Grid/Layout and notebook.

Normally variables inside braces are not expanded. GRIDPLUS will, by default, perform variable substitution (using the Tcl subst command) for the layout parameter of the Grid, Layout and Notebook GRIDPLUS command modes. This can make the code tidier and easier to read.

The gpset command can be used to set the values to be substituted.

Example:-

gpset WIN win1 

gridplus window .$(WIN) 

combobox .$(WIN).title -editable 0 -width 4 -textvariable (.$(WIN).title)  
eval     .$(WIN).title list insert end [list Mr Mrs Miss Ms] 

gridplus entry .$(WIN).employee -size 8 -title Employee {  
   {ID     .id +}  
   {Title  @$(WIN).title} 
   {Name   .name 25}  
   {Age    .age 3}  
   {Salary .salary}  
}  

gridplus button .$(WIN).buttons {  
   {Find .find} {Exit .exit} 
} 

gridplus layout .$(WIN).main -title "Test - $(WIN)" {  
   .$(WIN).employee 
   .$(WIN).buttons:ew 
}  

pack .$(WIN).main 

This example creates a toplevel window called "win1" with some entry fields, a combobox and a couple of buttons. The name of the toplevel window is set (using "gpset WIN win1") in the null named array element "WIN". Subsequently this variable is used when a reference to the toplevel window is required.

GRIDPLUS Command Substitution in Grid/Layout and Notebook

In addition to variable substitution GRIDPLUS can also, optionally, perform command subsitution.

There are four option database options which control this function:-

Option Database NameDefaultOverrides *Gridplus.substCommand
*Gridplus.substCommand0N/A
*Gridplus.substCommandGrid*Gridplus.substCommandYes
*Gridplus.substCommandLayout*Gridplus.substCommandYes
*Gridplus.substCommandNotebook*Gridplus.substCommandYes

For Example:

gpoptions substCommand 1
...Enables command substitution for Grid/Layout and Notebook.

  
gpoptions substCommandNotebook 1
...Enables command substitution for Notebook only.


 gpoptions {
   substCommandLayout   1
   substCommandNotebook 1
} 
...Enables command substitution for Layout and Notebook only.

  
gpoptions {
   substCommand     1
   substCommandGrid 0
}
...Also enables command substitution for Layout and Notebook only.


Window:

Source Code:

#----------------------------------------------------------------#
# Procedure to create notebook pane content.                     #
#----------------------------------------------------------------#
  
proc myFind {} {
   gridplus checkbutton .match -padding 0 {
      {.word "Match whole word only"}
      {.case "Match case"}
   }

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

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

  #-----------------------------------------------
  # NOTE: Return name of item for notebook page...
  
   return .action
}

#-----------------------------#
# Enable command substitution #
#-----------------------------#

gpoptions substCommand 1

#---------------------------------------#
# Create notebook using above procedure #
#---------------------------------------#

gridplus notebook .mynotebook { 
   "Find" [myFind] 
}

pack .mynotebook
Comments:

In this example, a procedure ("myFind") based on Example 3 is to be used to populate the content of a Notebook page.

Disabling Variable and Command Substitution in Grid/Layout and Notebook

Variable substitution can be disabled either globally, by using the option database...

option add *Gridplus.subst 0

...using gpoptions...

gpoptions subst 0

...or for a specific command, by using the -subst option.


Copyright © 2013 Adrian Davis.