text

Name

text -- A widget for multi line formatted text editing.

Synopsis

text [-option value...]

Screenshot

Options

-baseFont

type: FONT

Set default font for the text widget.

-baseColor

type: color

Set default color for the text widget.

-onButtonPress

type: string (default: "")

Tcl script which is executed if a mouse button is pressed inside the widget. Before evaluation the following percent strings are substituted: 
%w widget name
%t type of event, one of buttonPress, button2Press or button3Press
%x mouse pointer x coordinate
%y mouse pointer y coordinate
%b button number
%s state of buttons and modifiers (bitmask)
-onButtonRelease

type: string (default: "")

Tcl script which is executed if a mouse button is released inside the widget. Before evaluation the following percent strings are substituted: 
%w widget name
%t type of event, one of buttonPress, button2Press or button3Press
%x mouse pointer x coordinate
%y mouse pointer y coordinate
%b button number
%s state of buttons and modifiers (bitmask)

Note: In order to obtain update cursors position etc, use bindings on the ButtonReleas event.

-onKeyPress

type: string (default: "")

Tcl script which is executed if a mouse button is released inside the widget. Before evaluation the following percent strings are substituted: 
%w widget name
%t type of event, one of buttonPress, button2Predd or button3Press
%x mouse pointer x coordinate
%y mouse pointer y coordinate
%b button number
%s state of buttons and modifiers (bitmask)

-onKeyRelease

type: string (default: "")

Tcl script which is executed if a mouse button is released inside the widget. Before evaluation the following percent strings are substituted: 
%w widget name
%t type of event, one of buttonPress, button2Predd or button3Press
%x mouse pointer x coordinate
%y mouse pointer y coordinate
%b button number
%s state of buttons and modifiers (bitmask)

-onMotion

type: string (default: "")

Tcl script which is executed if the mouse pointer moves inside the widget. Before evaluation the following percent strings are substituated 

%w widget name
%x mouse pointer x coordinate
%y mouse pointer y coordinate
%s state of buttons and modifiers (bitmask)

-onShowHelp

type: string (default: "")

Tcl script which is executed in the global scope if the "show-help" signal is recieved, which is normally the case if the user presses F1 or Ctrl-F1. Before evaluation the following percent strings are substituated 

%w widget name
%h help type: either "whatsThis" or "tooltip"

-onApplyTag

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%t name of tag applied
%c column from which the tag was applied
%r row from which the tag was applied
%l line to which the tag was applied
%o offset to which the tag was applied
 
-onBeginUserAction

type: string (default: "")

Tcl script which is executed when the buffer signals that user input has begun. Before evaluation the following percent strings are substituated 

%b value =1. As this event occurs only when user action is begun, it always returns the value 1.

See Also:  -onEndUserAction

-onDeleteRange

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%r row from which the text was deleted
%c column from which the text was deleted
%l line to which the text was deleted
%o offset to which the text was deleted
%t deleted text
-onEndUserAction

type: string (default: "")

Tcl script which is executed when the buffer signals that user input has ended. Before evaluation the following percent strings are substituated 

%e value =1. As this event occurs only when user action ends, it always returns the value 1.

See Also:  -onBeginUserAction

-onInsertChildAnchor

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%a anchor name
%r row at which the anchor has been inserted.
%c column at which the anchor has been inserted
-onInsertText

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%t text inserted
%r row at which the text was inserted
%c column at which the text was inserted
%l length of text inserted
-onMarkSet

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%n name of the mark inserted
%r row at which the text was inserted
%c column at which the text was inserted
-onMarkDelete

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%n name of the deleted mark
-onModified

type: string (default: "")

Tcl script which is executed when the buffer signals that the contexts of the text buffer has been modified. Before evaluation the following percent strings are substituated 

%c value =1. As this event occurs only the buffer content changes, it always returns the value 1.
-onRemoveTag

type: string (default: "")

Tcl script which is executed when a valid tag is applied to the contexts of the textbuffer. Before evaluation the following percent strings are substituated 

%t name of tag removed
%r row from which the tag removal began
%c column from which the tag removal began
%l line at which the tag removal ended
%o offset at which the tag removal ended

-scrollbar

type: always, never, automatic (default: automatic)

When to show scrollbars. If the value is a list of two elements, the first value is for the horizontal scrollbar and the second value for the vertical scrollbar.

-pixelsInsideWrap

type: integer

Pixels between lines after wrap.

-pixelsBelowLines

type: integer

Pixels below lines.

-pixelsAboveLines

type: integer

Pixels above lines.

-editable

type: boolean (default: 1)

Whether the text in the widget is editable.

-wrapMode

type: ONEOF none, char, word

Wrap mode used for the rendering of the cells.

-justify

type: ONEOF left, right, center, fill

Justification of the lines in one cell.

-leftMargin

type: integer

-rightMargin

type: integer

-indent

type: integer

-cursorVisible

type: boolean (default: 1)

Whether the cursor is visible.

-hasFocus

type: 1

This sets the focus to the widget. To unset the focus it must be set to another widet.

-sensitive

type: boolean (default: 1)

Whether or not the item is sensitve to user input.

-visible

type: boolean (default: 1)

Whether or not the item is visible.

-name

type: string

Name of the widget, can be used to set options in an rc file.

-tooltip

type: string

Message that appear next to this widget when the mouse pointer is held over it for a short amount of time.





Description

A text widget is used to input and show formatted text. Some text commands need an index as parameter. An index can be either a list of the row and the column, both starting at 0, for example "1 7", or a keyword like end, cursor, selectionStart, selectionEnd with an (without space) appended character offset, for example "selectionStart+3".

Commands

id class

Returns the class of the widget, i.e. text.

id configure [-option value...]

Configures the widget. Option may have any of the values accepted on creation of the widget.

id copy

Copies all text to the clipboard.

id cut

Copies all text to the clipboard and removes it from the widget.

id delete

Deletes the widget and the associated tcl command.

id signalEmit signal

Causes the widget to emit a signal under programme control. This causes the handling scripts configured to the matching signal to be called.

id erase startIndex ?endIndex?

Removes all text between startIndex and endIndex. endIndex defaults to end.

id get startIndex ?endIndex?

Returns the text between startIndex and endIndex. endIndex defaults to end.

id getCursor

Returns the  position position of the cursor as list of its row and column

  • id getCursor


  • Returns the position position of the cursor as list of its row and column

  • id gotoWordEnd 
  • Move the cursor to the start of the word in which it is occupied.

  • id gotoWordEnd
  • Move the cursor to the start of the word in which it is occupied.
  • id getLength

    Returns the number of characters in the widget.

    id getLineCount

    Returns the number of lines in the current text view.

    id getLineLength index

    Returns the number of characters in the line specified by the given index.

    id insert index text ?-tags taglist?

    Inserts and position indext the text text. If taglist is given the text is taged with each element of the list.

    id paste

    Pastes text from the clipboard at the current cursor position.

    id scrollToMark mark

    Scrolls the widget so that the specified mark is visible.

    id scrollToPosition index [-option value...]

    Scrolls the widget so that the specified index is visible.

    Options

    -align

    type: a list of the horizontal and vertical alignment or one of topLeft, top, topRight, left, center, right, bottomLeft, bottom, or bottomRight

    Specifies where the index shall be shown.

    -margin

    type: 0 lt float lt 1

    Specifies the margin.

    id select startIndex ?endIndex?

    Select the text between startIndex and endIndex. endIndex defaults to end.

    id setCursor index

    Sets the cursor to position index.

    id tag apply startIndex endIndex -tags taglist

    Applies the list of tags to the specified text range.

    id tag create tagName [-option value...]

    Creates a tag with name tagName and configures it dependent of the options given. The options are the same as with tag configure.

    id tag delete tagName

    Delete tag defintion from the textbuffer tag table. All instances of the tag in the textbuffer will be automatically removed.

    id tag configure tagName [-option value...]

    Configures the existing tag tagName.

    Options

    -background

    type: color

    Background color of the text.

    -editable

    type: boolean (default: 0)

    Whether the text can be edited.

    -foreground

    type: color

    Foreground color of the text.

    -font

    type: FONT

    Font of the text.

    -fontFamily

    Font family of the text.

    -fontStyle

    type: ONEOF normal, oblique, italic (default: normal)

    Font style of the text.

    -fontVariant

    type: ONEOF normal, smallCaps (default: normal)

    Font variant of the text.

    -fontWeight

    type: ONEOF ultralight, light, normal, bold, ultrabold, heavy (default: normal)

    Font weight of the text.

    -fontRise

    type: integer (default: 0)

    How many pixels the text should be risen.

    -fontStretch

    type: ONEOF ultraCondensed, extraCondensed, condensed, semiCondensed, normal, semiExpanded, expanded, extraExpanded, ultraExpanded (default: normal)

    Font stretch of the text.

    -fontSize

    type: integer

    Font size of the text.

    -fontScale

    type: float ORONEOF xx-small, x-small, small, medium, large, x-large, xx-large (default: normal)

    Font scale used.

    -onEvent

    type: string (default: "")

    Tcl command which is executed when the buffer signals that a mouse even has occurs in region tagged. Before evaluation the following percent strings are substituated 

    %w widget name
    %n tag name
    %t type of event
    %x mouse pointer x coordinate
    %y mouse pointer y coordinate
    %b button number
    %s state of buttons and modifiers (bitmask)
      
    -invisible

    type: boolean (default: 0)

    Whether the text is invisible.

    -justify

    type: ONEOF left, right, center, fill

    Justification of the lines.

    -strikethrough

    type: boolean (default: 0)

    Whether the text is struck through.

    -underline

    type: ONEOF none, single, double, low (default: none)

    How the text should be underlined.

    -wrapMode

    type: ONEOF none, char, word

    Wrap mode used.

    id tag remove startIndex endIndex -tags taglist

    Removes the list of tags to the specified text range.

    Example

    set text [gnocl::text -scrollbar always]
    $text tag create bold -fontWeight bold -foreground blue
    $text insert end "This is "
    $text insert end "Gnocl" -tags bold
    $text insert end "!"
    gnocl::window -title "Text" -child $text

    results in

    See also

    entry, label, GtkTextBuffer, GtkTextView