:right-sidebar: True TextView =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: TextView(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.AccessibleText`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`, :class:`~gi.repository.Gtk.Scrollable` A widget that displays the contents of a :obj:`~gi.repository.Gtk.TextBuffer`. .. image:: https://docs.gtk.org/gtk4/multiline-text.png You may wish to begin by reading the `conceptual overview `_, which gives an overview of all the objects and data types related to the text widget and how they work together. CSS nodes --------- .. code-block:: :dedent: textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├── border.bottom ╰── [window.popup] ``GtkTextView`` 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. Accessibility ------------- ``GtkTextView`` uses the :const:`~gi.repository.Gtk.AccessibleRole.TEXT_BOX` role. Constructors ------------ .. rst-class:: interim-class .. class:: TextView :no-index: .. classmethod:: new() -> ~gi.repository.Gtk.Widget Creates a new ``GtkTextView``. If you don’t call :obj:`~gi.repository.Gtk.TextView.set_buffer` before using the text view, an empty default buffer will be created for you. Get the buffer with :obj:`~gi.repository.Gtk.TextView.get_buffer`. If you want to specify your own buffer, consider :obj:`~gi.repository.Gtk.TextView.new_with_buffer`. .. classmethod:: new_with_buffer(buffer: ~gi.repository.Gtk.TextBuffer) -> ~gi.repository.Gtk.Widget Creates a new ``GtkTextView`` widget displaying the buffer ``buffer``. One buffer can be shared among many widgets. ``buffer`` may be :const:`None` to create a default buffer, in which case this function is equivalent to :obj:`~gi.repository.Gtk.TextView.new`. The text view adds its own reference count to the buffer; it does not take over an existing reference. :param buffer: a ``GtkTextBuffer`` Methods ------- .. rst-class:: interim-class .. class:: TextView :no-index: .. method:: add_child_at_anchor(child: ~gi.repository.Gtk.Widget, anchor: ~gi.repository.Gtk.TextChildAnchor) -> None Adds a child widget in the text buffer, at the given ``anchor``. :param child: a ``GtkWidget`` :param anchor: a ``GtkTextChildAnchor`` in the ``GtkTextBuffer`` for ``text_view`` .. method:: add_overlay(child: ~gi.repository.Gtk.Widget, xpos: int, ypos: int) -> None Adds ``child`` at a fixed coordinate in the ``GtkTextView``'s text window. The ``xpos`` and ``ypos`` must be in buffer coordinates (see :obj:`~gi.repository.Gtk.TextView.get_iter_location` to convert to buffer coordinates). ``child`` will scroll with the text view. If instead you want a widget that will not move with the ``GtkTextView`` contents see ``GtkOverlay``. :param child: a ``GtkWidget`` :param xpos: X position of child in window coordinates :param ypos: Y position of child in window coordinates .. method:: backward_display_line(iter: ~gi.repository.Gtk.TextIter) -> 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. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. 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 ``GtkTextBuffer``. :param iter: a ``GtkTextIter`` .. method:: backward_display_line_start(iter: ~gi.repository.Gtk.TextIter) -> 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. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. 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 ``GtkTextBuffer``. :param iter: a ``GtkTextIter`` .. method:: buffer_to_window_coords(win: ~gi.repository.Gtk.TextWindowType, buffer_x: int, buffer_y: int) -> tuple[int, int] Converts buffer coordinates to window coordinates. :param win: a ``GtkTextWindowType`` :param buffer_x: buffer x coordinate :param buffer_y: buffer y coordinate .. method:: forward_display_line(iter: ~gi.repository.Gtk.TextIter) -> 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. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. 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 ``GtkTextBuffer``. :param iter: a ``GtkTextIter`` .. method:: forward_display_line_end(iter: ~gi.repository.Gtk.TextIter) -> 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. Display lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same. 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 ``GtkTextBuffer``. :param iter: a ``GtkTextIter`` .. method:: get_accepts_tab() -> bool Returns whether pressing the :kbd:`Tab` key inserts a tab characters. See :obj:`~gi.repository.Gtk.TextView.set_accepts_tab`. .. method:: get_bottom_margin() -> int Gets the bottom margin for text in the ``text_view``. .. method:: get_buffer() -> ~gi.repository.Gtk.TextBuffer Returns the ``GtkTextBuffer`` 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. .. method:: get_cursor_locations(iter: ~gi.repository.Gtk.TextIter | None = None) -> tuple[~gi.repository.Gdk.Rectangle, ~gi.repository.Gdk.Rectangle] Determine the positions of the strong and weak cursors if the insertion point is at ``iter``. 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 :const:`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; use :obj:`~gi.repository.Gtk.TextView.buffer_to_window_coords` to convert these coordinates to coordinates for one of the windows in the text view. :param iter: a ``GtkTextIter`` .. method:: get_cursor_visible() -> bool Find out whether the cursor should be displayed. .. method:: get_editable() -> bool Returns the default editability of the ``GtkTextView``. Tags in the buffer may override this setting for some ranges of text. .. method:: get_extra_menu() -> ~gi.repository.Gio.MenuModel Gets the menu model that gets added to the context menu or :const:`None` if none has been set. .. method:: get_gutter(win: ~gi.repository.Gtk.TextWindowType) -> ~gi.repository.Gtk.Widget | None Gets a ``GtkWidget`` that has previously been set as gutter. See :obj:`~gi.repository.Gtk.TextView.set_gutter`. ``win`` must be one of :const:`~gi.repository.Gtk.TextWindowType.LEFT`, :const:`~gi.repository.Gtk.TextWindowType.RIGHT`, :const:`~gi.repository.Gtk.TextWindowType.TOP`, or :const:`~gi.repository.Gtk.TextWindowType.BOTTOM`. :param win: a ``GtkTextWindowType`` .. method:: get_indent() -> int Gets the default indentation of paragraphs in ``text_view``. Tags in the view’s buffer may override the default. The indentation may be negative. .. method:: get_input_hints() -> ~gi.repository.Gtk.InputHints Gets the ``input-hints`` of the ``GtkTextView``. .. method:: get_input_purpose() -> ~gi.repository.Gtk.InputPurpose Gets the ``input-purpose`` of the ``GtkTextView``. .. method:: get_iter_at_location(x: int, y: int) -> tuple[bool, ~gi.repository.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 with :obj:`~gi.repository.Gtk.TextView.window_to_buffer_coords`. :param x: x position, in buffer coordinates :param y: y position, in buffer coordinates .. method:: get_iter_at_position(x: int, y: int) -> tuple[bool, ~gi.repository.Gtk.TextIter, 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 with :obj:`~gi.repository.Gtk.TextView.window_to_buffer_coords`. Note that this is different from :obj:`~gi.repository.Gtk.TextView.get_iter_at_location`, which returns cursor locations, i.e. positions between characters. :param x: x position, in buffer coordinates :param y: y position, in buffer coordinates .. method:: get_iter_location(iter: ~gi.repository.Gtk.TextIter) -> ~gi.repository.Gdk.Rectangle Gets a rectangle which roughly contains the character at ``iter``. The rectangle position is in buffer coordinates; use :obj:`~gi.repository.Gtk.TextView.buffer_to_window_coords` to convert these coordinates to coordinates for one of the windows in the text view. :param iter: a ``GtkTextIter`` .. method:: get_justification() -> ~gi.repository.Gtk.Justification Gets the default justification of paragraphs in ``text_view``. Tags in the buffer may override the default. .. method:: get_left_margin() -> int Gets the default left margin size of paragraphs in the ``text_view``. Tags in the buffer may override the default. .. method:: get_line_at_y(y: int) -> tuple[~gi.repository.Gtk.TextIter, int] Gets the ``GtkTextIter`` at the start of the line containing the coordinate ``y``. ``y`` is in buffer coordinates, convert from window coordinates with :obj:`~gi.repository.Gtk.TextView.window_to_buffer_coords`. If non-:const:`None`, ``line_top`` will be filled with the coordinate of the top edge of the line. :param y: a y coordinate .. method:: get_line_yrange(iter: ~gi.repository.Gtk.TextIter) -> tuple[int, 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 :obj:`~gi.repository.Gtk.TextView.buffer_to_window_coords`. :param iter: a ``GtkTextIter`` .. method:: get_ltr_context() -> ~gi.repository.Pango.Context Gets the ``PangoContext`` that is used for rendering LTR directed text layouts. The context may be replaced when CSS changes occur. .. versionadded:: 4.4 .. method:: get_monospace() -> bool Gets whether the ``GtkTextView`` uses monospace styling. .. method:: get_overwrite() -> bool Returns whether the ``GtkTextView`` is in overwrite mode or not. .. method:: get_pixels_above_lines() -> int Gets the default number of pixels to put above paragraphs. Adding this function with :obj:`~gi.repository.Gtk.TextView.get_pixels_below_lines` is equal to the line space between each paragraph. .. method:: get_pixels_below_lines() -> int Gets the default number of pixels to put below paragraphs. The line space is the sum of the value returned by this function and the value returned by :obj:`~gi.repository.Gtk.TextView.get_pixels_above_lines`. .. method:: get_pixels_inside_wrap() -> int Gets the default number of pixels to put between wrapped lines inside a paragraph. .. method:: get_right_margin() -> int Gets the default right margin for text in ``text_view``. Tags in the buffer may override the default. .. method:: get_rtl_context() -> ~gi.repository.Pango.Context Gets the ``PangoContext`` that is used for rendering RTL directed text layouts. The context may be replaced when CSS changes occur. .. versionadded:: 4.4 .. method:: get_tabs() -> ~gi.repository.Pango.TabArray | None Gets the default tabs for ``text_view``. Tags in the buffer may override the defaults. The returned array will be :const:`None` if “standard” (8-space) tabs are used. Free the return value with :obj:`~gi.repository.Pango.TabArray.free`. .. method:: get_top_margin() -> int Gets the top margin for text in the ``text_view``. .. method:: get_visible_rect() -> ~gi.repository.Gdk.Rectangle Fills ``visible_rect`` with the currently-visible region of the buffer, in buffer coordinates. Convert to window coordinates with :obj:`~gi.repository.Gtk.TextView.buffer_to_window_coords`. .. method:: get_wrap_mode() -> ~gi.repository.Gtk.WrapMode Gets the line wrapping for the view. .. method:: im_context_filter_keypress(event: ~gi.repository.Gdk.Event) -> bool Allow the ``GtkTextView`` input method to internally handle key press and release events. If this function returns :const:`True`, then no further processing should be done for this key event. See :obj:`~gi.repository.Gtk.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 ``GtkTextView``. .. code-block:: :dedent: static gboolean gtk_foo_bar_key_press_event (GtkWidget *widget, GdkEvent *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); } :param event: the key event .. method:: move_mark_onscreen(mark: ~gi.repository.Gtk.TextMark) -> bool Moves a mark within the buffer so that it's located within the currently-visible text area. :param mark: a ``GtkTextMark`` .. method:: move_overlay(child: ~gi.repository.Gtk.Widget, xpos: int, ypos: int) -> None Updates the position of a child. See :obj:`~gi.repository.Gtk.TextView.add_overlay`. :param child: a widget already added with :obj:`~gi.repository.Gtk.TextView.add_overlay` :param xpos: new X position in buffer coordinates :param ypos: new Y position in buffer coordinates .. method:: move_visually(iter: ~gi.repository.Gtk.TextIter, count: int) -> 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. :param iter: a ``GtkTextIter`` :param count: number of characters to move (negative moves left, positive moves right) .. method:: place_cursor_onscreen() -> bool Moves the cursor to the currently visible region of the buffer. .. method:: remove(child: ~gi.repository.Gtk.Widget) -> None Removes a child widget from ``text_view``. :param child: the child to remove .. method:: reset_cursor_blink() -> None Ensures that the cursor is shown. This also 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's event handlers). .. method:: reset_im_context() -> None 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. .. method:: scroll_mark_onscreen(mark: ~gi.repository.Gtk.TextMark) -> None Scrolls ``text_view`` the minimum distance such that ``mark`` is contained within the visible area of the widget. :param mark: a mark in the buffer for ``text_view`` .. method:: scroll_to_iter(iter: ~gi.repository.Gtk.TextIter, within_margin: float, use_align: bool, xalign: float, yalign: float) -> bool Scrolls ``text_view`` 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 :const:`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 size ``within_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 :obj:`~gi.repository.Gtk.TextView.scroll_to_mark` which saves a point to be scrolled to after line validation. :param iter: a ``GtkTextIter`` :param within_margin: margin as a [0.0,0.5) fraction of screen size :param use_align: whether to use alignment arguments (if :const:`False`, just get the mark onscreen) :param xalign: horizontal alignment of mark within visible area :param yalign: vertical alignment of mark within visible area .. method:: scroll_to_mark(mark: ~gi.repository.Gtk.TextMark, within_margin: float, use_align: bool, xalign: float, yalign: float) -> None Scrolls ``text_view`` 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 :const:`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 size ``within_margin``. :param mark: a ``GtkTextMark`` :param within_margin: margin as a [0.0,0.5) fraction of screen size :param use_align: whether to use alignment arguments (if :const:`False`, just get the mark onscreen) :param xalign: horizontal alignment of mark within visible area :param yalign: vertical alignment of mark within visible area .. method:: set_accepts_tab(accepts_tab: bool) -> None Sets the behavior of the text widget when the :kbd:`Tab` key is pressed. If ``accepts_tab`` is :const:`True`, a tab character is inserted. If ``accepts_tab`` is :const:`False` the keyboard focus is moved to the next widget in the focus chain. Focus can always be moved using :kbd:`Ctrl`+:kbd:`Tab`. :param accepts_tab: :const:`True` if pressing the Tab key should insert a tab character, :const:`False`, if pressing the Tab key should move the keyboard focus. .. method:: set_bottom_margin(bottom_margin: int) -> None Sets the bottom margin for text in ``text_view``. Note that this function is confusingly named. In CSS terms, the value set here is padding. :param bottom_margin: bottom margin in pixels .. method:: set_buffer(buffer: ~gi.repository.Gtk.TextBuffer | None = None) -> None Sets ``buffer`` as the buffer being displayed by ``text_view``. 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; ``GtkTextView`` will not “adopt” it. :param buffer: a ``GtkTextBuffer`` .. method:: set_cursor_visible(setting: bool) -> None 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 the :obj:`~gi.repository.Gtk.Settings.props.gtk_keynav_use_caret` setting. :param setting: whether to show the insertion cursor .. method:: set_editable(setting: bool) -> None Sets the default editability of the ``GtkTextView``. You can override this default setting with tags in the buffer, using the “editable” attribute of tags. :param setting: whether it’s editable .. method:: set_extra_menu(model: ~gi.repository.Gio.MenuModel | None = None) -> None Sets a menu model to add when constructing the context menu for ``text_view``. You can pass :const:`None` to remove a previously set extra menu. :param model: a ``GMenuModel`` .. method:: set_gutter(win: ~gi.repository.Gtk.TextWindowType, widget: ~gi.repository.Gtk.Widget | None = None) -> None Places ``widget`` into the gutter specified by ``win``. ``win`` must be one of :const:`~gi.repository.Gtk.TextWindowType.LEFT`, :const:`~gi.repository.Gtk.TextWindowType.RIGHT`, :const:`~gi.repository.Gtk.TextWindowType.TOP`, or :const:`~gi.repository.Gtk.TextWindowType.BOTTOM`. :param win: a ``GtkTextWindowType`` :param widget: a ``GtkWidget`` .. method:: set_indent(indent: int) -> None Sets the default indentation for paragraphs in ``text_view``. Tags in the buffer may override the default. :param indent: indentation in pixels .. method:: set_input_hints(hints: ~gi.repository.Gtk.InputHints) -> None Sets the ``input-hints`` of the ``GtkTextView``. The ``input-hints`` allow input methods to fine-tune their behaviour. :param hints: the hints .. method:: set_input_purpose(purpose: ~gi.repository.Gtk.InputPurpose) -> None Sets the ``input-purpose`` of the ``GtkTextView``. The ``input-purpose`` can be used by on-screen keyboards and other input methods to adjust their behaviour. :param purpose: the purpose .. method:: set_justification(justification: ~gi.repository.Gtk.Justification) -> None Sets the default justification of text in ``text_view``. Tags in the view’s buffer may override the default. :param justification: justification .. method:: set_left_margin(left_margin: int) -> None Sets the default left margin for text in ``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. :param left_margin: left margin in pixels .. method:: set_monospace(monospace: bool) -> None Sets whether the ``GtkTextView`` should display text in monospace styling. :param monospace: :const:`True` to request monospace styling .. method:: set_overwrite(overwrite: bool) -> None Changes the ``GtkTextView`` overwrite mode. :param overwrite: :const:`True` to turn on overwrite mode, :const:`False` to turn it off .. method:: set_pixels_above_lines(pixels_above_lines: int) -> None Sets the default number of blank pixels above paragraphs in ``text_view``. Tags in the buffer for ``text_view`` may override the defaults. :param pixels_above_lines: pixels above paragraphs .. method:: set_pixels_below_lines(pixels_below_lines: int) -> None Sets the default number of pixels of blank space to put below paragraphs in ``text_view``. May be overridden by tags applied to ``text_view``’s buffer. :param pixels_below_lines: pixels below paragraphs .. method:: set_pixels_inside_wrap(pixels_inside_wrap: int) -> None Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. May be overridden by tags in ``text_view``’s buffer. :param pixels_inside_wrap: default number of pixels between wrapped lines .. method:: set_right_margin(right_margin: int) -> None 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. :param right_margin: right margin in pixels .. method:: set_tabs(tabs: ~gi.repository.Pango.TabArray) -> None Sets the default tab stops for paragraphs in ``text_view``. Tags in the buffer may override the default. :param tabs: tabs as a ``PangoTabArray`` .. method:: set_top_margin(top_margin: int) -> None Sets the top margin for text in ``text_view``. Note that this function is confusingly named. In CSS terms, the value set here is padding. :param top_margin: top margin in pixels .. method:: set_wrap_mode(wrap_mode: ~gi.repository.Gtk.WrapMode) -> None Sets the line wrapping for the view. :param wrap_mode: a ``GtkWrapMode`` .. method:: starts_display_line(iter: ~gi.repository.Gtk.TextIter) -> bool Determines whether ``iter`` is at the start of a display line. See :obj:`~gi.repository.Gtk.TextView.forward_display_line` for an explanation of display lines vs. paragraphs. :param iter: a ``GtkTextIter`` .. method:: window_to_buffer_coords(win: ~gi.repository.Gtk.TextWindowType, window_x: int, window_y: int) -> tuple[int, int] Converts coordinates on the window identified by ``win`` to buffer coordinates. :param win: a ``GtkTextWindowType`` :param window_x: window x coordinate :param window_y: window y coordinate Properties ---------- .. rst-class:: interim-class .. class:: TextView :no-index: .. attribute:: props.accepts_tab :type: bool Whether Tab will result in a tab character being entered. .. attribute:: props.bottom_margin :type: int 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 :obj:`~gi.repository.Gtk.Widget.props.margin_bottom`. .. attribute:: props.buffer :type: ~gi.repository.Gtk.TextBuffer The buffer which is displayed. .. attribute:: props.cursor_visible :type: bool If the insertion cursor is shown. .. attribute:: props.editable :type: bool .. attribute:: props.extra_menu :type: ~gi.repository.Gio.MenuModel A menu model whose contents will be appended to the context menu. .. attribute:: props.im_module :type: str Which IM (input method) module should be used for this text_view. See :obj:`~gi.repository.Gtk.IMMulticontext`. Setting this to a non-:const:`None` value overrides the system-wide IM module setting. See the GtkSettings :obj:`~gi.repository.Gtk.Settings.props.gtk_im_module` property. .. attribute:: props.indent :type: int Amount to indent the paragraph, in pixels. A negative value of indent will produce a hanging indentation. That is, the first line will have the full width, and subsequent lines will be indented by the absolute value of indent. .. attribute:: props.input_hints :type: ~gi.repository.Gtk.InputHints Additional hints (beyond :obj:`~gi.repository.Gtk.TextView.props.input_purpose`) that allow input methods to fine-tune their behaviour. .. attribute:: props.input_purpose :type: ~gi.repository.Gtk.InputPurpose The purpose of this text field. This property can be used by on-screen keyboards and other input methods to adjust their behaviour. .. attribute:: props.justification :type: ~gi.repository.Gtk.Justification .. attribute:: props.left_margin :type: int 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. .. attribute:: props.monospace :type: bool Whether text should be displayed in a monospace font. If :const:`True`, set the .monospace style class on the text view to indicate that a monospace font is desired. .. attribute:: props.overwrite :type: bool Whether entered text overwrites existing contents. .. attribute:: props.pixels_above_lines :type: int .. attribute:: props.pixels_below_lines :type: int .. attribute:: props.pixels_inside_wrap :type: int .. attribute:: props.right_margin :type: int 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. .. attribute:: props.tabs :type: ~gi.repository.Pango.TabArray .. attribute:: props.top_margin :type: int 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 :obj:`~gi.repository.Gtk.Widget.props.margin_top`. .. attribute:: props.wrap_mode :type: ~gi.repository.Gtk.WrapMode Signals ------- .. rst-class:: interim-class .. class:: TextView.signals :no-index: .. method:: backspace() -> None Gets emitted when the user asks for it. The ::backspace signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Backspace` and :kbd:`Shift`+:kbd:`Backspace`. .. method:: copy_clipboard() -> None Gets emitted to copy the selection to the clipboard. The ::copy-clipboard signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Ctrl`+:kbd:`c` and :kbd:`Ctrl`+:kbd:`Insert`. .. method:: cut_clipboard() -> None Gets emitted to cut the selection to the clipboard. The ::cut-clipboard signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Ctrl`+:kbd:`x` and :kbd:`Shift`+:kbd:`Delete`. .. method:: delete_from_cursor(type: ~gi.repository.Gtk.DeleteType, count: int) -> None Gets emitted when the user initiates a text deletion. The ::delete-from-cursor signal is a `keybinding signal `_. If the ``type`` is :const:`~gi.repository.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` for deleting a character, :kbd:`Ctrl`+:kbd:`Delete` for deleting a word and :kbd:`Ctrl`+:kbd:`Backspace` for deleting a word backwards. :param type: the granularity of the deletion, as a ``GtkDeleteType`` :param count: the number of ``type`` units to delete .. method:: extend_selection(granularity: ~gi.repository.Gtk.TextExtendSelection, location: ~gi.repository.Gtk.TextIter, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> bool Emitted when the selection needs to be extended at ``location``. :param granularity: the granularity type :param location: the location where to extend the selection :param start: where the selection should start :param end: where the selection should end .. method:: insert_at_cursor(string: str) -> None Gets emitted when the user initiates the insertion of a fixed string at the cursor. The ::insert-at-cursor signal is a `keybinding signal `_. This signal has no default bindings. :param string: the string to insert .. method:: insert_emoji() -> None Gets emitted to present the Emoji chooser for the ``text_view``. The ::insert-emoji signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Ctrl`+. and :kbd:`Ctrl`+; .. method:: move_cursor(step: ~gi.repository.Gtk.MovementStep, count: int, extend_selection: bool) -> None Gets emitted when the user initiates a cursor movement. The ::move-cursor signal is a `keybinding signal `_. 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 :func:`~gi.repository.GObject.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` 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:`↓` move by individual characters/lines - :kbd:`Ctrl`+:kbd:`←`, etc. move by words/paragraphs - :kbd:`Home` and :kbd:`End` move to the ends of the buffer - :kbd:`PgUp` and :kbd:`PgDn` move vertically by pages - :kbd:`Ctrl`+:kbd:`PgUp` and :kbd:`Ctrl`+:kbd:`PgDn` move horizontally by pages :param step: the granularity of the move, as a ``GtkMovementStep`` :param count: the number of ``step`` units to move :param extend_selection: :const:`True` if the move should extend the selection .. method:: move_viewport(step: ~gi.repository.Gtk.ScrollStep, count: int) -> None Gets emitted to move the 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. change what part of the text view is visible in a containing scrolled window. There are no default bindings for this signal. :param step: the granularity of the movement, as a ``GtkScrollStep`` :param count: the number of ``step`` units to move .. method:: paste_clipboard() -> None Gets emitted to paste the contents of the clipboard into the text view. The ::paste-clipboard signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Ctrl`+:kbd:`v` and :kbd:`Shift`+:kbd:`Insert`. .. method:: preedit_changed(preedit: str) -> None Emitted when preedit text of the active IM 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. This signal is only emitted if the text at the given position is actually editable. :param preedit: the current preedit string .. method:: select_all(select: bool) -> None Gets emitted to select or unselect the complete contents of the text view. The ::select-all signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Ctrl`+:kbd:`a` and :kbd:`Ctrl`+/ for selecting and :kbd:`Shift`+:kbd:`Ctrl`+:kbd:`a` and :kbd:`Ctrl`+\ for unselecting. :param select: :const:`True` to select, :const:`False` to unselect .. method:: set_anchor() -> None Gets emitted when the user initiates settings the "anchor" mark. The ::set-anchor signal is a `keybinding signal `_ which 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. .. method:: toggle_cursor_visible() -> None Gets emitted to toggle the ``cursor-visible`` property. The ::toggle-cursor-visible signal is a `keybinding signal `_. The default binding for this signal is :kbd:`F7`. .. method:: toggle_overwrite() -> None Gets emitted to toggle the overwrite mode of the text view. The ::toggle-overwrite signal is a `keybinding signal `_. The default binding for this signal is :kbd:`Insert`. Virtual Methods --------------- .. rst-class:: interim-class .. class:: TextView :no-index: .. method:: do_backspace() -> None The class handler for the ``GtkTextView::backspace`` keybinding signal. .. method:: do_copy_clipboard() -> None The class handler for the ``GtkTextView::copy-clipboard`` keybinding signal. .. method:: do_cut_clipboard() -> None The class handler for the ``GtkTextView::cut-clipboard`` keybinding signal .. method:: do_delete_from_cursor(type: ~gi.repository.Gtk.DeleteType, count: int) -> None The class handler for the ``GtkTextView::delete-from-cursor`` keybinding signal. :param type: :param count: .. method:: do_extend_selection(granularity: ~gi.repository.Gtk.TextExtendSelection, location: ~gi.repository.Gtk.TextIter, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> bool The class handler for the ``GtkTextView::extend-selection`` signal. :param granularity: :param location: :param start: :param end: .. method:: do_insert_at_cursor(str: str) -> None The class handler for the ``GtkTextView::insert-at-cursor`` keybinding signal. :param str: .. method:: do_insert_emoji() -> None The class handler for the ``GtkTextView::insert-emoji`` signal. .. method:: do_move_cursor(step: ~gi.repository.Gtk.MovementStep, count: int, extend_selection: bool) -> None The class handler for the ``GtkTextView::move-cursor`` keybinding signal. :param step: :param count: :param extend_selection: .. method:: do_paste_clipboard() -> None The class handler for the ``GtkTextView::paste-clipboard`` keybinding signal. .. method:: do_set_anchor() -> None The class handler for the ``GtkTextView::set-anchor`` keybinding signal. .. method:: do_snapshot_layer(layer: ~gi.repository.Gtk.TextViewLayer, snapshot: ~gi.repository.Gtk.Snapshot) -> None The snapshot_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 :const:`~gi.repository.Gtk.TextViewLayer.BELOW_TEXT` and :const:`~gi.repository.Gtk.TextViewLayer.ABOVE_TEXT` layers the drawing is done in the buffer coordinate space. :param layer: :param snapshot: .. method:: do_toggle_overwrite() -> None The class handler for the ``GtkTextView::toggle-overwrite`` keybinding signal. Fields ------ .. rst-class:: interim-class .. class:: TextView :no-index: .. attribute:: parent_instance .. attribute:: priv