Gtk.TextView - Classes - Gtk 3.0 (original) (raw)

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.TextView Gtk.TextView Gtk.Container->Gtk.TextView Gtk.Scrollable->Gtk.TextView Gtk.Widget->Gtk.Container

Example

../_images/TextView.png

Subclasses:

None

Methods

Inherited:

Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Scrollable (9)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class new ()
class new_with_buffer (buffer)
add_child_at_anchor (child, anchor)
add_child_in_window (child, which_window, xpos, ypos)
backward_display_line (iter)
backward_display_line_start (iter)
buffer_to_window_coords (win, buffer_x, buffer_y)
forward_display_line (iter)
forward_display_line_end (iter)
get_accepts_tab ()
get_border_window_size (type)
get_bottom_margin ()
get_buffer ()
get_cursor_locations (iter)
get_cursor_visible ()
get_default_attributes ()
get_editable ()
get_hadjustment ()
get_indent ()
get_input_hints ()
get_input_purpose ()
get_iter_at_location (x, y)
get_iter_at_position (x, y)
get_iter_location (iter)
get_justification ()
get_left_margin ()
get_line_at_y (y)
get_line_yrange (iter)
get_monospace ()
get_overwrite ()
get_pixels_above_lines ()
get_pixels_below_lines ()
get_pixels_inside_wrap ()
get_right_margin ()
get_tabs ()
get_top_margin ()
get_vadjustment ()
get_visible_rect ()
get_window (win)
get_window_type (window)
get_wrap_mode ()
im_context_filter_keypress (event)
move_child (child, xpos, ypos)
move_mark_onscreen (mark)
move_visually (iter, count)
place_cursor_onscreen ()
reset_cursor_blink ()
reset_im_context ()
scroll_mark_onscreen (mark)
scroll_to_iter (iter, within_margin, use_align, xalign, yalign)
scroll_to_mark (mark, within_margin, use_align, xalign, yalign)
set_accepts_tab (accepts_tab)
set_border_window_size (type, size)
set_bottom_margin (bottom_margin)
set_buffer (buffer)
set_cursor_visible (setting)
set_editable (setting)
set_indent (indent)
set_input_hints (hints)
set_input_purpose (purpose)
set_justification (justification)
set_left_margin (left_margin)
set_monospace (monospace)
set_overwrite (overwrite)
set_pixels_above_lines (pixels_above_lines)
set_pixels_below_lines (pixels_below_lines)
set_pixels_inside_wrap (pixels_inside_wrap)
set_right_margin (right_margin)
set_tabs (tabs)
set_top_margin (top_margin)
set_wrap_mode (wrap_mode)
starts_display_line (iter)
window_to_buffer_coords (win, window_x, window_y)

Virtual Methods

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Scrollable (1)

do_backspace ()
do_copy_clipboard ()
do_cut_clipboard ()
do_delete_from_cursor (type, count)
do_draw_layer (layer, cr)
do_extend_selection (granularity, location, start, end)
do_insert_at_cursor (str)
do_insert_emoji ()
do_move_cursor (step, count, extend_selection)
do_paste_clipboard ()
do_populate_popup (popup)
do_set_anchor ()
do_toggle_overwrite ()

Properties

Inherited:

Gtk.Container (3), Gtk.Widget (39), Gtk.Scrollable (4)

Name Type Flags Short Description
accepts-tab bool r/w/en Whether Tab will result in a tab character being entered
bottom-margin int r/w/en Height of the bottom margin in pixels
buffer Gtk.TextBuffer r/w The buffer which is displayed
cursor-visible bool r/w/en If the insertion cursor is shown
editable bool r/w/en Whether the text can be modified by the user
im-module str r/w Which IM module should be used
indent int r/w/en Amount to indent the paragraph, in pixels
input-hints Gtk.InputHints r/w/en Hints for the text field behaviour
input-purpose Gtk.InputPurpose r/w/en Purpose of the text field
justification Gtk.Justification r/w/en Left, right, or center justification
left-margin int r/w/en Width of the left margin in pixels
monospace bool r/w/en Whether to use a monospace font
overwrite bool r/w/en Whether entered text overwrites existing contents
pixels-above-lines int r/w/en Pixels of blank space above paragraphs
pixels-below-lines int r/w/en Pixels of blank space below paragraphs
pixels-inside-wrap int r/w/en Pixels of blank space between wrapped lines in a paragraph
populate-all bool r/w/en Whether to emit ::populate-popup for touch popups
right-margin int r/w/en Width of the right margin in pixels
tabs Pango.TabArray r/w Custom tabs for this text
top-margin int r/w/en Height of the top margin in pixels
wrap-mode Gtk.WrapMode r/w/en Whether to wrap lines never, at word boundaries, or at character boundaries

Style Properties

Inherited:

Gtk.Widget (17)

Name Type Default Flags Short Description
error-underline-color Gdk.Color None r Color with which to draw error-indication underlines

Signals

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name Short Description
backspace The ::backspace signal is a keybinding signal which gets emitted when the user asks for it.
copy-clipboard The ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
cut-clipboard The ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
delete-from-cursor The ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
extend-selection The ::extend-selection signal is emitted when the selection needs to be extended at location.
insert-at-cursor The ::insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor.
insert-emoji The ::insert-emoji signal is a keybinding signal which gets emitted to present the Emoji chooser for the text_view.
move-cursor The ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement.
move-viewport The ::move-viewport signal is a keybinding signal which can be bound to key combinations to allow the user to move the viewport, i.e.
paste-clipboard The ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
populate-popup The ::populate-popup signal gets emitted before showing the context menu of the text view.
preedit-changed If an input method is used, the typed text will not immediately be committed to the buffer.
select-all The ::select-all signal is a keybinding signal which gets emitted to select or unselect the complete contents of the text view.
set-anchor The ::set-anchor signal is a keybinding signal which gets emitted when the user initiates setting the “anchor” mark.
toggle-cursor-visible The ::toggle-cursor-visible signal is a keybinding signal which gets emitted to toggle the Gtk.TextView :cursor-visible property.
toggle-overwrite The ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the text view.

Fields

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name Type Access Description
parent_instance Gtk.Container r

Class Details

class Gtk.TextView(**kwargs)

Bases:

Gtk.Container, Gtk.Scrollable

Abstract:

No

Structure:

Gtk.TextViewClass

You may wish to begin by reading thetext widget conceptual overviewwhich gives an overview of all the objects and data types related to the text widget and how they work together.

CSS nodes

textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├── border.bottom ╰── [window.popup]

Gtk.TextView has a main css node with name textview and style class .view, and subnodes for each of the border windows, and the main text area, with names border and text, respectively. The border nodes each get one of the style classes .left, .right, .top or .bottom.

A node representing the selection will appear below the text node.

If a context menu is opened, the window node will appear as a subnode of the main node.

classmethod new()[source]

Returns:

a new Gtk.TextView

Return type:

Gtk.Widget

Creates a new Gtk.TextView. If you don’t call Gtk.TextView.set_buffer() before using the text view, an empty default buffer will be created for you. Get the buffer with Gtk.TextView.get_buffer(). If you want to specify your own buffer, consider Gtk.TextView.new_with_buffer().

classmethod new_with_buffer(buffer)[source]

Parameters:

buffer (Gtk.TextBuffer) – a Gtk.TextBuffer

Returns:

a new Gtk.TextView.

Return type:

Gtk.Widget

Creates a new Gtk.TextView widget displaying the bufferbuffer. One buffer can be shared among many widgets.buffer may be None to create a default buffer, in which case this function is equivalent to Gtk.TextView.new(). The text view adds its own reference count to the buffer; it does not take over an existing reference.

add_child_at_anchor(child, anchor)[source]

Parameters:

Adds a child widget in the text buffer, at the given anchor.

add_child_in_window(child, which_window, xpos, ypos)[source]

Parameters:

Adds a child at fixed coordinates in one of the text widget’s windows.

The window must have nonzero size (seeGtk.TextView.set_border_window_size()). Note that the child coordinates are given relative to scrolling. When placing a child in Gtk.TextWindowType.WIDGET, scrolling is irrelevant, the child floats above all scrollable areas. But when placing a child in one of the scrollable windows (border windows or text window) it will move with the scrolling as needed.

backward_display_line(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

True if iter was moved and is not on the end iterator

Return type:

bool

Moves the given iter backward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.xlib.Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. xlib.Display lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of the Gtk.TextBuffer.

backward_display_line_start(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

True if iter was moved and is not on the end iterator

Return type:

bool

Moves the given iter backward to the next display line start. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.xlib.Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. xlib.Display lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of the Gtk.TextBuffer.

buffer_to_window_coords(win, buffer_x, buffer_y)[source]

Parameters:

Returns:

window_x:

window x coordinate return location or None

window_y:

window y coordinate return location or None

Return type:

(window_x: int, window_y: int)

Converts coordinate (buffer_x, buffer_y) to coordinates for the windowwin, and stores the result in (window_x, window_y).

Note that you can’t convert coordinates for a nonexisting window (seeGtk.TextView.set_border_window_size()).

forward_display_line(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

True if iter was moved and is not on the end iterator

Return type:

bool

Moves the given iter forward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.xlib.Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. xlib.Display lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of the Gtk.TextBuffer.

forward_display_line_end(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

True if iter was moved and is not on the end iterator

Return type:

bool

Moves the given iter forward to the next display line end. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.xlib.Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. xlib.Display lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of the Gtk.TextBuffer.

get_accepts_tab()[source]

Returns:

True if pressing the Tab key inserts a tab character,False if pressing the Tab key moves the keyboard focus.

Return type:

bool

Returns whether pressing the Tab key inserts a tab characters.Gtk.TextView.set_accepts_tab().

New in version 2.4.

get_border_window_size(type)[source]

Parameters:

type (Gtk.TextWindowType) – window to return size from

Returns:

width of window

Return type:

int

Gets the width of the specified border window. SeeGtk.TextView.set_border_window_size().

get_bottom_margin()[source]

Returns:

bottom margin in pixels

Return type:

int

Gets the bottom margin for text in the self.

New in version 3.18.

get_buffer()[source]

Returns:

a Gtk.TextBuffer

Return type:

Gtk.TextBuffer

Returns the Gtk.TextBuffer being displayed by this text view. The reference count on the buffer is not incremented; the caller of this function won’t own a new reference.

get_cursor_locations(iter)[source]

Parameters:

iter (Gtk.TextIter or None) – a Gtk.TextIter

Returns:

strong:

location to store the strong cursor position (may be None)

weak:

location to store the weak cursor position (may be None)

Return type:

(strong: Gdk.Rectangle, weak: Gdk.Rectangle)

Given an iter within a text layout, determine the positions of the strong and weak cursors if the insertion point is at that iterator. 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 of the paragraph are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction of the paragraph are inserted.

If iter is None, the actual cursor position is used.

Note that if iter happens to be the actual cursor position, and there is currently an IM preedit sequence being entered, the returned locations will be adjusted to account for the preedit cursor’s offset within the preedit sequence.

The rectangle position is in buffer coordinates; useGtk.TextView.buffer_to_window_coords() to convert these coordinates to coordinates for one of the windows in the text view.

New in version 3.0.

get_cursor_visible()[source]

Returns:

whether the insertion mark is visible

Return type:

bool

Find out whether the cursor should be displayed.

get_default_attributes()[source]

Returns:

a new Gtk.TextAttributes

Return type:

Gtk.TextAttributes

Obtains a copy of the default text attributes. These are the attributes used for text unless a tag overrides them. You’d typically pass the default attributes in toGtk.TextIter.get_attributes() in order to get the attributes in effect at a given text position.

The return value is a copy owned by the caller of this function, and should be freed with Gtk.TextAttributes.unref().

get_editable()[source]

Returns:

whether text is editable by default

Return type:

bool

Returns the default editability of the Gtk.TextView. Tags in the buffer may override this setting for some ranges of text.

get_hadjustment()[source]

Returns:

pointer to the horizontal Gtk.Adjustment

Return type:

Gtk.Adjustment

Gets the horizontal-scrolling Gtk.Adjustment.

New in version 2.22.

get_indent()[source]

Returns:

number of pixels of indentation

Return type:

int

Gets the default indentation of paragraphs in self. Tags in the view’s buffer may override the default. The indentation may be negative.

get_input_hints()[source]

Return type:

Gtk.InputHints

Gets the value of the Gtk.TextView :input-hints property.

New in version 3.6.

get_input_purpose()[source]

Return type:

Gtk.InputPurpose

Gets the value of the Gtk.TextView :input-purpose property.

New in version 3.6.

get_iter_at_location(x, y)[source]

Parameters:

Returns:

True if the position is over text

iter:

a Gtk.TextIter

Return type:

(bool, iter: Gtk.TextIter)

Retrieves the iterator at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates withGtk.TextView.window_to_buffer_coords().

get_iter_at_position(x, y)[source]

Parameters:

Returns:

True if the position is over text

iter:

a Gtk.TextIter

trailing:

if non-None, location to store an integer indicating where in the grapheme the user clicked. It will either be zero, or the number of characters in the grapheme. 0 represents the trailing edge of the grapheme.

Return type:

(bool, iter: Gtk.TextIter, trailing: int)

Retrieves the iterator pointing to the character at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates withGtk.TextView.window_to_buffer_coords().

Note that this is different from Gtk.TextView.get_iter_at_location(), which returns cursor locations, i.e. positions between characters.

New in version 2.6.

get_iter_location(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

bounds of the character at iter

Return type:

location: Gdk.Rectangle

Gets a rectangle which roughly contains the character at iter. The rectangle position is in buffer coordinates; useGtk.TextView.buffer_to_window_coords() to convert these coordinates to coordinates for one of the windows in the text view.

get_justification()[source]

Returns:

default justification

Return type:

Gtk.Justification

Gets the default justification of paragraphs in self. Tags in the buffer may override the default.

get_left_margin()[source]

Returns:

left margin in pixels

Return type:

int

Gets the default left margin size of paragraphs in the self. Tags in the buffer may override the default.

get_line_at_y(y)[source]

Parameters:

y (int) – a y coordinate

Returns:

target_iter:

a Gtk.TextIter

line_top:

return location for top coordinate of the line

Return type:

(target_iter: Gtk.TextIter, line_top: int)

Gets the Gtk.TextIter at the start of the line containing the coordinate y. y is in buffer coordinates, convert from window coordinates with Gtk.TextView.window_to_buffer_coords(). If non-None, line_top will be filled with the coordinate of the top edge of the line.

get_line_yrange(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

y:

return location for a y coordinate

height:

return location for a height

Return type:

(y: int, height: int)

Gets the y coordinate of the top of the line containing iter, and the height of the line. The coordinate is a buffer coordinate; convert to window coordinates with Gtk.TextView.buffer_to_window_coords().

get_monospace()[source]

Returns:

True if monospace fonts are desired

Return type:

bool

Gets the value of the Gtk.TextView :monospace property.

New in version 3.16.

get_overwrite()[source]

Returns:

whether self is in overwrite mode or not.

Return type:

bool

Returns whether the Gtk.TextView is in overwrite mode or not.

New in version 2.4.

get_pixels_above_lines()[source]

Returns:

default number of pixels above paragraphs

Return type:

int

Gets the default number of pixels to put above paragraphs. Adding this function with Gtk.TextView.get_pixels_below_lines() is equal to the line space between each paragraph.

get_pixels_below_lines()[source]

Returns:

default number of blank pixels below paragraphs

Return type:

int

Gets the value set by Gtk.TextView.set_pixels_below_lines().

The line space is the sum of the value returned by this function and the value returned by Gtk.TextView.get_pixels_above_lines().

get_pixels_inside_wrap()[source]

Returns:

default number of pixels of blank space between wrapped lines

Return type:

int

Gets the value set by Gtk.TextView.set_pixels_inside_wrap().

get_right_margin()[source]

Returns:

right margin in pixels

Return type:

int

Gets the default right margin for text in self. Tags in the buffer may override the default.

get_tabs()[source]

Returns:

copy of default tab array, or None if “standard” tabs are used; must be freed with Pango.TabArray.free().

Return type:

Pango.TabArray or None

Gets the default tabs for self. Tags in the buffer may override the defaults. The returned array will be None if “standard” (8-space) tabs are used. Free the return value with Pango.TabArray.free().

get_top_margin()[source]

Returns:

top margin in pixels

Return type:

int

Gets the top margin for text in the self.

New in version 3.18.

get_vadjustment()[source]

Returns:

pointer to the vertical Gtk.Adjustment

Return type:

Gtk.Adjustment

Gets the vertical-scrolling Gtk.Adjustment.

New in version 2.22.

get_visible_rect()[source]

Returns:

rectangle to fill

Return type:

visible_rect: Gdk.Rectangle

Fills visible_rect with the currently-visible region of the buffer, in buffer coordinates. Convert to window coordinates with Gtk.TextView.buffer_to_window_coords().

get_window(win)[source]

Parameters:

win (Gtk.TextWindowType) – window to get

Returns:

a Gdk.Window, or None

Return type:

Gdk.Window or None

Retrieves the Gdk.Window corresponding to an area of the text view; possible windows include the overall widget window, child windows on the left, right, top, bottom, and the window that displays the text buffer. Windows are None and nonexistent if their width or height is 0, and are nonexistent before the widget has been realized.

get_window_type(window)[source]

Parameters:

window (Gdk.Window) – a window type

Returns:

the window type.

Return type:

Gtk.TextWindowType

Usually used to find out which window an event corresponds to.

If you connect to an event signal on self, this function should be called on event->window to see which window it was.

get_wrap_mode()[source]

Returns:

the line wrap setting

Return type:

Gtk.WrapMode

Gets the line wrapping for the view.

im_context_filter_keypress(event)[source]

Parameters:

event (Gdk.EventKey) – the key event

Returns:

True if the input method handled the key event.

Return type:

bool

Allow the Gtk.TextView input method to internally handle key press and release events. If this function returns True, then no further processing should be done for this key event. SeeGtk.IMContext.filter_keypress().

Note that you are expected to call this function from your handler when overriding key event handling. This is needed in the case when you need to insert your own key handling between the input method and the default key event handling of the Gtk.TextView.

static gboolean gtk_foo_bar_key_press_event (GtkWidget *widget, GdkEventKey *event) { guint keyval;

gdk_event_get_keyval ((GdkEvent*)event, &keyval);

if (keyval == GDK_KEY_Return || keyval == GDK_KEY_KP_Enter) { if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (widget), event)) return TRUE; }

// Do some stuff

return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event); }

New in version 2.22.

move_child(child, xpos, ypos)[source]

Parameters:

Updates the position of a child, as for Gtk.TextView.add_child_in_window().

move_mark_onscreen(mark)[source]

Parameters:

mark (Gtk.TextMark) – a Gtk.TextMark

Returns:

True if the mark moved (wasn’t already onscreen)

Return type:

bool

Moves a mark within the buffer so that it’s located within the currently-visible text area.

move_visually(iter, count)[source]

Parameters:

Returns:

True if iter moved and is not on the end iterator

Return type:

bool

Move the iterator a given number of characters visually, treating it as the strong cursor position. If count is positive, then the new strong cursor position will be count positions to the right of the old cursor position. If count is negative then the new strong cursor position will be count positions to the left of the old cursor position.

In the presence of bi-directional text, the correspondence between logical and visual order will depend on the direction of the current run, and there may be jumps when the cursor is moved off of the end of a run.

place_cursor_onscreen()[source]

Returns:

True if the cursor had to be moved.

Return type:

bool

Moves the cursor to the currently visible region of the buffer, it it isn’t there already.

reset_cursor_blink()[source]

Ensures that the cursor is shown (i.e. not in an ‘off’ blink interval) and resets the time that it will stay blinking (or visible, in case blinking is disabled).

This function should be called in response to user input (e.g. from derived classes that override the textview’sGtk.Widget ::key-press-event handler).

New in version 3.20.

reset_im_context()[source]

Reset the input method context of the text view if needed.

This can be necessary in the case where modifying the buffer would confuse on-going input method behavior.

New in version 2.22.

scroll_mark_onscreen(mark)[source]

Parameters:

mark (Gtk.TextMark) – a mark in the buffer for self

Scrolls self the minimum distance such that mark is contained within the visible area of the widget.

scroll_to_iter(iter, within_margin, use_align, xalign, yalign)[source]

Parameters:

Returns:

True if scrolling occurred

Return type:

bool

Scrolls self so that iter is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is False, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of sizewithin_margin.

Note that this function uses the currently-computed height of the lines in the text buffer. Line heights are computed in an idle handler; so this function may not have the desired effect if it’s called before the height computations. To avoid oddness, consider using Gtk.TextView.scroll_to_mark() which saves a point to be scrolled to after line validation.

scroll_to_mark(mark, within_margin, use_align, xalign, yalign)[source]

Parameters:

Scrolls self so that mark is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is False, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of sizewithin_margin.

set_accepts_tab(accepts_tab)[source]

Parameters:

accepts_tab (bool) – True if pressing the Tab key should insert a tab character, False, if pressing the Tab key should move the keyboard focus.

Sets the behavior of the text widget when the Tab key is pressed. If accepts_tab is True, a tab character is inserted. If accepts_tabis False the keyboard focus is moved to the next widget in the focus chain.

New in version 2.4.

set_border_window_size(type, size)[source]

Parameters:

Sets the width of Gtk.TextWindowType.LEFT or Gtk.TextWindowType.RIGHT, or the height of Gtk.TextWindowType.TOP or Gtk.TextWindowType.BOTTOM. Automatically destroys the corresponding window if the size is set to 0, and creates the window if the size is set to non-zero. This function can only be used for the “border windows”, and it won’t work with Gtk.TextWindowType.WIDGET, Gtk.TextWindowType.TEXT, orGtk.TextWindowType.PRIVATE.

set_bottom_margin(bottom_margin)[source]

Parameters:

bottom_margin (int) – bottom margin in pixels

Sets the bottom margin for text in self.

Note that this function is confusingly named. In CSS terms, the value set here is padding.

New in version 3.18.

set_buffer(buffer)[source]

Parameters:

buffer (Gtk.TextBuffer or None) – a Gtk.TextBuffer

Sets buffer as the buffer being displayed by self. The previous buffer displayed by the text view is unreferenced, and a reference is added to buffer. If you owned a reference to buffer before passing it to this function, you must remove that reference yourself; Gtk.TextViewwill not “adopt” it.

set_cursor_visible(setting)[source]

Parameters:

setting (bool) – whether to show the insertion cursor

Toggles whether the insertion point should be displayed. A buffer with no editable text probably shouldn’t have a visible cursor, so you may want to turn the cursor off.

Note that this property may be overridden by theGtk.Settings :gtk-keynave-use-caret settings.

set_editable(setting)[source]

Parameters:

setting (bool) – whether it’s editable

Sets the default editability of the Gtk.TextView. You can override this default setting with tags in the buffer, using the “editable” attribute of tags.

set_indent(indent)[source]

Parameters:

indent (int) – indentation in pixels

Sets the default indentation for paragraphs in self. Tags in the buffer may override the default.

set_input_hints(hints)[source]

Parameters:

hints (Gtk.InputHints) – the hints

Sets the Gtk.TextView :input-hints property, which allows input methods to fine-tune their behaviour.

New in version 3.6.

set_input_purpose(purpose)[source]

Parameters:

purpose (Gtk.InputPurpose) – the purpose

Sets the Gtk.TextView :input-purpose property which can be used by on-screen keyboards and other input methods to adjust their behaviour.

New in version 3.6.

set_justification(justification)[source]

Parameters:

justification (Gtk.Justification) – justification

Sets the default justification of text in self. Tags in the view’s buffer may override the default.

set_left_margin(left_margin)[source]

Parameters:

left_margin (int) – left margin in pixels

Sets the default left margin for text in self. Tags in the buffer may override the default.

Note that this function is confusingly named. In CSS terms, the value set here is padding.

set_monospace(monospace)[source]

Parameters:

monospace (bool) – True to request monospace styling

Sets the Gtk.TextView :monospace property, which indicates that the text view should use monospace fonts.

New in version 3.16.

set_overwrite(overwrite)[source]

Parameters:

overwrite (bool) – True to turn on overwrite mode, False to turn it off

Changes the Gtk.TextView overwrite mode.

New in version 2.4.

set_pixels_above_lines(pixels_above_lines)[source]

Parameters:

pixels_above_lines (int) – pixels above paragraphs

Sets the default number of blank pixels above paragraphs in self. Tags in the buffer for self may override the defaults.

set_pixels_below_lines(pixels_below_lines)[source]

Parameters:

pixels_below_lines (int) – pixels below paragraphs

Sets the default number of pixels of blank space to put below paragraphs in self. May be overridden by tags applied to self’s buffer.

set_pixels_inside_wrap(pixels_inside_wrap)[source]

Parameters:

pixels_inside_wrap (int) – default number of pixels between wrapped lines

Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. May be overridden by tags in self’s buffer.

set_right_margin(right_margin)[source]

Parameters:

right_margin (int) – right margin in pixels

Sets the default right margin for text in the text view. Tags in the buffer may override the default.

Note that this function is confusingly named. In CSS terms, the value set here is padding.

set_tabs(tabs)[source]

Parameters:

tabs (Pango.TabArray) – tabs as a Pango.TabArray

Sets the default tab stops for paragraphs in self. Tags in the buffer may override the default.

set_top_margin(top_margin)[source]

Parameters:

top_margin (int) – top margin in pixels

Sets the top margin for text in self.

Note that this function is confusingly named. In CSS terms, the value set here is padding.

New in version 3.18.

set_wrap_mode(wrap_mode)[source]

Parameters:

wrap_mode (Gtk.WrapMode) – a Gtk.WrapMode

Sets the line wrapping for the view.

starts_display_line(iter)[source]

Parameters:

iter (Gtk.TextIter) – a Gtk.TextIter

Returns:

True if iter begins a wrapped line

Return type:

bool

Determines whether iter is at the start of a display line. See Gtk.TextView.forward_display_line() for an explanation of display lines vs. paragraphs.

window_to_buffer_coords(win, window_x, window_y)[source]

Parameters:

Returns:

buffer_x:

buffer x coordinate return location or None

buffer_y:

buffer y coordinate return location or None

Return type:

(buffer_x: int, buffer_y: int)

Converts coordinates on the window identified by win to buffer coordinates, storing the result in (buffer_x,`buffer_y`).

Note that you can’t convert coordinates for a nonexisting window (seeGtk.TextView.set_border_window_size()).

do_backspace() virtual

The class handler for the Gtk.TextView ::backspacekeybinding signal.

do_copy_clipboard() virtual

The class handler for the #GtkTextview::copy-clipboard keybinding signal.

do_cut_clipboard() virtual

The class handler for the Gtk.TextView ::cut-clipboardkeybinding signal

do_delete_from_cursor(type, count) virtual

Parameters:

The class handler for the Gtk.TextView ::delete-from-cursorkeybinding signal.

do_draw_layer(layer, cr) virtual

Parameters:

The draw_layer vfunc is called before and after the text view is drawing its own text. Applications can override this vfunc in a subclass to draw customized content underneath or above the text. In the Gtk.TextViewLayer.BELOW_TEXT and Gtk.TextViewLayer.ABOVE_TEXTthe drawing is done in the buffer coordinate space, but the older (deprecated) layers Gtk.TextViewLayer.BELOW and Gtk.TextViewLayer.ABOVE work in viewport coordinates, which makes them unnecessarily hard to use.

New in version 3.14.

do_extend_selection(granularity, location, start, end) virtual

Parameters:

Return type:

bool

The class handler for the Gtk.TextView ::extend-selectionsignal.

New in version 3.16.

do_insert_at_cursor(str) virtual

Parameters:

str (str) –

The class handler for the Gtk.TextView ::insert-at-cursorkeybinding signal.

do_insert_emoji() virtual

do_move_cursor(step, count, extend_selection) virtual

Parameters:

The class handler for the Gtk.TextView ::move-cursorkeybinding signal.

do_paste_clipboard() virtual

The class handler for the Gtk.TextView ::paste-clipboardkeybinding signal.

Parameters:

popup (Gtk.Widget) –

The class handler for the Gtk.TextView ::populate-popupsignal.

do_set_anchor() virtual

The class handler for the Gtk.TextView ::set-anchorkeybinding signal.

do_toggle_overwrite() virtual

The class handler for the Gtk.TextView ::toggle-overwritekeybinding signal.

Signal Details

Gtk.TextView.signals.backspace(text_view)

Signal Name:

backspace

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::backspace signal is akeybinding signalwhich gets emitted when the user asks for it.

The default bindings for this signal are Backspace and Shift-Backspace.

Gtk.TextView.signals.copy_clipboard(text_view)

Signal Name:

copy-clipboard

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::copy-clipboard signal is akeybinding signalwhich gets emitted to copy the selection to the clipboard.

The default bindings for this signal are Ctrl-c and Ctrl-Insert.

Gtk.TextView.signals.cut_clipboard(text_view)

Signal Name:

cut-clipboard

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::cut-clipboard signal is akeybinding signalwhich gets emitted to cut the selection to the clipboard.

The default bindings for this signal are Ctrl-x and Shift-Delete.

Gtk.TextView.signals.delete_from_cursor(text_view, type, count)

Signal Name:

delete-from-cursor

Flags:

RUN_LAST, ACTION

Parameters:

The ::delete-from-cursor signal is akeybinding signalwhich gets emitted when the user initiates a text deletion.

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 Delete for deleting a character, Ctrl-Delete for deleting a word and Ctrl-Backspace for deleting a word backwords.

Gtk.TextView.signals.extend_selection(text_view, granularity, location, start, end)

Signal Name:

extend-selection

Flags:

RUN_LAST

Parameters:

Returns:

Gdk.EVENT_STOP to stop other handlers from being invoked for the event. Gdk.EVENT_PROPAGATE to propagate the event further.

Return type:

bool

The ::extend-selection signal is emitted when the selection needs to be extended at location.

New in version 3.16.

Gtk.TextView.signals.insert_at_cursor(text_view, string)

Signal Name:

insert-at-cursor

Flags:

RUN_LAST, ACTION

Parameters:

The ::insert-at-cursor signal is akeybinding signalwhich gets emitted when the user initiates the insertion of a fixed string at the cursor.

This signal has no default bindings.

Gtk.TextView.signals.insert_emoji(text_view)

Signal Name:

insert-emoji

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::insert-emoji signal is akeybinding signalwhich gets emitted to present the Emoji chooser for the text_view.

The default bindings for this signal are Ctrl-. and Ctrl-;

New in version 3.22.27.

Gtk.TextView.signals.move_cursor(text_view, step, count, extend_selection)

Signal Name:

move-cursor

Flags:

RUN_LAST, ACTION

Parameters:

The ::move-cursor signal is akeybinding signalwhich gets emitted when the user initiates a cursor movement. If the cursor is not visible in text_view, this signal causes the viewport to be moved instead.

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 Shift modifier extends the selection, the variant without the Shift modifer does not. There are too many key combinations to list them all here.

Gtk.TextView.signals.move_viewport(text_view, step, count)

Signal Name:

move-viewport

Flags:

RUN_LAST, ACTION

Parameters:

The ::move-viewport signal is akeybinding signalwhich can be bound to key combinations to allow the user to move the viewport, i.e. change what part of the text view is visible in a containing scrolled window.

There are no default bindings for this signal.

Gtk.TextView.signals.paste_clipboard(text_view)

Signal Name:

paste-clipboard

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::paste-clipboard signal is akeybinding signalwhich gets emitted to paste the contents of the clipboard into the text view.

The default bindings for this signal are Ctrl-v and Shift-Insert.

Signal Name:

populate-popup

Flags:

RUN_LAST

Parameters:

The ::populate-popup signal gets emitted before showing the context menu of the text view.

If you need to add items to the context menu, connect to this signal and append your items to the popup, which will be a Gtk.Menu in this case.

If Gtk.TextView :populate-all is True, this signal will also be emitted to populate touch popups. In this case,popup will be a different container, e.g. a Gtk.Toolbar.

The signal handler should not make assumptions about the type of widget, but check whether popup is a Gtk.Menuor Gtk.Toolbar or another kind of container.

Gtk.TextView.signals.preedit_changed(text_view, preedit)

Signal Name:

preedit-changed

Flags:

RUN_LAST, ACTION

Parameters:

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.

This signal is only emitted if the text at the given position is actually editable.

New in version 2.20.

Gtk.TextView.signals.select_all(text_view, select)

Signal Name:

select-all

Flags:

RUN_LAST, ACTION

Parameters:

The ::select-all signal is akeybinding signalwhich gets emitted to select or unselect the complete contents of the text view.

The default bindings for this signal are Ctrl-a and Ctrl-/ for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.

Gtk.TextView.signals.set_anchor(text_view)

Signal Name:

set-anchor

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::set-anchor signal is akeybinding signalwhich gets emitted when the user initiates setting the “anchor” mark. The “anchor” mark gets placed at the same position as the “insert” mark.

This signal has no default bindings.

Gtk.TextView.signals.toggle_cursor_visible(text_view)

Signal Name:

toggle-cursor-visible

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::toggle-cursor-visible signal is akeybinding signalwhich gets emitted to toggle the Gtk.TextView :cursor-visibleproperty.

The default binding for this signal is F7.

Gtk.TextView.signals.toggle_overwrite(text_view)

Signal Name:

toggle-overwrite

Flags:

RUN_LAST, ACTION

Parameters:

text_view (Gtk.TextView) – The object which received the signal

The ::toggle-overwrite signal is akeybinding signalwhich gets emitted to toggle the overwrite mode of the text view.

The default bindings for this signal is Insert.

Property Details

Gtk.TextView.props.accepts_tab

Name:

accepts-tab

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether Tab will result in a tab character being entered

Gtk.TextView.props.bottom_margin

Name:

bottom-margin

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The bottom margin for text in the text view.

Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.

Don’t confuse this property with Gtk.Widget :margin-bottom.

New in version 3.18.

Gtk.TextView.props.buffer

Name:

buffer

Type:

Gtk.TextBuffer

Default Value:

None

Flags:

READABLE, WRITABLE

The buffer which is displayed

Gtk.TextView.props.cursor_visible

Name:

cursor-visible

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If the insertion cursor is shown

Gtk.TextView.props.editable

Name:

editable

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the text can be modified by the user

Gtk.TextView.props.im_module

Name:

im-module

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

Which IM (input method) module should be used for this text_view. See Gtk.IMContext.

Setting this to a non-None value overrides the system-wide IM module setting. See the Gtk.Settings Gtk.Settings :gtk-im-module property.

New in version 2.16.

Gtk.TextView.props.indent

Name:

indent

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Amount to indent the paragraph, in pixels

Gtk.TextView.props.input_hints

Name:

input-hints

Type:

Gtk.InputHints

Default Value:

Gtk.InputHints.NONE

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Additional hints (beyond Gtk.TextView :input-purpose) that allow input methods to fine-tune their behaviour.

New in version 3.6.

Gtk.TextView.props.input_purpose

Name:

input-purpose

Type:

Gtk.InputPurpose

Default Value:

Gtk.InputPurpose.FREE_FORM

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The purpose of this text field.

This property can be used by on-screen keyboards and other input methods to adjust their behaviour.

New in version 3.6.

Gtk.TextView.props.justification

Name:

justification

Type:

Gtk.Justification

Default Value:

Gtk.Justification.LEFT

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Left, right, or center justification

Gtk.TextView.props.left_margin

Name:

left-margin

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The default left margin for text in the text view. Tags in the buffer may override the default.

Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.

Don’t confuse this property with Gtk.Widget :margin-left.

Gtk.TextView.props.monospace

Name:

monospace

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to use a monospace font

Gtk.TextView.props.overwrite

Name:

overwrite

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether entered text overwrites existing contents

Gtk.TextView.props.pixels_above_lines

Name:

pixels-above-lines

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Pixels of blank space above paragraphs

Gtk.TextView.props.pixels_below_lines

Name:

pixels-below-lines

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Pixels of blank space below paragraphs

Gtk.TextView.props.pixels_inside_wrap

Name:

pixels-inside-wrap

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Pixels of blank space between wrapped lines in a paragraph

Gtk.TextView.props.populate_all

Name:

populate-all

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If :populate-all is True, the Gtk.TextView ::populate-popupsignal is also emitted for touch popups.

New in version 3.8.

Gtk.TextView.props.right_margin

Name:

right-margin

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The default right margin for text in the text view. Tags in the buffer may override the default.

Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.

Don’t confuse this property with Gtk.Widget :margin-right.

Gtk.TextView.props.tabs

Name:

tabs

Type:

Pango.TabArray

Default Value:

None

Flags:

READABLE, WRITABLE

Custom tabs for this text

Gtk.TextView.props.top_margin

Name:

top-margin

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The top margin for text in the text view.

Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.

Don’t confuse this property with Gtk.Widget :margin-top.

New in version 3.18.

Gtk.TextView.props.wrap_mode

Name:

wrap-mode

Type:

Gtk.WrapMode

Default Value:

Gtk.WrapMode.NONE

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to wrap lines never, at word boundaries, or at character boundaries