Gtk.Text¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Editable (27)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/c/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when the user hits the <kbd>Enter</kbd> key. |
|
Emitted when the user asks for it. |
|
Emitted to copy the selection to the clipboard. |
|
Emitted to cut the selection to the clipboard. |
|
Emitted when the user initiates a text deletion. |
|
Emitted when the user initiates the insertion of a fixed string at the cursor. |
|
Emitted to present the Emoji chooser for the widget. |
|
Emitted when the user initiates a cursor movement. |
|
Emitted to paste the contents of the clipboard. |
|
Emitted when the preedit text changes. |
|
Emitted to toggle the overwrite mode of the |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.Text(**kwargs)¶
- Bases:
- Abstract:
No
The
GtkText
widget is a single-line text entry widget.GtkText
is the common implementation of single-line text editing that is shared between [class`Gtk`.Entry], [class`Gtk`.PasswordEntry], [class`Gtk`.SpinButton], and other widgets. In all of these,GtkText
is used as the delegate for the [iface`Gtk`.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 [method`Gtk`.Text.set_visibility]. 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 [method`Gtk`.Text.set_invisible_char].
If you are looking to add icons or progress display in an entry, look at [class`Gtk`.Entry]. There other alternatives for more specialized use cases, such as [class`Gtk`.SearchEntry].
If you need multi-line editable text, look at [class`Gtk`.TextView].
- CSS nodes
`` text[.read-only] ├── placeholder ├── undershoot.left ├── undershoot.right ├── [selection] ├── [block-cursor] ╰── [window.popup] ``
GtkText
has a main node with the nametext
. 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
GtkText
uses theGtk.AccessibleRole.NONE
role, which causes it to be skipped for accessibility. This is becauseGtkText
is expected to be used as a delegate for aGtkEditable
implementation that will be represented to accessibility.- classmethod new_with_buffer(buffer)[source]¶
- Parameters:
buffer (
Gtk.EntryBuffer
) – The buffer to use for the newGtkText
.- Returns:
a new
GtkText
- Return type:
Creates a new
GtkText
with the specified text buffer.
- compute_cursor_extents(position)[source]¶
- Parameters:
position (
int
) – the character position- Returns:
- strong:
location to store the strong cursor position
- weak:
location to store the weak cursor position
- Return type:
(strong:
Graphene.Rect
, weak:Graphene.Rect
)
Determine the positions of the strong and weak cursors if the insertion point in the layout is at position.
The position of each cursor is stored as a zero-width rectangle. The strong cursor location is the location where characters of the directionality equal to the base direction are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction are inserted.
The rectangle positions are in widget coordinates.
New in version 4.4.
- get_activates_default()[source]¶
-
Returns whether pressing Enter will activate the default widget for the window containing self.
See [method`Gtk`.Text.set_activates_default].
- get_attributes()[source]¶
- Returns:
the attribute list
- Return type:
Gets the attribute list that was set on the
GtkText
.See [method`Gtk`.Text.set_attributes].
- get_buffer()[source]¶
- Returns:
A
GtkEntryBuffer
object.- Return type:
Get the
GtkEntryBuffer
object which holds the text for this widget.
- get_enable_emoji_completion()[source]¶
-
Returns whether Emoji completion is enabled for this
GtkText
widget.
- Returns:
the menu model
- Return type:
Gets the menu model for extra items in the context menu.
See [method`Gtk`.Text.set_extra_menu].
- get_invisible_char()[source]¶
- Returns:
the current invisible
str
, or 0, if text does not show invisible text at all.- Return type:
Retrieves the character displayed when visibility is set to false.
Note that GTK does not compute this value unless it needs it, so the value returned by this function is not very useful unless it has been explicitly set with [method`Gtk`.Text.set_invisible_char].
- get_max_length()[source]¶
- Returns:
the maximum allowed number of characters in
GtkText
, or 0 if there is no maximum.- Return type:
Retrieves the maximum allowed length of the text in self.
See [method`Gtk`.Text.set_max_length].
This is equivalent to getting self's
GtkEntryBuffer
and calling [method`Gtk`.EntryBuffer.get_max_length] on it.
- get_overwrite_mode()[source]¶
- Returns:
whether the text is overwritten when typing
- Return type:
Gets whether text is overwritten when typing in the
GtkText
.See [method`Gtk`.Text.set_overwrite_mode].
- get_placeholder_text()[source]¶
-
Retrieves the text that will be displayed when self is empty and unfocused
If no placeholder text has been set,
None
will be returned.
- get_propagate_text_width()[source]¶
-
Returns whether the
GtkText
will grow and shrink with the content.
- get_tabs()[source]¶
- Returns:
the tabstops
- Return type:
Gets the tabstops that were set on the
GtkText
.See [method`Gtk`.Text.set_tabs].
- get_text_length()[source]¶
- Returns:
the current number of characters in
GtkText
, or 0 if there are none.- Return type:
Retrieves the current length of the text in self.
This is equivalent to getting self's
GtkEntryBuffer
and calling [method`Gtk`.EntryBuffer.get_length] on it.
- get_truncate_multiline()[source]¶
-
Returns whether the
GtkText
will truncate multi-line text that is pasted into the widget
- grab_focus_without_selecting()[source]¶
-
Causes self to have keyboard focus.
It behaves like [method`Gtk`.Widget.grab_focus], except that it doesn’t select the contents of self. You only want to call this on some special entries which the user usually doesn’t want to replace all text in, such as search-as-you-type entries.
- set_activates_default(activates)[source]¶
-
If activates is
True
, pressing Enter will activate the default widget for the window containing self.This usually means that the dialog containing the
GtkText
will be closed, since the default widget is usually one of the dialog buttons.
- set_attributes(attrs)[source]¶
- Parameters:
attrs (
Pango.AttrList
orNone
) – aPangoAttrList
Sets attributes that are applied to the text.
- set_buffer(buffer)[source]¶
- Parameters:
buffer (
Gtk.EntryBuffer
) – aGtkEntryBuffer
Set the
GtkEntryBuffer
object which holds the text for this widget.
- set_enable_emoji_completion(enable_emoji_completion)[source]¶
-
Sets whether Emoji completion is enabled.
If it is, typing ‘:’, followed by a recognized keyword, will pop up a window with suggested Emojis matching the keyword.
- Parameters:
model (
Gio.MenuModel
orNone
) – aGMenuModel
Sets a menu model to add when constructing the context menu for self.
- set_input_hints(hints)[source]¶
- Parameters:
hints (
Gtk.InputHints
) – the hints
Sets input hints that allow input methods to fine-tune their behaviour.
- set_input_purpose(purpose)[source]¶
- Parameters:
purpose (
Gtk.InputPurpose
) – the purpose
Sets the input purpose of the
GtkText
.This can be used by on-screen keyboards and other input methods to adjust their behaviour.
- set_invisible_char(ch)[source]¶
- Parameters:
ch (
str
) – a Unicode character
Sets the character to use when in “password mode”.
By default, GTK picks the best invisible
str
available in the current font. If you set the invisiblestr
to 0, then the user will get no feedback at all; there will be no text on the screen as they type.
- set_max_length(length)[source]¶
- Parameters:
length (
int
) – the maximum length of theGtkText
, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536.
Sets the maximum allowed length of the contents of the widget.
If the current contents are longer than the given length, then they will be truncated to fit.
This is equivalent to getting self's
GtkEntryBuffer
and calling [method`Gtk`.EntryBuffer.set_max_length] on it.
- set_overwrite_mode(overwrite)[source]¶
- Parameters:
overwrite (
bool
) – new value
Sets whether the text is overwritten when typing in the
GtkText
.
- set_placeholder_text(text)[source]¶
-
Sets text to be displayed in self when it is empty.
This can be used to give a visual hint of the expected contents of the
GtkText
.
- set_propagate_text_width(propagate_text_width)[source]¶
-
Sets whether the
GtkText
should grow and shrink with the content.
- set_tabs(tabs)[source]¶
- Parameters:
tabs (
Pango.TabArray
orNone
) – aPangoTabArray
Sets tabstops that are applied to the text.
- set_truncate_multiline(truncate_multiline)[source]¶
-
Sets whether the
GtkText
should truncate multi-line text that is pasted into the widget.
- set_visibility(visible)[source]¶
-
Sets whether the contents of the
GtkText
are visible or not.When visibility is set to
False
, characters are displayed as the invisiblestr
, and will also appear that way when the text in the widget is copied to the clipboard.By default, GTK picks the best invisible character available in the current font, but it can be changed with [method`Gtk`.Text.set_invisible_char].
Note that you probably want to set [property`Gtk`.Text:input-purpose] to
Gtk.InputPurpose.PASSWORD
orGtk.InputPurpose.PIN
to inform input methods about the purpose of this self, in addition to setting visibility toFalse
.
Signal Details¶
- Gtk.Text.signals.activate(text)¶
- Signal Name:
activate
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted when the user hits the <kbd>Enter</kbd> key.
The default bindings for this signal are all forms of the <kbd>Enter</kbd> key.
- Gtk.Text.signals.backspace(text)¶
- Signal Name:
backspace
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted when the user asks for it.
This is a keybinding signal.
The default bindings for this signal are <kbd>Backspace</kbd> and <kbd>Shift</kbd>+<kbd>Backspace</kbd>.
- Gtk.Text.signals.copy_clipboard(text)¶
- Signal Name:
copy-clipboard
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted to copy the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>c</kbd> and <kbd>Ctrl</kbd>+<kbd>Insert</kbd>.
- Gtk.Text.signals.cut_clipboard(text)¶
- Signal Name:
cut-clipboard
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted to cut the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>x</kbd> and <kbd>Shift</kbd>+<kbd>Delete</kbd>.
- Gtk.Text.signals.delete_from_cursor(text, type, count)¶
- Signal Name:
delete-from-cursor
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signaltype (
Gtk.DeleteType
) – the granularity of the deletion, as aGtkDeleteType
count (
int
) – the number of type units to delete
Emitted when the user initiates a text deletion.
This is a keybinding signal.
If the type is
Gtk.DeleteType.CHARS
, GTK deletes the selection if there is one, otherwise it deletes the requested number of characters.The default bindings for this signal are <kbd>Delete</kbd> for deleting a character and <kbd>Ctrl</kbd>+<kbd>Delete</kbd> for deleting a word.
- Gtk.Text.signals.insert_at_cursor(text, string)¶
- Signal Name:
insert-at-cursor
- Flags:
- Parameters:
Emitted when the user initiates the insertion of a fixed string at the cursor.
This is a keybinding signal.
This signal has no default bindings.
- Gtk.Text.signals.insert_emoji(text)¶
- Signal Name:
insert-emoji
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted to present the Emoji chooser for the widget.
This is a keybinding signal.
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>.</kbd> and <kbd>Ctrl</kbd>+<kbd>;</kbd>
- Gtk.Text.signals.move_cursor(text, step, count, extend)¶
- Signal Name:
move-cursor
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signalstep (
Gtk.MovementStep
) – the granularity of the move, as aGtkMovementStep
count (
int
) – the number of step units to moveextend (
bool
) –True
if the move should extend the selection
Emitted when the user initiates a cursor movement.
If the cursor is not visible in self, this signal causes the viewport to be moved instead.
This is a keybinding signal.
Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the <kbd>Shift</kbd> modifier extends the selection, the variant without it does not. There are too many key combinations to list them all here.
<kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd> move by individual characters/lines
<kbd>Ctrl</kbd>+<kbd>←</kbd>, etc. move by words/paragraphs
<kbd>Home</kbd> and <kbd>End</kbd> move to the ends of the buffer
- Gtk.Text.signals.paste_clipboard(text)¶
- Signal Name:
paste-clipboard
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted to paste the contents of the clipboard.
This is a keybinding signal.
The default bindings for this signal are <kbd>Ctrl</kbd>+<kbd>v</kbd> and <kbd>Shift</kbd>+<kbd>Insert</kbd>.
- Gtk.Text.signals.preedit_changed(text, preedit)¶
- Signal Name:
preedit-changed
- Flags:
- Parameters:
Emitted when the preedit text changes.
If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.
- Gtk.Text.signals.toggle_overwrite(text)¶
- Signal Name:
toggle-overwrite
- Flags:
- Parameters:
text (
Gtk.Text
) – The object which received the signal
Emitted to toggle the overwrite mode of the
GtkText
.This is a keybinding signal.
The default bindings for this signal is <kbd>Insert</kbd>.
Property Details¶
- Gtk.Text.props.activates_default¶
- Name:
activates-default
- Type:
- Default Value:
- Flags:
Whether to activate the default widget when Enter is pressed.
- Gtk.Text.props.attributes¶
- Name:
attributes
- Type:
- Default Value:
- Flags:
A list of Pango attributes to apply to the text of the
GtkText
.This is mainly useful to change the size or weight of the text.
The
PangoAttribute
’s start_index and end_index must refer to theGtkEntryBuffer
text, i.e. without the preedit string.
- Gtk.Text.props.buffer¶
- Name:
buffer
- Type:
- Default Value:
- Flags:
The
GtkEntryBuffer
object which stores the text.
- Gtk.Text.props.enable_emoji_completion¶
- Name:
enable-emoji-completion
- Type:
- Default Value:
- Flags:
Whether to suggest Emoji replacements.
- Name:
extra-menu
- Type:
- Default Value:
- Flags:
A menu model whose contents will be appended to the context menu.
- Gtk.Text.props.im_module¶
- Name:
im-module
- Type:
- Default Value:
- Flags:
Which IM (input method) module should be used for this self.
See [class`Gtk`.IMMulticontext].
Setting this to a non-
None
value overrides the system-wide IM module setting. See the [property`Gtk`.Settings:gtk-im-module] property.
- Gtk.Text.props.input_hints¶
- Name:
input-hints
- Type:
- Default Value:
- Flags:
Additional hints that allow input methods to fine-tune their behaviour.
- Gtk.Text.props.input_purpose¶
- Name:
input-purpose
- Type:
- Default Value:
- Flags:
The purpose of this text field.
This property can be used by on-screen keyboards and other input methods to adjust their behaviour.
Note that setting the purpose to
Gtk.InputPurpose.PASSWORD
orGtk.InputPurpose.PIN
is independent from setting [property`Gtk`.Text:visibility].
- Gtk.Text.props.invisible_char¶
- Name:
invisible-char
- Type:
- Default Value:
42
- Flags:
The character to used when masking contents (in “password mode”).
- Gtk.Text.props.max_length¶
- Name:
max-length
- Type:
- Default Value:
0
- Flags:
Maximum number of characters that are allowed.
Zero indicates no limit.
- Gtk.Text.props.overwrite_mode¶
- Name:
overwrite-mode
- Type:
- Default Value:
- Flags:
If text is overwritten when typing in the
GtkText
.
- Gtk.Text.props.placeholder_text¶
- Name:
placeholder-text
- Type:
- Default Value:
- Flags:
The text that will be displayed in the
GtkText
when it is empty and unfocused.
- Gtk.Text.props.propagate_text_width¶
- Name:
propagate-text-width
- Type:
- Default Value:
- Flags:
Whether the widget should grow and shrink with the content.
- Gtk.Text.props.scroll_offset¶
- Name:
scroll-offset
- Type:
- Default Value:
0
- Flags:
Number of pixels scrolled of the screen to the left.
- Gtk.Text.props.tabs¶
- Name:
tabs
- Type:
- Default Value:
- Flags:
A list of tabstops to apply to the text of the
GtkText
.