:right-sidebar: True TextBuffer =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: TextBuffer(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Stores text and attributes for display in a ``GtkTextView``. You may wish to begin by reading the `text widget conceptual overview `_, which gives an overview of all the objects and data types related to the text widget and how they work together. GtkTextBuffer can support undoing changes to the buffer content, see :obj:`~gi.repository.Gtk.TextBuffer.set_enable_undo`. Constructors ------------ .. rst-class:: interim-class .. class:: TextBuffer :no-index: .. classmethod:: new(table: ~gi.repository.Gtk.TextTagTable | None = None) -> ~gi.repository.Gtk.TextBuffer Creates a new text buffer. :param table: a tag table, or :const:`None` to create a new one Methods ------- .. rst-class:: interim-class .. class:: TextBuffer :no-index: .. method:: add_mark(mark: ~gi.repository.Gtk.TextMark, where: ~gi.repository.Gtk.TextIter) -> None Adds the mark at position ``where``. The mark must not be added to another buffer, and if its name is not :const:`None` then there must not be another mark in the buffer with the same name. Emits the :obj:`~gi.repository.Gtk.TextBuffer.signals.mark_set` signal as notification of the mark's initial placement. :param mark: the mark to add :param where: location to place mark .. method:: add_selection_clipboard(clipboard: ~gi.repository.Gdk.Clipboard) -> None Adds ``clipboard`` to the list of clipboards in which the selection contents of ``buffer`` are available. In most cases, ``clipboard`` will be the ``GdkClipboard`` returned by :obj:`~gi.repository.Gtk.Widget.get_primary_clipboard` for a view of ``buffer``. :param clipboard: a ``GdkClipboard`` .. method:: apply_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “apply-tag” signal on ``buffer``. The default handler for the signal applies ``tag`` to the given range. ``start`` and ``end`` do not have to be in order. :param tag: a ``GtkTextTag`` :param start: one bound of range to be tagged :param end: other bound of range to be tagged .. method:: apply_tag_by_name(name: str, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “apply-tag” signal on ``buffer``. Calls :obj:`~gi.repository.Gtk.TextTagTable.lookup` on the buffer’s tag table to get a ``GtkTextTag``, then calls :obj:`~gi.repository.Gtk.TextBuffer.apply_tag`. :param name: name of a named ``GtkTextTag`` :param start: one bound of range to be tagged :param end: other bound of range to be tagged .. method:: backspace(iter: ~gi.repository.Gtk.TextIter, interactive: bool, default_editable: bool) -> bool Performs the appropriate action as if the user hit the delete key with the cursor at the position specified by ``iter``. In the normal case a single character will be deleted, but when combining accents are involved, more than one character can be deleted, and when precomposed character and accent combinations are involved, less than one character will be deleted. Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the ``iter`` will be re-initialized to point to the location where text was deleted. :param iter: a position in ``buffer`` :param interactive: whether the deletion is caused by user interaction :param default_editable: whether the buffer is editable by default .. method:: begin_irreversible_action() -> None Denotes the beginning of an action that may not be undone. This will cause any previous operations in the undo/redo queue to be cleared. This should be paired with a call to :obj:`~gi.repository.Gtk.TextBuffer.end_irreversible_action` after the irreversible action has completed. You may nest calls to :func:`~gi.repository.Gtk.TextBuffer.begin_irreversible_action` and :func:`~gi.repository.Gtk.TextBuffer.end_irreversible_action` pairs. .. method:: begin_user_action() -> None Called to indicate that the buffer operations between here and a call to :func:`~gi.repository.Gtk.TextBuffer.end_user_action` are part of a single user-visible operation. The operations between :func:`~gi.repository.Gtk.TextBuffer.begin_user_action` and :func:`~gi.repository.Gtk.TextBuffer.end_user_action` can then be grouped when creating an undo stack. ``GtkTextBuffer`` maintains a count of calls to :func:`~gi.repository.Gtk.TextBuffer.begin_user_action` that have not been closed with a call to :func:`~gi.repository.Gtk.TextBuffer.end_user_action`, and emits the “begin-user-action” and “end-user-action” signals only for the outermost pair of calls. This allows you to build user actions from other user actions. The “interactive” buffer mutation functions, such as :obj:`~gi.repository.Gtk.TextBuffer.insert_interactive`, automatically call begin/end user action around the buffer operations they perform, so there's no need to add extra calls if you user action consists solely of a single call to one of those functions. .. method:: create_child_anchor(iter: ~gi.repository.Gtk.TextIter) -> ~gi.repository.Gtk.TextChildAnchor Creates and inserts a child anchor. This is a convenience function which simply creates a child anchor with :obj:`~gi.repository.Gtk.TextChildAnchor.new` and inserts it into the buffer with :obj:`~gi.repository.Gtk.TextBuffer.insert_child_anchor`. The new anchor is owned by the buffer; no reference count is returned to the caller of this function. :param iter: location in the buffer .. method:: create_mark(mark_name, where, left_gravity=False) Creates a mark at position ``where``. If ``mark_name`` is :const:`None`, the mark is anonymous; otherwise, the mark can be retrieved by name using :obj:`~gi.repository.Gtk.TextBuffer.get_mark`. If a mark has left gravity, and text is inserted at the mark’s current location, the mark will be moved to the left of the newly-inserted text. If the mark has right gravity (``left_gravity`` = :const:`False`), the mark will end up on the right of newly-inserted text. The standard left-to-right cursor is a mark with right gravity (when you type, the cursor stays on the right side of the text you’re typing). The caller of this function does not own a reference to the returned ``GtkTextMark``, so you can ignore the return value if you like. Marks are owned by the buffer and go away when the buffer does. Emits the :obj:`~gi.repository.Gtk.TextBuffer.signals.mark_set` signal as notification of the mark's initial placement. :param mark_name: name for mark :param where: location to place mark :param left_gravity: whether the mark has left gravity .. method:: create_tag(tag_name=None, **properties) Creates a tag and adds it to the tag table of the TextBuffer. :param str tag_name: Name of the new tag, or None :param **properties: Keyword list of properties and their values This is equivalent to creating a Gtk.TextTag and then adding the tag to the buffer's tag table. The returned tag is owned by the buffer's tag table. If ``tag_name`` is None, the tag is anonymous. If ``tag_name`` is not None, a tag called ``tag_name`` must not already exist in the tag table for this buffer. Properties are passed as a keyword list of names and values (e.g. foreground='DodgerBlue', weight=Pango.Weight.BOLD) :returns: A new tag. .. method:: cut_clipboard(clipboard: ~gi.repository.Gdk.Clipboard, default_editable: bool) -> None Copies the currently-selected text to a clipboard, then deletes said text if it’s editable. :param clipboard: the ``GdkClipboard`` object to cut to :param default_editable: default editability of the buffer .. method:: delete(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Deletes text between ``start`` and ``end``. The order of ``start`` and ``end`` is not actually relevant; :func:`~gi.repository.Gtk.TextBuffer.delete` will reorder them. This function actually emits the “delete-range” signal, and the default handler of that signal deletes the text. Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the ``start`` and ``end`` will be re-initialized to point to the location where text was deleted. :param start: a position in ``buffer`` :param end: another position in ``buffer`` .. method:: delete_interactive(start_iter: ~gi.repository.Gtk.TextIter, end_iter: ~gi.repository.Gtk.TextIter, default_editable: bool) -> bool Deletes all editable text in the given range. Calls :obj:`~gi.repository.Gtk.TextBuffer.delete` for each editable sub-range of [``start``,``end``). ``start`` and ``end`` are revalidated to point to the location of the last deleted range, or left untouched if no text was deleted. :param start_iter: start of range to delete :param end_iter: end of range :param default_editable: whether the buffer is editable by default .. method:: delete_mark(mark: ~gi.repository.Gtk.TextMark) -> None Deletes ``mark``, so that it’s no longer located anywhere in the buffer. Removes the reference the buffer holds to the mark, so if you haven’t called :func:`~gi.repository.GObject.GObject.Object.ref` on the mark, it will be freed. Even if the mark isn’t freed, most operations on ``mark`` become invalid, until it gets added to a buffer again with :obj:`~gi.repository.Gtk.TextBuffer.add_mark`. Use :obj:`~gi.repository.Gtk.TextMark.get_deleted` to find out if a mark has been removed from its buffer. The :obj:`~gi.repository.Gtk.TextBuffer.signals.mark_deleted` signal will be emitted as notification after the mark is deleted. :param mark: a ``GtkTextMark`` in ``buffer`` .. method:: delete_mark_by_name(name: str) -> None Deletes the mark named ``name``; the mark must exist. See :obj:`~gi.repository.Gtk.TextBuffer.delete_mark` for details. :param name: name of a mark in ``buffer`` .. method:: delete_selection(interactive: bool, default_editable: bool) -> bool Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text. If ``interactive`` is :const:`True`, the editability of the selection will be considered (users can’t delete uneditable text). :param interactive: whether the deletion is caused by user interaction :param default_editable: whether the buffer is editable by default .. method:: end_irreversible_action() -> None Denotes the end of an action that may not be undone. This will cause any previous operations in the undo/redo queue to be cleared. This should be called after completing modifications to the text buffer after :obj:`~gi.repository.Gtk.TextBuffer.begin_irreversible_action` was called. You may nest calls to :func:`~gi.repository.Gtk.TextBuffer.begin_irreversible_action` and :func:`~gi.repository.Gtk.TextBuffer.end_irreversible_action` pairs. .. method:: end_user_action() -> None Ends a user-visible operation. Should be paired with a call to :obj:`~gi.repository.Gtk.TextBuffer.begin_user_action`. See that function for a full explanation. .. method:: get_bounds() -> tuple[~gi.repository.Gtk.TextIter, ~gi.repository.Gtk.TextIter] Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [``start``,``end``). .. method:: get_can_redo() -> bool Gets whether there is a redoable action in the history. .. method:: get_can_undo() -> bool Gets whether there is an undoable action in the history. .. method:: get_char_count() -> int Gets the number of characters in the buffer. Note that characters and bytes are not the same, you can’t e.g. expect the contents of the buffer in string form to be this many bytes long. The character count is cached, so this function is very fast. .. method:: get_enable_undo() -> bool Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions. See :obj:`~gi.repository.Gtk.TextBuffer.begin_irreversible_action` and :obj:`~gi.repository.Gtk.TextBuffer.end_irreversible_action` to create changes to the buffer that cannot be undone. .. method:: get_end_iter() -> ~gi.repository.Gtk.TextIter Initializes ``iter`` with the “end iterator,” one past the last valid character in the text buffer. If dereferenced with :obj:`~gi.repository.Gtk.TextIter.get_char`, the end iterator has a character value of 0. The entire buffer lies in the range from the first position in the buffer (call :obj:`~gi.repository.Gtk.TextBuffer.get_start_iter` to get character position 0) to the end iterator. .. method:: get_has_selection() -> bool Indicates whether the buffer has some text currently selected. .. method:: get_insert() -> ~gi.repository.Gtk.TextMark Returns the mark that represents the cursor (insertion point). Equivalent to calling :obj:`~gi.repository.Gtk.TextBuffer.get_mark` to get the mark named “insert”, but very slightly more efficient, and involves less typing. .. method:: get_iter_at_child_anchor(anchor: ~gi.repository.Gtk.TextChildAnchor) -> ~gi.repository.Gtk.TextIter Obtains the location of ``anchor`` within ``buffer``. :param anchor: a child anchor that appears in ``buffer`` .. method:: get_iter_at_line(line_number: int) -> tuple[bool, ~gi.repository.Gtk.TextIter] Initializes ``iter`` to the start of the given line. If ``line_number`` is greater than or equal to the number of lines in the ``buffer``, the end iterator is returned. :param line_number: line number counting from 0 .. method:: get_iter_at_line_index(line_number: int, byte_index: int) -> tuple[bool, ~gi.repository.Gtk.TextIter] Obtains an iterator pointing to ``byte_index`` within the given line. ``byte_index`` must be the start of a UTF-8 character. Note bytes, not characters; UTF-8 may encode one character as multiple bytes. If ``line_number`` is greater than or equal to the number of lines in the ``buffer``, the end iterator is returned. And if ``byte_index`` is off the end of the line, the iterator at the end of the line is returned. :param line_number: line number counting from 0 :param byte_index: byte index from start of line .. method:: get_iter_at_line_offset(line_number: int, char_offset: int) -> tuple[bool, ~gi.repository.Gtk.TextIter] Obtains an iterator pointing to ``char_offset`` within the given line. Note characters, not bytes; UTF-8 may encode one character as multiple bytes. If ``line_number`` is greater than or equal to the number of lines in the ``buffer``, the end iterator is returned. And if ``char_offset`` is off the end of the line, the iterator at the end of the line is returned. :param line_number: line number counting from 0 :param char_offset: char offset from start of line .. method:: get_iter_at_mark(mark: ~gi.repository.Gtk.TextMark) -> ~gi.repository.Gtk.TextIter Initializes ``iter`` with the current position of ``mark``. :param mark: a ``GtkTextMark`` in ``buffer`` .. method:: get_iter_at_offset(char_offset: int) -> ~gi.repository.Gtk.TextIter Initializes ``iter`` to a position ``char_offset`` chars from the start of the entire buffer. If ``char_offset`` is -1 or greater than the number of characters in the buffer, ``iter`` is initialized to the end iterator, the iterator one past the last valid character in the buffer. :param char_offset: char offset from start of buffer, counting from 0, or -1 .. method:: get_line_count() -> int Obtains the number of lines in the buffer. This value is cached, so the function is very fast. .. method:: get_mark(name: str) -> ~gi.repository.Gtk.TextMark | None Returns the mark named ``name`` in buffer ``buffer``, or :const:`None` if no such mark exists in the buffer. :param name: a mark name .. method:: get_max_undo_levels() -> int Gets the maximum number of undo levels to perform. If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer. .. method:: get_modified() -> bool Indicates whether the buffer has been modified since the last call to :obj:`~gi.repository.Gtk.TextBuffer.set_modified` set the modification flag to :const:`False`. Used for example to enable a “save” function in a text editor. .. method:: get_selection_bound() -> ~gi.repository.Gtk.TextMark Returns the mark that represents the selection bound. Equivalent to calling :obj:`~gi.repository.Gtk.TextBuffer.get_mark` to get the mark named “selection_bound”, but very slightly more efficient, and involves less typing. The currently-selected text in ``buffer`` is the region between the “selection_bound” and “insert” marks. If “selection_bound” and “insert” are in the same place, then there is no current selection. :obj:`~gi.repository.Gtk.TextBuffer.get_selection_bounds` is another convenient function for handling the selection, if you just want to know whether there’s a selection and what its bounds are. .. method:: get_selection_bounds() -> tuple[bool, ~gi.repository.Gtk.TextIter, ~gi.repository.Gtk.TextIter] Returns :const:`True` if some text is selected; places the bounds of the selection in ``start`` and ``end``. If the selection has length 0, then ``start`` and ``end`` are filled in with the same value. ``start`` and ``end`` will be in ascending order. If ``start`` and ``end`` are :const:`None`, then they are not filled in, but the return value still indicates whether text is selected. .. method:: get_selection_content() -> ~gi.repository.Gdk.ContentProvider Get a content provider for this buffer. It can be used to make the content of ``buffer`` available in a ``GdkClipboard``, see :obj:`~gi.repository.Gdk.Clipboard.set_content`. .. method:: get_slice(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter, include_hidden_chars: bool) -> str Returns the text in the range [``start``,``end``). Excludes undisplayed text (text marked with tags that set the invisibility attribute) if ``include_hidden_chars`` is :const:`False`. The returned string includes a 0xFFFC character whenever the buffer contains embedded images, so byte and character indexes into the returned string do correspond to byte and character indexes into the buffer. Contrast with :obj:`~gi.repository.Gtk.TextBuffer.get_text`. Note that 0xFFFC can occur in normal text as well, so it is not a reliable indicator that a paintable or widget is in the buffer. :param start: start of a range :param end: end of a range :param include_hidden_chars: whether to include invisible text .. method:: get_start_iter() -> ~gi.repository.Gtk.TextIter Initialized ``iter`` with the first position in the text buffer. This is the same as using :obj:`~gi.repository.Gtk.TextBuffer.get_iter_at_offset` to get the iter at character offset 0. .. method:: get_tag_table() -> ~gi.repository.Gtk.TextTagTable Get the ``GtkTextTagTable`` associated with this buffer. .. method:: get_text(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter, include_hidden_chars: bool) -> str Returns the text in the range [``start``,``end``). Excludes undisplayed text (text marked with tags that set the invisibility attribute) if ``include_hidden_chars`` is :const:`False`. Does not include characters representing embedded images, so byte and character indexes into the returned string do not correspond to byte and character indexes into the buffer. Contrast with :obj:`~gi.repository.Gtk.TextBuffer.get_slice`. :param start: start of a range :param end: end of a range :param include_hidden_chars: whether to include invisible text .. method:: insert(iter, text, length=-1) Inserts ``len`` bytes of ``text`` at position ``iter``. If ``len`` is -1, ``text`` must be nul-terminated and will be inserted in its entirety. Emits the “insert-text” signal; insertion actually occurs in the default handler for the signal. ``iter`` is invalidated when insertion occurs (because the buffer contents change), but the default signal handler revalidates it to point to the end of the inserted text. :param iter: a position in the buffer :param text: text in UTF-8 format :param length: .. method:: insert_at_cursor(text, length=-1) Inserts ``text`` in ``buffer``. Simply calls :obj:`~gi.repository.Gtk.TextBuffer.insert`, using the current cursor position as the insertion point. :param text: text in UTF-8 format :param length: .. method:: insert_child_anchor(iter: ~gi.repository.Gtk.TextIter, anchor: ~gi.repository.Gtk.TextChildAnchor) -> None Inserts a child widget anchor into the text buffer at ``iter``. The anchor will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for child anchors, but the “text” variants do not. E.g. see :obj:`~gi.repository.Gtk.TextBuffer.get_slice` and :obj:`~gi.repository.Gtk.TextBuffer.get_text`. Consider :obj:`~gi.repository.Gtk.TextBuffer.create_child_anchor` as a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion. :param iter: location to insert the anchor :param anchor: a ``GtkTextChildAnchor`` .. method:: insert_interactive(iter: ~gi.repository.Gtk.TextIter, text: str, len: int, default_editable: bool) -> bool Inserts ``text`` in ``buffer``. Like :obj:`~gi.repository.Gtk.TextBuffer.insert`, but the insertion will not occur if ``iter`` is at a non-editable location in the buffer. Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive). ``default_editable`` indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of :obj:`~gi.repository.Gtk.TextView.get_editable` is appropriate here. :param iter: a position in ``buffer`` :param text: some UTF-8 text :param len: length of text in bytes, or -1 :param default_editable: default editability of buffer .. method:: insert_interactive_at_cursor(text: str, len: int, default_editable: bool) -> bool Inserts ``text`` in ``buffer``. Calls :obj:`~gi.repository.Gtk.TextBuffer.insert_interactive` at the cursor position. ``default_editable`` indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of :obj:`~gi.repository.Gtk.TextView.get_editable` is appropriate here. :param text: text in UTF-8 format :param len: length of text in bytes, or -1 :param default_editable: default editability of buffer .. method:: insert_markup(iter: ~gi.repository.Gtk.TextIter, markup: str, len: int) -> None Inserts the text in ``markup`` at position ``iter``. ``markup`` will be inserted in its entirety and must be nul-terminated and valid UTF-8. Emits the :obj:`~gi.repository.Gtk.TextBuffer.signals.insert_text` signal, possibly multiple times; insertion actually occurs in the default handler for the signal. ``iter`` will point to the end of the inserted text on return. :param iter: location to insert the markup :param markup: a nul-terminated UTF-8 string containing Pango markup :param len: length of ``markup`` in bytes, or -1 .. method:: insert_paintable(iter: ~gi.repository.Gtk.TextIter, paintable: ~gi.repository.Gdk.Paintable) -> None Inserts an image into the text buffer at ``iter``. The image will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for paintable, but the “text” variants do not. e.g. see :obj:`~gi.repository.Gtk.TextBuffer.get_slice` and :obj:`~gi.repository.Gtk.TextBuffer.get_text`. :param iter: location to insert the paintable :param paintable: a ``GdkPaintable`` .. method:: insert_range(iter: ~gi.repository.Gtk.TextIter, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Copies text, tags, and paintables between ``start`` and ``end`` and inserts the copy at ``iter``. The order of ``start`` and ``end`` doesn’t matter. Used instead of simply getting/inserting text because it preserves images and tags. If ``start`` and ``end`` are in a different buffer from ``buffer``, the two buffers must share the same tag table. Implemented via emissions of the ::insert-text and ::apply-tag signals, so expect those. :param iter: a position in ``buffer`` :param start: a position in a ``GtkTextBuffer`` :param end: another position in the same buffer as ``start`` .. method:: insert_range_interactive(iter: ~gi.repository.Gtk.TextIter, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter, default_editable: bool) -> bool Copies text, tags, and paintables between ``start`` and ``end`` and inserts the copy at ``iter``. Same as :obj:`~gi.repository.Gtk.TextBuffer.insert_range`, but does nothing if the insertion point isn’t editable. The ``default_editable`` parameter indicates whether the text is editable at ``iter`` if no tags enclosing ``iter`` affect editability. Typically the result of :obj:`~gi.repository.Gtk.TextView.get_editable` is appropriate here. :param iter: a position in ``buffer`` :param start: a position in a ``GtkTextBuffer`` :param end: another position in the same buffer as ``start`` :param default_editable: default editability of the buffer .. method:: insert_with_tags(iter, text, *tags) Inserts ``text`` into ``buffer`` at ``iter``, applying the list of tags to the newly-inserted text. The last tag specified must be :const:`None` to terminate the list. Equivalent to calling :obj:`~gi.repository.Gtk.TextBuffer.insert`, then :obj:`~gi.repository.Gtk.TextBuffer.apply_tag` on the inserted text; this is just a convenience function. :param iter: an iterator in ``buffer`` :param text: UTF-8 text :param tags: .. method:: insert_with_tags_by_name(iter, text, *tags) Inserts ``text`` into ``buffer`` at ``iter``, applying the list of tags to the newly-inserted text. Same as :obj:`~gi.repository.Gtk.TextBuffer.insert_with_tags`, but allows you to pass in tag names instead of tag objects. :param iter: position in ``buffer`` :param text: UTF-8 text :param tags: .. method:: move_mark(mark: ~gi.repository.Gtk.TextMark, where: ~gi.repository.Gtk.TextIter) -> None Moves ``mark`` to the new location ``where``. Emits the :obj:`~gi.repository.Gtk.TextBuffer.signals.mark_set` signal as notification of the move. :param mark: a ``GtkTextMark`` :param where: new location for ``mark`` in ``buffer`` .. method:: move_mark_by_name(name: str, where: ~gi.repository.Gtk.TextIter) -> None Moves the mark named ``name`` (which must exist) to location ``where``. See :obj:`~gi.repository.Gtk.TextBuffer.move_mark` for details. :param name: name of a mark :param where: new location for mark .. method:: paste_clipboard(clipboard: ~gi.repository.Gdk.Clipboard, override_location: ~gi.repository.Gtk.TextIter | None, default_editable: bool) -> None Pastes the contents of a clipboard. If ``override_location`` is :const:`None`, the pasted text will be inserted at the cursor position, or the buffer selection will be replaced if the selection is non-empty. Note: pasting is asynchronous, that is, we’ll ask for the paste data and return, and at some point later after the main loop runs, the paste data will be inserted. :param clipboard: the ``GdkClipboard`` to paste from :param override_location: location to insert pasted text :param default_editable: whether the buffer is editable by default .. method:: place_cursor(where: ~gi.repository.Gtk.TextIter) -> None This function moves the “insert” and “selection_bound” marks simultaneously. If you move them to the same place in two steps with :obj:`~gi.repository.Gtk.TextBuffer.move_mark`, you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized. :param where: where to put the cursor .. method:: redo() -> None Redoes the next redoable action on the buffer, if there is one. .. method:: remove_all_tags(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Removes all tags in the range between ``start`` and ``end``. Be careful with this function; it could remove tags added in code unrelated to the code you’re currently writing. That is, using this function is probably a bad idea if you have two or more unrelated code sections that add tags. :param start: one bound of range to be untagged :param end: other bound of range to be untagged .. method:: remove_selection_clipboard(clipboard: ~gi.repository.Gdk.Clipboard) -> None Removes a ``GdkClipboard`` added with :obj:`~gi.repository.Gtk.TextBuffer.add_selection_clipboard` :param clipboard: a ``GdkClipboard`` added to ``buffer`` by :obj:`~gi.repository.Gtk.TextBuffer.add_selection_clipboard` .. method:: remove_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “remove-tag” signal. The default handler for the signal removes all occurrences of ``tag`` from the given range. ``start`` and ``end`` don’t have to be in order. :param tag: a ``GtkTextTag`` :param start: one bound of range to be untagged :param end: other bound of range to be untagged .. method:: remove_tag_by_name(name: str, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “remove-tag” signal. Calls :obj:`~gi.repository.Gtk.TextTagTable.lookup` on the buffer’s tag table to get a ``GtkTextTag``, then calls :obj:`~gi.repository.Gtk.TextBuffer.remove_tag`. :param name: name of a ``GtkTextTag`` :param start: one bound of range to be untagged :param end: other bound of range to be untagged .. method:: select_range(ins: ~gi.repository.Gtk.TextIter, bound: ~gi.repository.Gtk.TextIter) -> None This function moves the “insert” and “selection_bound” marks simultaneously. If you move them in two steps with :obj:`~gi.repository.Gtk.TextBuffer.move_mark`, you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized. :param ins: where to put the “insert” mark :param bound: where to put the “selection_bound” mark .. method:: set_enable_undo(enable_undo: bool) -> None Sets whether or not to enable undoable actions in the text buffer. Undoable actions in this context are changes to the text content of the buffer. Changes to tags and marks are not tracked. If enabled, the user will be able to undo the last number of actions up to :obj:`~gi.repository.Gtk.TextBuffer.get_max_undo_levels`. See :obj:`~gi.repository.Gtk.TextBuffer.begin_irreversible_action` and :obj:`~gi.repository.Gtk.TextBuffer.end_irreversible_action` to create changes to the buffer that cannot be undone. :param enable_undo: :const:`True` to enable undo .. method:: set_max_undo_levels(max_undo_levels: int) -> None Sets the maximum number of undo levels to perform. If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer. :param max_undo_levels: the maximum number of undo actions to perform .. method:: set_modified(setting: bool) -> None Used to keep track of whether the buffer has been modified since the last time it was saved. Whenever the buffer is saved to disk, call `gtk_text_buffer_set_modified (``buffer``, FALSE)`. When the buffer is modified, it will automatically toggle on the modified bit again. When the modified bit flips, the buffer emits the :obj:`~gi.repository.Gtk.TextBuffer.signals.modified_changed` signal. :param setting: modification flag setting .. method:: set_text(text, length=-1) Deletes current contents of ``buffer``, and inserts ``text`` instead. This is automatically marked as an irreversible action in the undo stack. If you wish to mark this action as part of a larger undo operation, call :obj:`~gi.repository.TextBuffer.delete` and :obj:`~gi.repository.TextBuffer.insert` directly instead. If ``len`` is -1, ``text`` must be nul-terminated. ``text`` must be valid UTF-8. :param text: UTF-8 text to insert :param length: .. method:: undo() -> None Undoes the last undoable action on the buffer, if there is one. Properties ---------- .. rst-class:: interim-class .. class:: TextBuffer :no-index: .. attribute:: props.can_redo :type: bool Denotes that the buffer can reapply the last undone action. .. attribute:: props.can_undo :type: bool Denotes that the buffer can undo the last applied action. .. attribute:: props.cursor_position :type: int The position of the insert mark. This is an offset from the beginning of the buffer. It is useful for getting notified when the cursor moves. .. attribute:: props.enable_undo :type: bool Denotes if support for undoing and redoing changes to the buffer is allowed. .. attribute:: props.has_selection :type: bool Whether the buffer has some text currently selected. .. attribute:: props.tag_table :type: ~gi.repository.Gtk.TextTagTable The GtkTextTagTable for the buffer. .. attribute:: props.text :type: str The text content of the buffer. Without child widgets and images, see :obj:`~gi.repository.Gtk.TextBuffer.get_text` for more information. Signals ------- .. rst-class:: interim-class .. class:: TextBuffer.signals :no-index: .. method:: apply_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emitted to apply a tag to a range of text in a ``GtkTextBuffer``. Applying actually occurs in the default handler. Note that if your handler runs before the default handler it must not invalidate the ``start`` and ``end`` iters (or has to revalidate them). See also: :obj:`~gi.repository.Gtk.TextBuffer.apply_tag`, :obj:`~gi.repository.Gtk.TextBuffer.insert_with_tags`, :obj:`~gi.repository.Gtk.TextBuffer.insert_range`. :param tag: the applied tag :param start: the start of the range the tag is applied to :param end: the end of the range the tag is applied to .. method:: begin_user_action() -> None Emitted at the beginning of a single user-visible operation on a ``GtkTextBuffer``. See also: :obj:`~gi.repository.Gtk.TextBuffer.begin_user_action`, :obj:`~gi.repository.Gtk.TextBuffer.insert_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.insert_range_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.delete_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.backspace`, :obj:`~gi.repository.Gtk.TextBuffer.delete_selection`. .. method:: changed() -> None Emitted when the content of a ``GtkTextBuffer`` has changed. .. method:: delete_range(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emitted to delete a range from a ``GtkTextBuffer``. Note that if your handler runs before the default handler it must not invalidate the ``start`` and ``end`` iters (or has to revalidate them). The default signal handler revalidates the ``start`` and ``end`` iters to both point to the location where text was deleted. Handlers which run after the default handler (see :func:`~gi.repository.GObject.signal_connect_after`) do not have access to the deleted text. See also: :obj:`~gi.repository.Gtk.TextBuffer.delete`. :param start: the start of the range to be deleted :param end: the end of the range to be deleted .. method:: end_user_action() -> None Emitted at the end of a single user-visible operation on the ``GtkTextBuffer``. See also: :obj:`~gi.repository.Gtk.TextBuffer.end_user_action`, :obj:`~gi.repository.Gtk.TextBuffer.insert_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.insert_range_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.delete_interactive`, :obj:`~gi.repository.Gtk.TextBuffer.backspace`, :obj:`~gi.repository.Gtk.TextBuffer.delete_selection`, :obj:`~gi.repository.Gtk.TextBuffer.backspace`. .. method:: insert_child_anchor(location: ~gi.repository.Gtk.TextIter, anchor: ~gi.repository.Gtk.TextChildAnchor) -> None Emitted to insert a ``GtkTextChildAnchor`` in a ``GtkTextBuffer``. Insertion actually occurs in the default handler. Note that if your handler runs before the default handler it must not invalidate the ``location`` iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted ``anchor``. See also: :obj:`~gi.repository.Gtk.TextBuffer.insert_child_anchor`. :param location: position to insert ``anchor`` in ``textbuffer`` :param anchor: the ``GtkTextChildAnchor`` to be inserted .. method:: insert_paintable(location: ~gi.repository.Gtk.TextIter, paintable: ~gi.repository.Gdk.Paintable) -> None Emitted to insert a ``GdkPaintable`` in a ``GtkTextBuffer``. Insertion actually occurs in the default handler. Note that if your handler runs before the default handler it must not invalidate the ``location`` iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted ``paintable``. See also: :obj:`~gi.repository.Gtk.TextBuffer.insert_paintable`. :param location: position to insert ``paintable`` in ``textbuffer`` :param paintable: the ``GdkPaintable`` to be inserted .. method:: insert_text(location: ~gi.repository.Gtk.TextIter, text: str, len: int) -> None Emitted to insert text in a ``GtkTextBuffer``. Insertion actually occurs in the default handler. Note that if your handler runs before the default handler it must not invalidate the ``location`` iter (or has to revalidate it). The default signal handler revalidates it to point to the end of the inserted text. See also: :obj:`~gi.repository.Gtk.TextBuffer.insert`, :obj:`~gi.repository.Gtk.TextBuffer.insert_range`. :param location: position to insert ``text`` in ``textbuffer`` :param text: the UTF-8 text to be inserted :param len: length of the inserted text in bytes .. method:: mark_deleted(mark: ~gi.repository.Gtk.TextMark) -> None Emitted as notification after a ``GtkTextMark`` is deleted. See also: :obj:`~gi.repository.Gtk.TextBuffer.delete_mark`. :param mark: The mark that was deleted .. method:: mark_set(location: ~gi.repository.Gtk.TextIter, mark: ~gi.repository.Gtk.TextMark) -> None Emitted as notification after a ``GtkTextMark`` is set. See also: :obj:`~gi.repository.Gtk.TextBuffer.create_mark`, :obj:`~gi.repository.Gtk.TextBuffer.move_mark`. :param location: The location of ``mark`` in ``textbuffer`` :param mark: The mark that is set .. method:: modified_changed() -> None Emitted when the modified bit of a ``GtkTextBuffer`` flips. See also: :obj:`~gi.repository.Gtk.TextBuffer.set_modified`. .. method:: paste_done(clipboard: ~gi.repository.Gdk.Clipboard) -> None Emitted after paste operation has been completed. This is useful to properly scroll the view to the end of the pasted text. See :obj:`~gi.repository.Gtk.TextBuffer.paste_clipboard` for more details. :param clipboard: the ``GdkClipboard`` pasted from .. method:: redo() -> None Emitted when a request has been made to redo the previously undone operation. .. method:: remove_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emitted to remove all occurrences of ``tag`` from a range of text in a ``GtkTextBuffer``. Removal actually occurs in the default handler. Note that if your handler runs before the default handler it must not invalidate the ``start`` and ``end`` iters (or has to revalidate them). See also: :obj:`~gi.repository.Gtk.TextBuffer.remove_tag`. :param tag: the tag to be removed :param start: the start of the range the tag is removed from :param end: the end of the range the tag is removed from .. method:: undo() -> None Emitted when a request has been made to undo the previous operation or set of operations that have been grouped together. Virtual Methods --------------- .. rst-class:: interim-class .. class:: TextBuffer :no-index: .. method:: do_apply_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “apply-tag” signal on ``buffer``. The default handler for the signal applies ``tag`` to the given range. ``start`` and ``end`` do not have to be in order. :param tag: a ``GtkTextTag`` :param start: one bound of range to be tagged :param end: other bound of range to be tagged .. method:: do_begin_user_action() -> None Called to indicate that the buffer operations between here and a call to :func:`~gi.repository.Gtk.TextBuffer.end_user_action` are part of a single user-visible operation. The operations between :func:`~gi.repository.Gtk.TextBuffer.begin_user_action` and :func:`~gi.repository.Gtk.TextBuffer.end_user_action` can then be grouped when creating an undo stack. ``GtkTextBuffer`` maintains a count of calls to :func:`~gi.repository.Gtk.TextBuffer.begin_user_action` that have not been closed with a call to :func:`~gi.repository.Gtk.TextBuffer.end_user_action`, and emits the “begin-user-action” and “end-user-action” signals only for the outermost pair of calls. This allows you to build user actions from other user actions. The “interactive” buffer mutation functions, such as :obj:`~gi.repository.Gtk.TextBuffer.insert_interactive`, automatically call begin/end user action around the buffer operations they perform, so there's no need to add extra calls if you user action consists solely of a single call to one of those functions. .. method:: do_changed() -> None The class handler for the ``GtkTextBuffer::changed`` signal. .. method:: do_delete_range(start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None The class handler for the ``GtkTextBuffer::delete-range`` signal. :param start: :param end: .. method:: do_end_user_action() -> None Ends a user-visible operation. Should be paired with a call to :obj:`~gi.repository.Gtk.TextBuffer.begin_user_action`. See that function for a full explanation. .. method:: do_insert_child_anchor(iter: ~gi.repository.Gtk.TextIter, anchor: ~gi.repository.Gtk.TextChildAnchor) -> None Inserts a child widget anchor into the text buffer at ``iter``. The anchor will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for child anchors, but the “text” variants do not. E.g. see :obj:`~gi.repository.Gtk.TextBuffer.get_slice` and :obj:`~gi.repository.Gtk.TextBuffer.get_text`. Consider :obj:`~gi.repository.Gtk.TextBuffer.create_child_anchor` as a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion. :param iter: location to insert the anchor :param anchor: a ``GtkTextChildAnchor`` .. method:: do_insert_paintable(iter: ~gi.repository.Gtk.TextIter, paintable: ~gi.repository.Gdk.Paintable) -> None Inserts an image into the text buffer at ``iter``. The image will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for paintable, but the “text” variants do not. e.g. see :obj:`~gi.repository.Gtk.TextBuffer.get_slice` and :obj:`~gi.repository.Gtk.TextBuffer.get_text`. :param iter: location to insert the paintable :param paintable: a ``GdkPaintable`` .. method:: do_insert_text(pos: ~gi.repository.Gtk.TextIter, new_text: str, new_text_length: int) -> None The class handler for the ``GtkTextBuffer::insert-text`` signal. :param pos: :param new_text: :param new_text_length: .. method:: do_mark_deleted(mark: ~gi.repository.Gtk.TextMark) -> None The class handler for the ``GtkTextBuffer::mark-deleted`` signal. :param mark: .. method:: do_mark_set(location: ~gi.repository.Gtk.TextIter, mark: ~gi.repository.Gtk.TextMark) -> None The class handler for the ``GtkTextBuffer::mark-set`` signal. :param location: :param mark: .. method:: do_modified_changed() -> None The class handler for the ``GtkTextBuffer::modified-changed`` signal. .. method:: do_paste_done(clipboard: ~gi.repository.Gdk.Clipboard) -> None The class handler for the ``GtkTextBuffer::paste-done`` signal. :param clipboard: .. method:: do_redo() -> None Redoes the next redoable action on the buffer, if there is one. .. method:: do_remove_tag(tag: ~gi.repository.Gtk.TextTag, start: ~gi.repository.Gtk.TextIter, end: ~gi.repository.Gtk.TextIter) -> None Emits the “remove-tag” signal. The default handler for the signal removes all occurrences of ``tag`` from the given range. ``start`` and ``end`` don’t have to be in order. :param tag: a ``GtkTextTag`` :param start: one bound of range to be untagged :param end: other bound of range to be untagged .. method:: do_undo() -> None Undoes the last undoable action on the buffer, if there is one. Fields ------ .. rst-class:: interim-class .. class:: TextBuffer :no-index: .. attribute:: parent_instance .. attribute:: priv