UI command templates

 
 
 

Command templates are a means of specifying default parameters for ELF commands. They are intended to support a consistent appearance in an application’s user interface. By specifying default arguments for text alignments, border styles, indentations, etc. an application will have a more coherent appearance. The look of the application can be modified in one place by modifying the default arguments in the command templates.

A single template can hold the defaults for any number of ELF commands. Multiple templates can exist holding different sets of default parameters. During execution the default parameters are transparently added to the argument list for the commands that are part of the current template. Any parameters that are explicitly specified in the argument list will override the default parameters in the template. The defaults are only parsed once when the template is created, and thereafter are kept in the parsed state for later use.

To create a new empty command template the “uiTemplate” command is used. Each command can add its defaults to a template using the “-dt/defineTemplate” flag along with the specific template that it is specifying and the parameters that it wants to have as defaults. A template is made current with the “setUITemplate” command.

Each template is named and they can be pushed and popped to change the current template for a certain section of script. Typically a script writer will “push” their desired command template at the beginning of a procedure and “pop” it at the end of the procedure to restore whatever was the previous template. If no templates are desired then it is prudent to set the current template to “NONE” (the keyword for indicating no current templates). Whenever a new window is created the command template stack is cleared so pushing templates must be done after window creation to have an effect. Commands can also utilize any existing template without changing the current one by using the “-ut/useTemplate” flag.

Script 4. Command templates

// Create a new template object.
//
if (!`uiTemplate -exists TestTemplate`) {
 uiTemplate TestTemplate;
}
// Add the command default parameters to the template.
//
frameLayout -defineTemplate TestTemplate 
 -borderVisible true -labelVisible true -labelAlign "center"
 -marginWidth 5 -marginHeight 5;
button -defineTemplate TestTemplate -width 150 -label "Default Text";
// Now make a window.
//
window -title "Test Window" ExampleWindow4;
 // Make our template current
 //
 setUITemplate -pushTemplate TestTemplate;
 frameLayout -label "Buttons" TestFrameLayout;
 columnLayout TestColumnLayout;
 button;
 button -label "Not Default Text";
 button;
 // Restore previous, if any template to clean up.
 //
 setUITemplate -popTemplate;
showWindow ExampleWindow4;

This window shows the results of the script. Notice how the default parameters defined for the template were added to the subsequent commands. For example we added the label text “Default Text” as a default parameter for the button command, the first and third buttons had that parameter applied as a default without explicitly specifying it. However the second button overloaded the default argument by specifying its own argument for the label text flag, “Not Default Text”.

The default parameters for a command can be changed at any time by simply re-executing the command with the “-dt/defineTemplate” flag for the specified template. Try changing the button command’s default label string in the above template and then re-execute the window creation part of the above example.

button -defineTemplate TestTemplate -label "New Default Text";

To prevent accidental use of a template that is still active, the “window” command clears the current template when a window is created. Use the “setUITemplate” command after the “window” command or it will have no effect.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License