gtk.text
Module for [Text] class
Types 3
The gtk.text.Text widget is a single-line text entry widget.
gtk.text.Text is the common implementation of single-line text editing that is shared between gtk.entry.Entry, gtk.password_entry.PasswordEntry, gtk.spin_button.SpinButton, and other widgets. In all of these, gtk.text.Text is used as the delegate for the gtk.editable.Editable implementation.
A fairly large set of key bindings are supported by default. If the entered text is longer than the allocation of the widget, the widget will scroll so that the cursor position is visible.
When using an entry for passwords and other sensitive information, it can be put into “password mode” using gtk.text.Text.setVisibility. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the best invisible character that is available in the current font, but it can be changed with gtk.text.Text.setInvisibleChar.
If you are looking to add icons or progress display in an entry, look at gtk.entry.Entry. There other alternatives for more specialized use cases, such as gtk.search_entry.SearchEntry.
If you need multi-line editable text, look at gtk.text_view.TextView.
CSS nodes
text[.read-only]
├── placeholder
├── undershoot.left
├── undershoot.right
├── [selection]
├── [block-cursor]
╰── [window.popup]gtk.text.Text has a main node with the name text. Depending on the properties of the widget, the .read-only style class may appear.
When the entry has a selection, it adds a subnode with the name selection.
When the entry is in overwrite mode, it adds a subnode with the name block-cursor that determines how the block cursor is drawn.
The CSS node for a context menu is added as a subnode with the name popup.
The undershoot nodes are used to draw the underflow indication when content is scrolled out of view. These nodes get the .left or .right style class added depending on where the indication is drawn.
When touch is used and touch selection handles are shown, they are using CSS nodes with name cursor-handle. They get the .top or .bottom style class depending on where they are shown in relation to the selection. If there is just a single handle for the text cursor, it gets the style class .insertion-cursor.
Accessibility
gtk.text.Text uses the gtk.types.AccessibleRole.None role, which causes it to be skipped for accessibility. This is because gtk.text.Text is expected to be used as a delegate for a gtk.editable.Editable implementation that will be represented to accessibility.
bool activatesDefault() @property nothrowGet `activatesDefault` property. Returns: Whether to activate the default widget when Enter is pressed.void activatesDefault(bool propval) @property nothrowSet `activatesDefault` property. Params: propval = Whether to activate the default widget when Enter is pressed.pango.attr_list.AttrList attributes() @property nothrowGet `attributes` property. Returns: A list of Pango attributes to apply to the text of the [gtk.text.Text].void attributes(pango.attr_list.AttrList propval) @property nothrowSet `attributes` property. Params: propval = A list of Pango attributes to apply to the text of the [gtk.text.Text].gtk.entry_buffer.EntryBuffer buffer() @property nothrowGet `buffer` property. Returns: The [gtk.entry_buffer.EntryBuffer] object which stores the text.void buffer(gtk.entry_buffer.EntryBuffer propval) @property nothrowSet `buffer` property. Params: propval = The [gtk.entry_buffer.EntryBuffer] object which stores the text.bool enableEmojiCompletion() @property nothrowGet `enableEmojiCompletion` property. Returns: Whether to suggest Emoji replacements.void enableEmojiCompletion(bool propval) @property nothrowSet `enableEmojiCompletion` property. Params: propval = Whether to suggest Emoji replacements.gio.menu_model.MenuModel extraMenu() @property nothrowGet `extraMenu` property. Returns: A menu model whose contents will be appended to the context menu.void extraMenu(gio.menu_model.MenuModel propval) @property nothrowSet `extraMenu` property. Params: propval = A menu model whose contents will be appended to the context menu.string imModule() @property nothrowGet `imModule` property. Returns: Which IM (input method) module should be used for this self.void imModule(string propval) @property nothrowSet `imModule` property. Params: propval = Which IM (input method) module should be used for this self.gtk.types.InputHints inputHints() @property nothrowGet `inputHints` property. Returns: Additional hints that allow input methods to fine-tune their behaviour.void inputHints(gtk.types.InputHints propval) @property nothrowSet `inputHints` property. Params: propval = Additional hints that allow input methods to fine-tune their behaviour.gtk.types.InputPurpose inputPurpose() @property nothrowGet `inputPurpose` property. Returns: The purpose of this text field.void inputPurpose(gtk.types.InputPurpose propval) @property nothrowSet `inputPurpose` property. Params: propval = The purpose of this text field.uint invisibleChar() @property nothrowGet `invisibleChar` property. Returns: The character to used when masking contents (in “password mode”).void invisibleChar(uint propval) @property nothrowSet `invisibleChar` property. Params: propval = The character to used when masking contents (in “password mode”).bool invisibleCharSet() @property nothrowGet `invisibleCharSet` property. Returns: Whether the invisible char has been set for the [gtk.text.Text].void invisibleCharSet(bool propval) @property nothrowSet `invisibleCharSet` property. Params: propval = Whether the invisible char has been set for the [gtk.text.Text].int maxLength() @property nothrowGet `maxLength` property. Returns: Maximum number of characters that are allowed.void maxLength(int propval) @property nothrowSet `maxLength` property. Params: propval = Maximum number of characters that are allowed.bool overwriteMode() @property nothrowGet `overwriteMode` property. Returns: If text is overwritten when typing in the [gtk.text.Text].void overwriteMode(bool propval) @property nothrowSet `overwriteMode` property. Params: propval = If text is overwritten when typing in the [gtk.text.Text].string placeholderText() @property nothrowGet `placeholderText` property. Returns: The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused.void placeholderText(string propval) @property nothrowSet `placeholderText` property. Params: propval = The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused.bool propagateTextWidth() @property nothrowGet `propagateTextWidth` property. Returns: Whether the widget should grow and shrink with the content.void propagateTextWidth(bool propval) @property nothrowSet `propagateTextWidth` property. Params: propval = Whether the widget should grow and shrink with the content.int scrollOffset() @property nothrowGet `scrollOffset` property. Returns: Number of pixels scrolled of the screen to the left.pango.tab_array.TabArray tabs() @property nothrowGet `tabs` property. Returns: A list of tabstops to apply to the text of the [gtk.text.Text].void tabs(pango.tab_array.TabArray propval) @property nothrowSet `tabs` property. Params: propval = A list of tabstops to apply to the text of the [gtk.text.Text].bool truncateMultiline() @property nothrowGet `truncateMultiline` property. Returns: When true, pasted multi-line text is truncated to the first line.void truncateMultiline(bool propval) @property nothrowSet `truncateMultiline` property. Params: propval = When true, pasted multi-line text is truncated to the first line.bool visibility() @property nothrowGet `visibility` property. Returns: If false, the text is masked with the “invisible char”.void visibility(bool propval) @property nothrowSet `visibility` property. Params: propval = If false, the text is masked with the “invisible char”.gtk.text.Text newWithBuffer(gtk.entry_buffer.EntryBuffer buffer) static nothrowCreates a new [gtk.text.Text] with the specified text buffer.void computeCursorExtents(size_t position, out graphene.rect.Rect strong, out graphene.rect.Rect weak) nothrowDetermine the positions of the strong and weak cursors if the insertion point in the layout is at position.bool getActivatesDefault() nothrowReturns whether pressing Enter will activate the default widget for the window containing self.pango.attr_list.AttrList getAttributes() nothrowGets the attribute list that was set on the [gtk.text.Text].gtk.entry_buffer.EntryBuffer getBuffer() nothrowGet the [gtk.entry_buffer.EntryBuffer] object which holds the text for this widget. Returns: A [gtk.entry_buffer.EntryBuffer] object.bool getEnableEmojiCompletion() nothrowReturns whether Emoji completion is enabled for this [gtk.text.Text] widget. Returns: true if Emoji completion is enabledgio.menu_model.MenuModel getExtraMenu() nothrowGets the menu model for extra items in the context menu.gtk.types.InputPurpose getInputPurpose() nothrowGets the input purpose of the [gtk.text.Text]. Returns:string getPlaceholderText() nothrowRetrieves the text that will be displayed when self is empty and unfocusedbool getPropagateTextWidth() nothrowReturns whether the [gtk.text.Text] will grow and shrink with the content. Returns: true if self will propagate the text widthbool getTruncateMultiline() nothrowReturns whether the [gtk.text.Text] will truncate multi-line text that is pasted into the widget Returns: true if self will truncate multi-line textbool getVisibility() nothrowRetrieves whether the text in self is visible. Returns: true if the text is currently visiblevoid setActivatesDefault(bool activates) nothrowIf activates is true, pressing Enter will activate the default widget for the window containing self.void setAttributes(pango.attr_list.AttrList attrs = null) nothrowSets attributes that are applied to the text.void setBuffer(gtk.entry_buffer.EntryBuffer buffer) nothrowSet the [gtk.entry_buffer.EntryBuffer] object which holds the text for this widget.void setEnableEmojiCompletion(bool enableEmojiCompletion) nothrowSets whether Emoji completion is enabled.void setExtraMenu(gio.menu_model.MenuModel model = null) nothrowSets a menu model to add when constructing the context menu for self.void setInputHints(gtk.types.InputHints hints) nothrowSets input hints that allow input methods to fine-tune their behaviour.void setInputPurpose(gtk.types.InputPurpose purpose) nothrowSets the input purpose of the [gtk.text.Text].void setOverwriteMode(bool overwrite) nothrowSets whether the text is overwritten when typing in the [gtk.text.Text].void setPlaceholderText(string text = null) nothrowSets text to be displayed in self when it is empty.void setPropagateTextWidth(bool propagateTextWidth) nothrowSets whether the [gtk.text.Text] should grow and shrink with the content.void setTabs(pango.tab_array.TabArray tabs = null) nothrowSets tabstops that are applied to the text.void setTruncateMultiline(bool truncateMultiline) nothrowSets whether the [gtk.text.Text] should truncate multi-line text that is pasted into the widget.void setVisibility(bool visible) nothrowSets whether the contents of the [gtk.text.Text] are visible or not.gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `Activate` signal.gulong connectBackspace(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `Backspace` signal.gulong connectCopyClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `CopyClipboard` signal.gulong connectCutClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `CutClipboard` signal.gulong connectDeleteFromCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.DeleteType)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.text.Text)))
&& Parameters!T.length < 4) nothrowConnect to `DeleteFromCursor` signal.gulong connectInsertAtCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == string)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.text.Text)))
&& Parameters!T.length < 3) nothrowConnect to `InsertAtCursor` signal.gulong connectInsertEmoji(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `InsertEmoji` signal.gulong connectMoveCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.MovementStep)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] == bool)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.text.Text)))
&& Parameters!T.length < 5) nothrowConnect to `MoveCursor` signal.gulong connectPasteClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `PasteClipboard` signal.gulong connectPreeditChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == string)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.text.Text)))
&& Parameters!T.length < 3) nothrowConnect to `PreeditChanged` signal.gulong connectToggleOverwrite(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2) nothrowConnect to `ToggleOverwrite` signal.Fluent builder implementation template for gtk.text.Text
T activatesDefault(bool propval) nothrowSet `activatesDefault` property. Params: propval = Whether to activate the default widget when Enter is pressed. Returns: Builder instance for fluent chainingT attributes(pango.attr_list.AttrList propval) nothrowSet `attributes` property. Params: propval = A list of Pango attributes to apply to the text of the [gtk.text.Text].T buffer(gtk.entry_buffer.EntryBuffer propval) nothrowSet `buffer` property. Params: propval = The [gtk.entry_buffer.EntryBuffer] object which stores the text. Returns: Builder instance for fluent chainingT enableEmojiCompletion(bool propval) nothrowSet `enableEmojiCompletion` property. Params: propval = Whether to suggest Emoji replacements. Returns: Builder instance for fluent chainingT extraMenu(gio.menu_model.MenuModel propval) nothrowSet `extraMenu` property. Params: propval = A menu model whose contents will be appended to the context menu. Returns: Builder instance for fluent chainingT imModule(string propval) nothrowSet `imModule` property. Params: propval = Which IM (input method) module should be used for this self.T inputHints(gtk.types.InputHints propval) nothrowSet `inputHints` property. Params: propval = Additional hints that allow input methods to fine-tune their behaviour. Returns: Builder instance for fluent chainingT inputPurpose(gtk.types.InputPurpose propval) nothrowSet `inputPurpose` property. Params: propval = The purpose of this text field.T invisibleChar(uint propval) nothrowSet `invisibleChar` property. Params: propval = The character to used when masking contents (in “password mode”). Returns: Builder instance for fluent chainingT invisibleCharSet(bool propval) nothrowSet `invisibleCharSet` property. Params: propval = Whether the invisible char has been set for the [gtk.text.Text]. Returns: Builder instance for fluent chainingT maxLength(int propval) nothrowSet `maxLength` property. Params: propval = Maximum number of characters that are allowed.T overwriteMode(bool propval) nothrowSet `overwriteMode` property. Params: propval = If text is overwritten when typing in the [gtk.text.Text]. Returns: Builder instance for fluent chainingT placeholderText(string propval) nothrowSet `placeholderText` property. Params: propval = The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused. Returns: Builder instance for fluent chainingT propagateTextWidth(bool propval) nothrowSet `propagateTextWidth` property. Params: propval = Whether the widget should grow and shrink with the content. Returns: Builder instance for fluent chainingT tabs(pango.tab_array.TabArray propval) nothrowSet `tabs` property. Params: propval = A list of tabstops to apply to the text of the [gtk.text.Text]. Returns: Builder instance for fluent chainingT truncateMultiline(bool propval) nothrowSet `truncateMultiline` property. Params: propval = When true, pasted multi-line text is truncated to the first line. Returns: Builder instance for fluent chainingT visibility(bool propval) nothrowSet `visibility` property. Params: propval = If false, the text is masked with the “invisible char”. Returns: Builder instance for fluent chainingFluent builder for gtk.text.Text