TextBuffer#
Superclasses: 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 set_enable_undo.
Constructors#
- class TextBuffer
- classmethod new(table: TextTagTable | None = None) TextBuffer#
Creates a new text buffer.
- Parameters:
table – a tag table, or
Noneto create a new one
Methods#
- class TextBuffer
- add_commit_notify(flags: TextBufferNotifyFlags, commit_notify: Callable[[TextBuffer, TextBufferNotifyFlags, int, int, Any], None], user_data: Any = None) int#
Adds a [callback``Gtk``.TextBufferCommitNotify] to be called when a change is to be made to the
TextBuffer.Functions are explicitly forbidden from making changes to the
TextBufferfrom this callback. It is intended for tracking changes to the buffer only.It may be advantageous to use [callback``Gtk``.TextBufferCommitNotify] over connecting to the
insert_textordelete_rangesignals to avoid ordering issues with other signal handlers which may further modify theTextBuffer.Added in version 4.16.
- Parameters:
flags – which notifications should be dispatched to
callbackcommit_notify – a [callback``Gtk``.TextBufferCommitNotify] to call for commit notifications
user_data – closure data for
commit_notify
- add_mark(mark: TextMark, where: TextIter) None#
Adds the mark at position
where.The mark must not be added to another buffer, and if its name is not
Nonethen there must not be another mark in the buffer with the same name.Emits the
mark_setsignal as notification of the mark’s initial placement.- Parameters:
mark – the mark to add
where – location to place mark
- add_selection_clipboard(clipboard: Clipboard) None#
Adds
clipboardto the list of clipboards in which the selection contents ofbufferare available.In most cases,
clipboardwill be theGdkClipboardreturned byget_primary_clipboardfor a view ofbuffer.- Parameters:
clipboard – a
GdkClipboard
- apply_tag(tag: TextTag, start: TextIter, end: TextIter) None#
Emits the “apply-tag” signal on
buffer.The default handler for the signal applies
tagto the given range.startandenddo not have to be in order.- Parameters:
tag – a
GtkTextTagstart – one bound of range to be tagged
end – other bound of range to be tagged
- apply_tag_by_name(name: str, start: TextIter, end: TextIter) None#
Emits the “apply-tag” signal on
buffer.Calls
lookupon the buffer’s tag table to get aGtkTextTag, then callsapply_tag.- Parameters:
name – name of a named
GtkTextTagstart – one bound of range to be tagged
end – other bound of range to be tagged
- backspace(iter: 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
iterwill be re-initialized to point to the location where text was deleted.- Parameters:
iter – a position in
bufferinteractive – whether the deletion is caused by user interaction
default_editable – whether the buffer is editable by default
- 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
end_irreversible_actionafter the irreversible action has completed.You may nest calls to
begin_irreversible_action()andend_irreversible_action()pairs.
- begin_user_action() None#
Called to indicate that the buffer operations between here and a call to
end_user_action()are part of a single user-visible operation.The operations between
begin_user_action()andend_user_action()can then be grouped when creating an undo stack.GtkTextBuffermaintains a count of calls tobegin_user_action()that have not been closed with a call toend_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
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.
- create_child_anchor(iter: TextIter) TextChildAnchor#
Creates and inserts a child anchor.
This is a convenience function which simply creates a child anchor with
newand inserts it into the buffer withinsert_child_anchor.The new anchor is owned by the buffer; no reference count is returned to the caller of this function.
- Parameters:
iter – location in the buffer
- create_mark(mark_name, where, left_gravity=False)#
Creates a mark at position
where.If
mark_nameisNone, the mark is anonymous; otherwise, the mark can be retrieved by name usingget_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=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
mark_setsignal as notification of the mark’s initial placement.- Parameters:
mark_name – name for mark
where – location to place mark
left_gravity – whether the mark has left gravity
- create_tag(tag_name=None, **properties)#
Creates a tag and adds it to the tag table of the TextBuffer.
- Parameters:
tag_name (str) – Name of the new tag, or None
**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_nameis None, the tag is anonymous.If
tag_nameis not None, a tag calledtag_namemust 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.
- cut_clipboard(clipboard: Clipboard, default_editable: bool) None#
Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
- Parameters:
clipboard – the
GdkClipboardobject to cut todefault_editable – default editability of the buffer
- delete(start: TextIter, end: TextIter) None#
Deletes text between
startandend.The order of
startandendis not actually relevant;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
startandendwill be re-initialized to point to the location where text was deleted.- Parameters:
start – a position in
bufferend – another position in
buffer
- delete_interactive(start_iter: TextIter, end_iter: TextIter, default_editable: bool) bool#
Deletes all editable text in the given range.
Calls
deletefor each editable sub-range of [start,``end``).startandendare revalidated to point to the location of the last deleted range, or left untouched if no text was deleted.- Parameters:
start_iter – start of range to delete
end_iter – end of range
default_editable – whether the buffer is editable by default
- delete_mark(mark: 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
ref()on the mark, it will be freed. Even if the mark isn’t freed, most operations onmarkbecome invalid, until it gets added to a buffer again withadd_mark. Useget_deletedto find out if a mark has been removed from its buffer.The
mark_deletedsignal will be emitted as notification after the mark is deleted.- Parameters:
mark – a
GtkTextMarkinbuffer
- delete_mark_by_name(name: str) None#
Deletes the mark named
name; the mark must exist.See
delete_markfor details.- Parameters:
name – name of a mark in
buffer
- 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
interactiveisTrue, the editability of the selection will be considered (users can’t delete uneditable text).- Parameters:
interactive – whether the deletion is caused by user interaction
default_editable – whether the buffer is editable by default
- do_insert_child_anchor(self, iter: TextIter, anchor: TextChildAnchor) None#
- Parameters:
iter
anchor
- do_insert_text(self, pos: TextIter, new_text: str, new_text_length: int) None#
- Parameters:
pos
new_text
new_text_length
- 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
begin_irreversible_actionwas called.You may nest calls to
begin_irreversible_action()andend_irreversible_action()pairs.
- end_user_action() None#
Ends a user-visible operation.
Should be paired with a call to
begin_user_action. See that function for a full explanation.
- get_bounds() tuple[TextIter, TextIter]#
Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [
start,``end``).
- 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.
- get_enable_undo() bool#
Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.
See
begin_irreversible_actionandend_irreversible_actionto create changes to the buffer that cannot be undone.
- get_end_iter() TextIter#
Initializes
iterwith the “end iterator,” one past the last valid character in the text buffer.If dereferenced with
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 (callget_start_iterto get character position 0) to the end iterator.
- get_insert() TextMark#
Returns the mark that represents the cursor (insertion point).
Equivalent to calling
get_markto get the mark named “insert”, but very slightly more efficient, and involves less typing.
- get_iter_at_child_anchor(anchor: TextChildAnchor) TextIter#
Obtains the location of
anchorwithinbuffer.- Parameters:
anchor – a child anchor that appears in
buffer
- get_iter_at_line(line_number: int) tuple[bool, TextIter]#
Initializes
iterto the start of the given line.If
line_numberis greater than or equal to the number of lines in thebuffer, the end iterator is returned.- Parameters:
line_number – line number counting from 0
- get_iter_at_line_index(line_number: int, byte_index: int) tuple[bool, TextIter]#
Obtains an iterator pointing to
byte_indexwithin the given line.byte_indexmust be the start of a UTF-8 character. Note bytes, not characters; UTF-8 may encode one character as multiple bytes.If
line_numberis greater than or equal to the number of lines in thebuffer, the end iterator is returned. And ifbyte_indexis off the end of the line, the iterator at the end of the line is returned.- Parameters:
line_number – line number counting from 0
byte_index – byte index from start of line
- get_iter_at_line_offset(line_number: int, char_offset: int) tuple[bool, TextIter]#
Obtains an iterator pointing to
char_offsetwithin the given line.Note characters, not bytes; UTF-8 may encode one character as multiple bytes.
If
line_numberis greater than or equal to the number of lines in thebuffer, the end iterator is returned. And ifchar_offsetis off the end of the line, the iterator at the end of the line is returned.- Parameters:
line_number – line number counting from 0
char_offset – char offset from start of line
- get_iter_at_mark(mark: TextMark) TextIter#
Initializes
iterwith the current position ofmark.- Parameters:
mark – a
GtkTextMarkinbuffer
- get_iter_at_offset(char_offset: int) TextIter#
Initializes
iterto a positionchar_offsetchars from the start of the entire buffer.If
char_offsetis -1 or greater than the number of characters in the buffer,iteris initialized to the end iterator, the iterator one past the last valid character in the buffer.- Parameters:
char_offset – char offset from start of buffer, counting from 0, or -1
- get_line_count() int#
Obtains the number of lines in the buffer.
This value is cached, so the function is very fast.
- get_mark(name: str) TextMark | None#
Returns the mark named
namein bufferbuffer, orNoneif no such mark exists in the buffer.- Parameters:
name – a mark name
- 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.
- get_modified() bool#
Indicates whether the buffer has been modified since the last call to
set_modifiedset the modification flag toFalse.Used for example to enable a “save” function in a text editor.
- get_selection_bound() TextMark#
Returns the mark that represents the selection bound.
Equivalent to calling
get_markto get the mark named “selection_bound”, but very slightly more efficient, and involves less typing.The currently-selected text in
bufferis 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.get_selection_boundsis another convenient function for handling the selection, if you just want to know whether there’s a selection and what its bounds are.
- get_selection_bounds() tuple[bool, TextIter, TextIter]#
Returns
Trueif some text is selected; places the bounds of the selection instartandend.If the selection has length 0, then
startandendare filled in with the same value.startandendwill be in ascending order. IfstartandendareNone, then they are not filled in, but the return value still indicates whether text is selected.
- get_selection_content() ContentProvider#
Get a content provider for this buffer.
It can be used to make the content of
bufferavailable in aGdkClipboard, seeset_content.
- get_slice(start: TextIter, end: 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_charsisFalse. 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 withget_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.- Parameters:
start – start of a range
end – end of a range
include_hidden_chars – whether to include invisible text
- get_start_iter() TextIter#
Initialized
iterwith the first position in the text buffer.This is the same as using
get_iter_at_offsetto get the iter at character offset 0.
- get_tag_table() TextTagTable#
Get the
GtkTextTagTableassociated with this buffer.
- get_text(start: TextIter, end: 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_charsisFalse. 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 withget_slice.- Parameters:
start – start of a range
end – end of a range
include_hidden_chars – whether to include invisible text
- insert(iter, text, length=-1)#
Inserts
lenbytes oftextat positioniter.If
lenis -1,textmust 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.iteris 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.- Parameters:
iter – a position in the buffer
text – text in UTF-8 format
length
- insert_at_cursor(text, length=-1)#
Inserts
textinbuffer.Simply calls
insert, using the current cursor position as the insertion point.- Parameters:
text – text in UTF-8 format
length
- insert_child_anchor(iter: TextIter, anchor: 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
get_sliceandget_text.Consider
create_child_anchoras a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion.- Parameters:
iter – location to insert the anchor
anchor – a
GtkTextChildAnchor
- insert_interactive(iter: TextIter, text: str, len: int, default_editable: bool) bool#
Inserts
textinbuffer.Like
insert, but the insertion will not occur ifiteris 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_editableindicates the editability of text that doesn’t have a tag affecting editability applied to it. Typically the result ofget_editableis appropriate here.- Parameters:
iter – a position in
buffertext – some UTF-8 text
len – length of text in bytes, or -1
default_editable – default editability of buffer
- insert_interactive_at_cursor(text: str, len: int, default_editable: bool) bool#
Inserts
textinbuffer.Calls
insert_interactiveat the cursor position.default_editableindicates the editability of text that doesn’t have a tag affecting editability applied to it. Typically the result ofget_editableis appropriate here.- Parameters:
text – text in UTF-8 format
len – length of text in bytes, or -1
default_editable – default editability of buffer
- insert_markup(iter: TextIter, markup: str, len: int) None#
Inserts the text in
markupat positioniter.markupwill be inserted in its entirety and must be nul-terminated and valid UTF-8. Emits theinsert_textsignal, possibly multiple times; insertion actually occurs in the default handler for the signal.iterwill point to the end of the inserted text on return.- Parameters:
iter – location to insert the markup
markup – a nul-terminated UTF-8 string containing Pango markup
len – length of
markupin bytes, or -1
- insert_paintable(iter: TextIter, paintable: 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
get_sliceandget_text.- Parameters:
iter – location to insert the paintable
paintable – a
GdkPaintable
- insert_range(iter: TextIter, start: TextIter, end: TextIter) None#
Copies text, tags, and paintables between
startandendand inserts the copy atiter.The order of
startandenddoesn’t matter.Used instead of simply getting/inserting text because it preserves images and tags. If
startandendare in a different buffer frombuffer, the two buffers must share the same tag table.Implemented via emissions of the ::insert-text and ::apply-tag signals, so expect those.
- Parameters:
iter – a position in
bufferstart – a position in a
GtkTextBufferend – another position in the same buffer as
start
- insert_range_interactive(iter: TextIter, start: TextIter, end: TextIter, default_editable: bool) bool#
Copies text, tags, and paintables between
startandendand inserts the copy atiter.Same as
insert_range, but does nothing if the insertion point isn’t editable. Thedefault_editableparameter indicates whether the text is editable atiterif no tags enclosingiteraffect editability. Typically the result ofget_editableis appropriate here.- Parameters:
iter – a position in
bufferstart – a position in a
GtkTextBufferend – another position in the same buffer as
startdefault_editable – default editability of the buffer
- insert_with_tags(iter, text, *tags)#
Inserts
textintobufferatiter, applying the list of tags to the newly-inserted text.The last tag specified must be
Noneto terminate the list. Equivalent to callinginsert, thenapply_tagon the inserted text; this is just a convenience function.- Parameters:
iter – an iterator in
buffertext – UTF-8 text
tags
- insert_with_tags_by_name(iter, text, *tags)#
Inserts
textintobufferatiter, applying the list of tags to the newly-inserted text.Same as
insert_with_tags, but allows you to pass in tag names instead of tag objects.- Parameters:
iter – position in
buffertext – UTF-8 text
tags
- move_mark(mark: TextMark, where: TextIter) None#
Moves
markto the new locationwhere.Emits the
mark_setsignal as notification of the move.- Parameters:
mark – a
GtkTextMarkwhere – new location for
markinbuffer
- move_mark_by_name(name: str, where: TextIter) None#
Moves the mark named
name(which must exist) to locationwhere.See
move_markfor details.- Parameters:
name – name of a mark
where – new location for mark
- paste_clipboard(clipboard: Clipboard, override_location: TextIter | None, default_editable: bool) None#
Pastes the contents of a clipboard.
If
override_locationisNone, 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.
- Parameters:
clipboard – the
GdkClipboardto paste fromoverride_location – location to insert pasted text
default_editable – whether the buffer is editable by default
- place_cursor(where: TextIter) None#
This function moves the “insert” and “selection_bound” marks simultaneously.
If you move them to the same place in two steps with
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.- Parameters:
where – where to put the cursor
- remove_all_tags(start: TextIter, end: TextIter) None#
Removes all tags in the range between
startandend.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.
- Parameters:
start – one bound of range to be untagged
end – other bound of range to be untagged
- remove_commit_notify(commit_notify_handler: int) None#
Removes the
GtkTextBufferCommitNotifyhandler previously registered withadd_commit_notify.This may result in the
user_data_destroybeing called that was passed when registering the commit notify functions.Added in version 4.16.
- Parameters:
commit_notify_handler – the notify handler identifier returned from
add_commit_notify.
- remove_selection_clipboard(clipboard: Clipboard) None#
Removes a
GdkClipboardadded withadd_selection_clipboard- Parameters:
clipboard – a
GdkClipboardadded tobufferbyadd_selection_clipboard
- remove_tag(tag: TextTag, start: TextIter, end: TextIter) None#
Emits the “remove-tag” signal.
The default handler for the signal removes all occurrences of
tagfrom the given range.startandenddon’t have to be in order.- Parameters:
tag – a
GtkTextTagstart – one bound of range to be untagged
end – other bound of range to be untagged
- remove_tag_by_name(name: str, start: TextIter, end: TextIter) None#
Emits the “remove-tag” signal.
Calls
lookupon the buffer’s tag table to get aGtkTextTag, then callsremove_tag.- Parameters:
name – name of a
GtkTextTagstart – one bound of range to be untagged
end – other bound of range to be untagged
- select_range(ins: TextIter, bound: TextIter) None#
This function moves the “insert” and “selection_bound” marks simultaneously.
If you move them in two steps with
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.- Parameters:
ins – where to put the “insert” mark
bound – where to put the “selection_bound” mark
- 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
get_max_undo_levels.See
begin_irreversible_actionandend_irreversible_actionto create changes to the buffer that cannot be undone.- Parameters:
enable_undo –
Trueto enable undo
- 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.
- Parameters:
max_undo_levels – the maximum number of undo actions to perform
- 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 themodified_changedsignal.- Parameters:
setting – modification flag setting
- set_text(text, length=-1)#
Deletes current contents of
buffer, and insertstextinstead. 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, calldeleteandinsertdirectly instead.If
lenis -1,textmust be nul-terminated.textmust be valid UTF-8.- Parameters:
text – UTF-8 text to insert
length
Properties#
- class TextBuffer
-
- props.tag_table: TextTagTable#
The type of the None singleton.
Signals#
- class TextBuffer.signals
- apply_tag(tag: TextTag, start: TextIter, end: TextIter) None#
The type of the None singleton.
- Parameters:
tag – the applied tag
start – the start of the range the tag is applied to
end – the end of the range the tag is applied to
- delete_range(start: TextIter, end: TextIter) None#
The type of the None singleton.
- Parameters:
start – the start of the range to be deleted
end – the end of the range to be deleted
- insert_child_anchor(location: TextIter, anchor: TextChildAnchor) None#
The type of the None singleton.
- Parameters:
location – position to insert
anchorintextbufferanchor – the
GtkTextChildAnchorto be inserted
- insert_paintable(location: TextIter, paintable: Paintable) None#
The type of the None singleton.
- Parameters:
location – position to insert
paintableintextbufferpaintable – the
GdkPaintableto be inserted
- insert_text(location: TextIter, text: str, len: int) None#
The type of the None singleton.
- Parameters:
location – position to insert
textintextbuffertext – the UTF-8 text to be inserted
len – length of the inserted text in bytes
- mark_deleted(mark: TextMark) None#
The type of the None singleton.
- Parameters:
mark – The mark that was deleted
- mark_set(location: TextIter, mark: TextMark) None#
The type of the None singleton.
- Parameters:
location – The location of
markintextbuffermark – The mark that is set
- paste_done(clipboard: Clipboard) None#
The type of the None singleton.
- Parameters:
clipboard – the
GdkClipboardpasted from
Virtual Methods#
- class TextBuffer
- do_apply_tag(tag: TextTag, start: TextIter, end: TextIter) None#
Emits the “apply-tag” signal on
buffer.The default handler for the signal applies
tagto the given range.startandenddo not have to be in order.- Parameters:
tag – a
GtkTextTagstart – one bound of range to be tagged
end – other bound of range to be tagged
- do_begin_user_action() None#
Called to indicate that the buffer operations between here and a call to
end_user_action()are part of a single user-visible operation.The operations between
begin_user_action()andend_user_action()can then be grouped when creating an undo stack.GtkTextBuffermaintains a count of calls tobegin_user_action()that have not been closed with a call toend_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
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.
- do_delete_range(start: TextIter, end: TextIter) None#
The type of the None singleton.
- Parameters:
start
end
- do_end_user_action() None#
Ends a user-visible operation.
Should be paired with a call to
begin_user_action. See that function for a full explanation.
- do_insert_child_anchor(iter: TextIter, anchor: 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
get_sliceandget_text.Consider
create_child_anchoras a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion.- Parameters:
iter – location to insert the anchor
anchor – a
GtkTextChildAnchor
- do_insert_paintable(iter: TextIter, paintable: 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
get_sliceandget_text.- Parameters:
iter – location to insert the paintable
paintable – a
GdkPaintable
- do_insert_text(pos: TextIter, new_text: str, new_text_length: int) None#
The type of the None singleton.
- Parameters:
pos
new_text
new_text_length
- do_mark_set(location: TextIter, mark: TextMark) None#
The type of the None singleton.
- Parameters:
location
mark
- do_remove_tag(tag: TextTag, start: TextIter, end: TextIter) None#
Emits the “remove-tag” signal.
The default handler for the signal removes all occurrences of
tagfrom the given range.startandenddon’t have to be in order.- Parameters:
tag – a
GtkTextTagstart – one bound of range to be untagged
end – other bound of range to be untagged