GRIDPLUS - Text
Home Reference Manpage Examples Download License Contact

GRIDPLUS Text

In order to simplify creation of screens GRIDPLUS provides a GRIDPLUS text command mode. This uses a simple syntax to create a edit/read-only text box with optional scrollbars. The GRIDPLUS text box can have its contents set using the gpset command. The contents of the GRIDPLUS text box can be read, in the same manner as other GRIDPLUS widgets, from the "null" array.

By default an editable text widget is created. Setting the -tags 1 option makes the text widget read-only and activates "tag" processing mode. In this mode tags (similar to HTML) can be emedded in the text. The tags can be used to set attributes (font, font size, foreground/background colours, underline and bold), set text indenting, create links (To move the display to other parts of the text or to invoke TCL procedures), embed images or ICONS package icons (Which may also be links or invoke TCL procedures) - See Example 4 below.

When tags are enabled the value of the widget ("$(.mytext)" in Example 4) can have a number of different values:-

NOTE: The GRIDPLUS goto command mode can be also used to move a tag enabled text widget display to a specified label.

Example

This section contains examples which illustrate the main GRIDPLUS text command mode features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout page. Information given on that page will not be duplicated here.

Note: The examples assume that the GRIDPLUS package has already been "required" and the commands imported.


Text Example 1

Window:

Source Code:

gridplus text .mytext

gridplus layout .main -title "Text Example" {
   .mytext
}

pack .main

Comments:

This example creates a text box with a default size (40 characters wide, 10 lines deep). The -wrap option is set to "word" by default.


Text Example 2

Window:

Source Code:

gridplus text .mytext -width 25 -height 8 -scroll y -title "Text Box"

gridplus layout .main -title "Text Example" {
   .mytext
}

pack .main

Comments:

This example creates a text box with a width of "25" characters and a height of "8" lines. As with GRIDPLUS Grids/Layouts, the text box can have a border. In this case the -title "Text Box" option adds a labeled "groove" style border. Borders without titles are added using the -relief option (See Text Example 3).

The -scroll y option adds a "Y" direction (vertical) scollbar.


Text Example 3

Window:

Source Code:

gridplus text .mytext -width 50 -height 8 -relief groove -scroll xy

gridplus layout .main -title "Text Example" {
   .mytext
}

pack .main

Comments:

This example creates a text box with a width of "50" characters and a height of "8" lines. As with GRIDPLUS Grids/Layouts, the text box can have a border. In this case the -relief groove option adds a "groove" style border.

The -scroll xy option adds both "X" (horizontal) and "Y" direction (vertical) scollbars.


Text Example 4

Windows:

The images above show the same text box. The right-hand image shows the text scrolled to the end.

Source Code:

proc mytext,mycommand {} {
   global {}

   tk_messageBox -title "Command: mycommand" -message "The Parameter is: $(.mytext)"
}

gridplus text .mytext      \
   -scroll     y           \
   -height     42          \
   -width      65          \
   -tags       1           \
   -linkcolor  blue/maroon \
   -linkcursor hand2       \
   -linkstyle  underline

gridplus layout .main -title "Text With Tags" {
   .mytext
}

pack .main

gpset .mytext {<label top><size 15>Tagged Text Example</size>

This text is in the default size, in the default font (Helvetica)
<size 10:default>This text is in the new default size (10 point).

This is <b>bold text</b>.
This is <u>underlined text</u>.
This is <i>italic text</i>.
This is <b><u><i>bold/underlined/italic text</i></u></b>.
This is <color red>red text</color>.
This is <color blue><bgcolor lightgray>blue text on a lightgray background</bgcolor></color>.

<color white:default><bgcolor blue:default>With the default colors set to white on blue:-

This is <b>bold text</b>.
This is <u>underlined text</u>.
This is <i>italic text</i>.
This is <b><u><i>bold/underlined/italic text</i></u></b>.
This is <color red>red text</color>.
This is <color blue><bgcolor lightgray>blue text on a lightgray background</bgcolor></color>.

<color black:default><bgcolor white:default>
This is <size +4>larger text</size> (Default size +4).
This is <size -4>smaller text</size> (Default size -4).

This is <font courier>the courier font</font>.
This is <font times>the times font</font>.

<b>Special Caracters:-</b>

!b:<tab>Bullet.
!lt:<tab>Less than.
!gt:<tab>Greater than.
!ob:<tab>Open brace.
!cb:<tab>Close brace.
!bs:<tab>Backslash.

<b>Indented text</b><indent 6>This text is indented 6 positions. The rest of this paragraph\
exists simply to create enough text to allow the word-wrap to take effect.

The text will remain indented until the indent is switched off.</indent>

The text is now no longer indented.

This is a <link top>Link to the top of the text</link>. The target of the link is the\
<font courier>!lt:label top!gt:</font> tag at the begining of this text.

The color of the link is specified using the <font courier>-linkcolor</font> option, in this\
case <color blue>blue</color>/<color maroon>maroon</color>. The style of the link is set using the\
<font courier>-linkstyle</font> option, in this case <font courier>underline</font>. The cursor\
displayed when the mouse-pointer is over a link is set using the <font courier>-linkcursor</font>\
option, in this case <font courier>hand2</font>.

This is a command to <command mycommand>run the mytext,mycommand procedure</command> without an\
explict parameter set.

This is a command to <command mycommand:my_parameter1>run the mytext,mycommand procedure</command>\
with an explicitly defined parameter.

This <image :navhome16> is the <font courier>:navhome16</font> icon from the ICONS package.\
This <image :navup16@top> is another icon which will behave as a link to the top of\
this text. This <image :actrun16~mycommand:my_parameter2> icon will invoke the\
<font courier>mytext,mycommand</font> procedure.

}

Comments:

This example creates a read-only text box with tags processing enabled. Refer to the tags page for further details.

Reading and Setting GRIDPLUS Text Values

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

For Example:

global {}

For GRIDPLUS text widgets the array element has the same name as the widget frame: Thus the value of ".mytext" is referenced as "$(.mytext)".

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

For Example:

gpset .mytext "This is some text\nThis is another line"


Copyright © 2004 Adrian Davis.