Gtk.TextBuffer¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r |
The list of targets this buffer supports for clipboard copying and DND source |
||
r |
The position of the insert mark (as offset from the beginning of the buffer) |
||
r |
Whether the buffer has some text currently selected |
||
r |
The list of targets this buffer supports for clipboard pasting and DND destination |
||
r/w/co |
Text Tag Table |
||
r/w |
Current text of the buffer |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The paste-done signal is emitted after paste operation has been completed. |
|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.TextBuffer(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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.
- classmethod new(table)[source]¶
- Parameters:
table (
Gtk.TextTagTable
orNone
) – a tag table, orNone
to create a new one- Returns:
a new text buffer
- Return type:
Creates a new text buffer.
- add_mark(mark, where)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – the mark to addwhere (
Gtk.TextIter
) – location to place mark
Adds the mark at position where. The mark must not be added to another buffer, and if its name is not
None
then there must not be another mark in the buffer with the same name.Emits the
Gtk.TextBuffer
::mark-set
signal as notification of the mark’s initial placement.New in version 2.12.
- add_selection_clipboard(clipboard)[source]¶
- Parameters:
clipboard (
Gtk.Clipboard
) – aGtk.Clipboard
Adds clipboard to the list of clipboards in which the selection contents of self are available. In most cases, clipboard will be the
Gtk.Clipboard
of type %GDK_SELECTION_PRIMARY for a view of self.
- apply_tag(tag, start, end)[source]¶
- Parameters:
tag (
Gtk.TextTag
) – aGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be taggedend (
Gtk.TextIter
) – other bound of range to be tagged
Emits the “apply-tag” signal on self. The default handler for the signal applies tag to the given range. start and end do not have to be in order.
- apply_tag_by_name(name, start, end)[source]¶
- Parameters:
name (
str
) – name of a namedGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be taggedend (
Gtk.TextIter
) – other bound of range to be tagged
Calls
Gtk.TextTagTable.lookup
() on the buffer’s tag table to get aGtk.TextTag
, then callsGtk.TextBuffer.apply_tag
().
- backspace(iter, interactive, default_editable)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – a position in selfinteractive (
bool
) – whether the deletion is caused by user interactiondefault_editable (
bool
) – whether the buffer is editable by default
- Returns:
True
if the buffer was modified- Return type:
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.
New in version 2.6.
- begin_user_action()[source]¶
Called to indicate that the buffer operations between here and a call to
Gtk.TextBuffer.end_user_action
() are part of a single user-visible operation. The operations betweenGtk.TextBuffer.begin_user_action
() andGtk.TextBuffer.end_user_action
() can then be grouped when creating an undo stack.Gtk.TextBuffer
maintains a count of calls toGtk.TextBuffer.begin_user_action
() that have not been closed with a call toGtk.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
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.
- copy_clipboard(clipboard)[source]¶
- Parameters:
clipboard (
Gtk.Clipboard
) – theGtk.Clipboard
object to copy to
Copies the currently-selected text to a clipboard.
- create_child_anchor(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – location in the buffer- Returns:
the created child anchor
- Return type:
This is a convenience function which simply creates a child anchor with
Gtk.TextChildAnchor.new
() and inserts it into the buffer withGtk.TextBuffer.insert_child_anchor
(). The new anchor is owned by the buffer; no reference count is returned to the caller ofGtk.TextBuffer.create_child_anchor
().
- create_mark(mark_name, where, left_gravity)[source]¶
- Parameters:
where (
Gtk.TextIter
) – location to place markleft_gravity (
bool
) – whether the mark has left gravity
- Returns:
the new
Gtk.TextMark
object- Return type:
Creates a mark at position where. If mark_name is
None
, the mark is anonymous; otherwise, the mark can be retrieved by name usingGtk.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 =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
Gtk.TextMark
, 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
Gtk.TextBuffer
::mark-set
signal as notification of the mark’s initial placement.
- create_tag(tag_name=None, **properties)[source]¶
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
- Returns:
A new tag.
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 calledtag_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)
- cut_clipboard(clipboard, default_editable)[source]¶
- Parameters:
clipboard (
Gtk.Clipboard
) – theGtk.Clipboard
object to cut todefault_editable (
bool
) – default editability of the buffer
Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
- delete(start, end)[source]¶
- Parameters:
start (
Gtk.TextIter
) – a position in selfend (
Gtk.TextIter
) – another position in self
Deletes text between start and end. The order of start and end is not actually relevant;
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.
- delete_interactive(start_iter, end_iter, default_editable)[source]¶
- Parameters:
start_iter (
Gtk.TextIter
) – start of range to deleteend_iter (
Gtk.TextIter
) – end of rangedefault_editable (
bool
) – whether the buffer is editable by default
- Returns:
whether some text was actually deleted
- Return type:
Deletes all editable text in the given range. Calls
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.
- delete_mark(mark)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – aGtk.TextMark
in self
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
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 withGtk.TextBuffer.add_mark
(). UseGtk.TextMark.get_deleted
() to find out if a mark has been removed from its buffer. TheGtk.TextBuffer
::mark-deleted
signal will be emitted as notification after the mark is deleted.
- delete_mark_by_name(name)[source]¶
- Parameters:
name (
str
) – name of a mark in self
Deletes the mark named name; the mark must exist. See
Gtk.TextBuffer.delete_mark
() for details.
- delete_selection(interactive, default_editable)[source]¶
- Parameters:
- Returns:
whether there was a non-empty selection to delete
- Return type:
Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text. If interactive is
True
, the editability of the selection will be considered (users can’t delete uneditable text).
- deserialize(content_buffer, format, iter, data)[source]¶
- Parameters:
content_buffer (
Gtk.TextBuffer
) – theGtk.TextBuffer
to deserialize intoformat (
Gdk.Atom
) – the rich text format to use for deserializingiter (
Gtk.TextIter
) – insertion point for the deserialized textdata (
bytes
) – data to deserialize
- Raises:
- Returns:
- Return type:
This function deserializes rich text in format format and inserts it at iter.
formats to be used must be registered using
Gtk.TextBuffer.register_deserialize_format
() orGtk.TextBuffer.register_deserialize_tagset
() beforehand.New in version 2.10.
- deserialize_get_can_create_tags(format)[source]¶
- Parameters:
format (
Gdk.Atom
) – aGdk.Atom
representing a registered rich text format- Returns:
whether deserializing this format may create tags
- Return type:
This functions returns the value set with
Gtk.TextBuffer.deserialize_set_can_create_tags
()New in version 2.10.
- deserialize_set_can_create_tags(format, can_create_tags)[source]¶
- Parameters:
Use this function to allow a rich text deserialization function to create new tags in the receiving buffer. Note that using this function is almost always a bad idea, because the rich text functions you register should know how to map the rich text format they handler to your text buffers set of tags.
The ability of creating new (arbitrary!) tags in the receiving buffer is meant for special rich text formats like the internal one that is registered using
Gtk.TextBuffer.register_deserialize_tagset
(), because that format is essentially a dump of the internal structure of the source buffer, including its tag names.You should allow creation of tags only if you know what you are doing, e.g. if you defined a tagset name for your application suite’s text buffers and you know that it’s fine to receive new tags from these buffers, because you know that your application can handle the newly created tags.
New in version 2.10.
- end_user_action()[source]¶
Should be paired with a call to
Gtk.TextBuffer.begin_user_action
(). See that function for a full explanation.
- get_bounds()[source]¶
- Returns:
- start:
iterator to initialize with first position in the buffer
- end:
iterator to initialize with the end iterator
- Return type:
(start:
Gtk.TextIter
, end:Gtk.TextIter
)
Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [start,`end`).
- get_char_count()[source]¶
- Returns:
number of characters in the buffer
- Return type:
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_copy_target_list()[source]¶
- Returns:
the
Gtk.TargetList
- Return type:
This function returns the list of targets this text buffer can provide for copying and as DND source. The targets in the list are added with info values from the
Gtk.TextBufferTargetInfo
enum, usingGtk.TargetList.add_rich_text_targets
() andGtk.TargetList.add_text_targets
().New in version 2.10.
- get_deserialize_formats()[source]¶
-
This function returns the rich text deserialize formats registered with self using
Gtk.TextBuffer.register_deserialize_format
() orGtk.TextBuffer.register_deserialize_tagset
()New in version 2.10.
- get_end_iter()[source]¶
- Returns:
iterator to initialize
- Return type:
iter:
Gtk.TextIter
Initializes iter with the “end iterator,” one past the last valid character in the text buffer. If dereferenced with
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 (callGtk.TextBuffer.get_start_iter
() to get character position 0) to the end iterator.
- get_has_selection()[source]¶
-
Indicates whether the buffer has some text currently selected.
New in version 2.10.
- get_insert()[source]¶
- Returns:
insertion point mark
- Return type:
Returns the mark that represents the cursor (insertion point). Equivalent to calling
Gtk.TextBuffer.get_mark
() to get the mark named “insert”, but very slightly more efficient, and involves less typing.
- get_iter_at_child_anchor(anchor)[source]¶
- Parameters:
anchor (
Gtk.TextChildAnchor
) – a child anchor that appears in self- Returns:
an iterator to be initialized
- Return type:
iter:
Gtk.TextIter
Obtains the location of anchor within self.
- get_iter_at_line(line_number)[source]¶
- Parameters:
line_number (
int
) – line number counting from 0- Returns:
iterator to initialize
- Return type:
iter:
Gtk.TextIter
Initializes iter to the start of the given line. If line_number is greater than the number of lines in the self, the end iterator is returned.
- get_iter_at_line_index(line_number, byte_index)[source]¶
- Parameters:
- Returns:
iterator to initialize
- Return type:
iter:
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.
Before the 3.20 version, it was not allowed to pass an invalid location.
Since the 3.20 version, if line_number is greater than the number of lines in the self, 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.
- get_iter_at_line_offset(line_number, char_offset)[source]¶
- Parameters:
- Returns:
iterator to initialize
- Return type:
iter:
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.
Before the 3.20 version, it was not allowed to pass an invalid location.
Since the 3.20 version, if line_number is greater than the number of lines in the self, 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.
- get_iter_at_mark(mark)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – aGtk.TextMark
in self- Returns:
iterator to initialize
- Return type:
iter:
Gtk.TextIter
Initializes iter with the current position of mark.
- get_iter_at_offset(char_offset)[source]¶
- Parameters:
char_offset (
int
) –str
offset from start of buffer, counting from 0, or -1- Returns:
iterator to initialize
- Return type:
iter:
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.
- get_line_count()[source]¶
- Returns:
number of lines in the buffer
- Return type:
Obtains the number of lines in the buffer. This value is cached, so the function is very fast.
- get_mark(name)[source]¶
- Parameters:
name (
str
) – a mark name- Returns:
a
Gtk.TextMark
, orNone
- Return type:
Gtk.TextMark
orNone
Returns the mark named name in buffer self, or
None
if no such mark exists in the buffer.
- get_modified()[source]¶
-
Indicates whether the buffer has been modified since the last call to
Gtk.TextBuffer.set_modified
() set the modification flag toFalse
. Used for example to enable a “save” function in a text editor.
- get_paste_target_list()[source]¶
- Returns:
the
Gtk.TargetList
- Return type:
This function returns the list of targets this text buffer supports for pasting and as DND destination. The targets in the list are added with info values from the
Gtk.TextBufferTargetInfo
enum, usingGtk.TargetList.add_rich_text_targets
() andGtk.TargetList.add_text_targets
().New in version 2.10.
- get_selection_bound()[source]¶
- Returns:
selection bound mark
- Return type:
Returns the mark that represents the selection bound. Equivalent to calling
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 self 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.
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.
- get_selection_bounds()[source]¶
- Returns:
If there is no selection returns an empty tuple otherwise a tuple containing:
- start:
selection start
- end:
selection end
- Return type:
(start:
Gtk.TextIter
, end:Gtk.TextIter
) orNone
Returns
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 areNone
, then they are not filled in, but the return value still indicates whether text is selected.
- get_serialize_formats()[source]¶
-
This function returns the rich text serialize formats registered with self using
Gtk.TextBuffer.register_serialize_format
() orGtk.TextBuffer.register_serialize_tagset
()New in version 2.10.
- get_slice(start, end, include_hidden_chars)[source]¶
- Parameters:
start (
Gtk.TextIter
) – start of a rangeend (
Gtk.TextIter
) – end of a rangeinclude_hidden_chars (
bool
) – whether to include invisible text
- Returns:
an allocated UTF-8 string
- Return type:
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
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 withGtk.TextBuffer.get_text
(). Note that 0xFFFC can occur in normal text as well, so it is not a reliable indicator that a pixbuf or widget is in the buffer.
- get_start_iter()[source]¶
- Returns:
iterator to initialize
- Return type:
iter:
Gtk.TextIter
Initialized iter with the first position in the text buffer. This is the same as using
Gtk.TextBuffer.get_iter_at_offset
() to get the iter at character offset 0.
- get_tag_table()[source]¶
- Returns:
the buffer’s tag table
- Return type:
Get the
Gtk.TextTagTable
associated with this buffer.
- get_text(start, end, include_hidden_chars)[source]¶
- Parameters:
start (
Gtk.TextIter
) – start of a rangeend (
Gtk.TextIter
) – end of a rangeinclude_hidden_chars (
bool
) – whether to include invisible text
- Returns:
an allocated UTF-8 string
- Return type:
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
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 withGtk.TextBuffer.get_slice
().
- insert(iter, text, length=-1)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – a position in the buffertext (
str
) – text in UTF-8 formatlen (
int
) – length of text in bytes, or -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.
- insert_at_cursor(text, len)[source]¶
-
Simply calls
Gtk.TextBuffer.insert
(), using the current cursor position as the insertion point.
- insert_child_anchor(iter, anchor)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – location to insert the anchoranchor (
Gtk.TextChildAnchor
) – aGtk.TextChildAnchor
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
Gtk.TextBuffer.get_slice
() andGtk.TextBuffer.get_text
(). ConsiderGtk.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.
- insert_interactive(iter, text, len, default_editable)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – a position in selftext (
str
) – some UTF-8 textlen (
int
) – length of text in bytes, or -1default_editable (
bool
) – default editability of buffer
- Returns:
whether text was actually inserted
- Return type:
Like
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
Gtk.TextView.get_editable
() is appropriate here.
- insert_interactive_at_cursor(text, len, default_editable)[source]¶
- Parameters:
- Returns:
whether text was actually inserted
- Return type:
Calls
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
Gtk.TextView.get_editable
() is appropriate here.
- insert_markup(iter, markup, len)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – location to insert the markupmarkup (
str
) – a nul-terminated UTF-8 string containing Pango markuplen (
int
) – length of markup in bytes, or -1
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
Gtk.TextBuffer
::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.New in version 3.16.
- insert_pixbuf(iter, pixbuf)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – location to insert the pixbufpixbuf (
GdkPixbuf.Pixbuf
) – aGdkPixbuf.Pixbuf
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 pixbufs, but the “text” variants do not. e.g. see
Gtk.TextBuffer.get_slice
() andGtk.TextBuffer.get_text
().
- insert_range(iter, start, end)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – a position in selfstart (
Gtk.TextIter
) – a position in aGtk.TextBuffer
end (
Gtk.TextIter
) – another position in the same buffer as start
Copies text, tags, and pixbufs between start and end (the order of start and end doesn’t matter) and inserts the copy at iter. Used instead of simply getting/inserting text because it preserves images and tags. If start and end are in a different buffer from self, the two buffers must share the same tag table.
Implemented via emissions of the insert_text and apply_tag signals, so expect those.
- insert_range_interactive(iter, start, end, default_editable)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – a position in selfstart (
Gtk.TextIter
) – a position in aGtk.TextBuffer
end (
Gtk.TextIter
) – another position in the same buffer as startdefault_editable (
bool
) – default editability of the buffer
- Returns:
whether an insertion was possible at iter
- Return type:
Same as
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 ofGtk.TextView.get_editable
() is appropriate here.
- insert_with_tags(iter, text, *tags)[source]¶
Inserts text into self at iter, applying the list of tags to the newly-inserted text. The last tag specified must be
None
to terminate the list. Equivalent to callingGtk.TextBuffer.insert
(), thenGtk.TextBuffer.apply_tag
() on the inserted text;Gtk.TextBuffer.insert_with_tags
() is just a convenience function.
- insert_with_tags_by_name(iter, text, *tags)[source]¶
Same as
Gtk.TextBuffer.insert_with_tags
(), but allows you to pass in tag names instead of tag objects.
- move_mark(mark, where)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – aGtk.TextMark
where (
Gtk.TextIter
) – new location for mark in self
Moves mark to the new location where. Emits the
Gtk.TextBuffer
::mark-set
signal as notification of the move.
- move_mark_by_name(name, where)[source]¶
- Parameters:
name (
str
) – name of a markwhere (
Gtk.TextIter
) – new location for mark
Moves the mark named name (which must exist) to location where. See
Gtk.TextBuffer.move_mark
() for details.
- paste_clipboard(clipboard, override_location, default_editable)[source]¶
- Parameters:
clipboard (
Gtk.Clipboard
) – theGtk.Clipboard
to paste fromoverride_location (
Gtk.TextIter
orNone
) – location to insert pasted text, orNone
default_editable (
bool
) – whether the buffer is editable by default
Pastes the contents of a clipboard. If override_location is
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.
- place_cursor(where)[source]¶
- Parameters:
where (
Gtk.TextIter
) – where to put the cursor
This function moves the “insert” and “selection_bound” marks simultaneously. If you move them to the same place in two steps with
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.
- register_deserialize_format(mime_type, function, *user_data)[source]¶
- Parameters:
mime_type (
str
) – the format’s mime-typefunction (
Gtk.TextBufferDeserializeFunc
) – the deserialize function to register
- Returns:
the
Gdk.Atom
that corresponds to the newly registered format’s mime-type.- Return type:
This function registers a rich text deserialization function along with its mime_type with the passed self.
New in version 2.10.
- register_deserialize_tagset(tagset_name)[source]¶
- Parameters:
tagset_name (
str
orNone
) – an optional tagset name, onNone
- Returns:
the
Gdk.Atom
that corresponds to the newly registered format’s mime-type.- Return type:
This function registers GTK+’s internal rich text serialization format with the passed self. See
Gtk.TextBuffer.register_serialize_tagset
() for details.New in version 2.10.
- register_serialize_format(mime_type, function, *user_data)[source]¶
- Parameters:
mime_type (
str
) – the format’s mime-typefunction (
Gtk.TextBufferSerializeFunc
) – the serialize function to register
- Returns:
the
Gdk.Atom
that corresponds to the newly registered format’s mime-type.- Return type:
This function registers a rich text serialization function along with its mime_type with the passed self.
New in version 2.10.
- register_serialize_tagset(tagset_name)[source]¶
- Parameters:
tagset_name (
str
orNone
) – an optional tagset name, onNone
- Returns:
the
Gdk.Atom
that corresponds to the newly registered format’s mime-type.- Return type:
This function registers GTK+’s internal rich text serialization format with the passed self. The internal format does not comply to any standard rich text format and only works between
Gtk.TextBuffer
instances. It is capable of serializing all of a text buffer’s tags and embedded pixbufs.This function is just a wrapper around
Gtk.TextBuffer.register_serialize_format
(). The mime type used for registering is “application/x-gtk-text-buffer-rich-text”, or “application/x-gtk-text-buffer-rich-text;format=`tagset_name`” if a tagset_name was passed.The tagset_name can be used to restrict the transfer of rich text to buffers with compatible sets of tags, in order to avoid unknown tags from being pasted. It is probably the common case to pass an identifier !=
None
here, since theNone
tagset requires the receiving buffer to deal with with pasting of arbitrary tags.New in version 2.10.
- remove_all_tags(start, end)[source]¶
- Parameters:
start (
Gtk.TextIter
) – one bound of range to be untaggedend (
Gtk.TextIter
) – other bound of range to be untagged
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.
- remove_selection_clipboard(clipboard)[source]¶
- Parameters:
clipboard (
Gtk.Clipboard
) – aGtk.Clipboard
added to self byGtk.TextBuffer.add_selection_clipboard
()
Removes a
Gtk.Clipboard
added withGtk.TextBuffer.add_selection_clipboard
().
- remove_tag(tag, start, end)[source]¶
- Parameters:
tag (
Gtk.TextTag
) – aGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be untaggedend (
Gtk.TextIter
) – other bound of range to be untagged
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.
- remove_tag_by_name(name, start, end)[source]¶
- Parameters:
name (
str
) – name of aGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be untaggedend (
Gtk.TextIter
) – other bound of range to be untagged
Calls
Gtk.TextTagTable.lookup
() on the buffer’s tag table to get aGtk.TextTag
, then callsGtk.TextBuffer.remove_tag
().
- select_range(ins, bound)[source]¶
- Parameters:
ins (
Gtk.TextIter
) – where to put the “insert” markbound (
Gtk.TextIter
) – where to put the “selection_bound” mark
This function moves the “insert” and “selection_bound” marks simultaneously. If you move them in two steps with
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.New in version 2.4.
- serialize(content_buffer, format, start, end)[source]¶
- Parameters:
content_buffer (
Gtk.TextBuffer
) – theGtk.TextBuffer
to serializeformat (
Gdk.Atom
) – the rich text format to use for serializingstart (
Gtk.TextIter
) – start of block of text to serializeend (
Gtk.TextIter
) – end of block of test to serialize
- Returns:
the serialized data, encoded as format
- Return type:
This function serializes the portion of text between start and end in the rich text format represented by format.
formats to be used must be registered using
Gtk.TextBuffer.register_serialize_format
() orGtk.TextBuffer.register_serialize_tagset
() beforehand.New in version 2.10.
- set_modified(setting)[source]¶
- Parameters:
setting (
bool
) – modification flag setting
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.TextBuffer.set_modified
(self,False
). When the buffer is modified, it will automatically toggled on the modified bit again. When the modified bit flips, the buffer emits theGtk.TextBuffer
::modified-changed
signal.
- set_text(text, length=-1)[source]¶
-
Deletes current contents of self, and inserts text instead. If len is -1, text must be nul-terminated. text must be valid UTF-8.
- unregister_deserialize_format(format)[source]¶
-
This function unregisters a rich text format that was previously registered using
Gtk.TextBuffer.register_deserialize_format
() orGtk.TextBuffer.register_deserialize_tagset
().New in version 2.10.
- unregister_serialize_format(format)[source]¶
-
This function unregisters a rich text format that was previously registered using
Gtk.TextBuffer.register_serialize_format
() orGtk.TextBuffer.register_serialize_tagset
()New in version 2.10.
- do_apply_tag(tag, start, end) virtual¶
- Parameters:
tag (
Gtk.TextTag
) – aGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be taggedend (
Gtk.TextIter
) – other bound of range to be tagged
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.
- do_begin_user_action() virtual¶
Called to indicate that the buffer operations between here and a call to
Gtk.TextBuffer.end_user_action
() are part of a single user-visible operation. The operations betweenGtk.TextBuffer.begin_user_action
() andGtk.TextBuffer.end_user_action
() can then be grouped when creating an undo stack.Gtk.TextBuffer
maintains a count of calls toGtk.TextBuffer.begin_user_action
() that have not been closed with a call toGtk.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
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.
- do_changed() virtual¶
The class handler for the
Gtk.TextBuffer
::changed
signal.
- do_delete_range(start, end) virtual¶
- Parameters:
start (
Gtk.TextIter
) –end (
Gtk.TextIter
) –
The class handler for the
Gtk.TextBuffer
::delete-range
signal.
- do_end_user_action() virtual¶
Should be paired with a call to
Gtk.TextBuffer.begin_user_action
(). See that function for a full explanation.
- do_insert_child_anchor(iter, anchor) virtual¶
- Parameters:
iter (
Gtk.TextIter
) – location to insert the anchoranchor (
Gtk.TextChildAnchor
) – aGtk.TextChildAnchor
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
Gtk.TextBuffer.get_slice
() andGtk.TextBuffer.get_text
(). ConsiderGtk.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.
- do_insert_pixbuf(iter, pixbuf) virtual¶
- Parameters:
iter (
Gtk.TextIter
) – location to insert the pixbufpixbuf (
GdkPixbuf.Pixbuf
) – aGdkPixbuf.Pixbuf
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 pixbufs, but the “text” variants do not. e.g. see
Gtk.TextBuffer.get_slice
() andGtk.TextBuffer.get_text
().
- do_insert_text(pos, new_text, new_text_length) virtual¶
- Parameters:
pos (
Gtk.TextIter
) –new_text (
str
) –new_text_length (
int
) –
The class handler for the
Gtk.TextBuffer
::insert-text
signal.
- do_mark_deleted(mark) virtual¶
- Parameters:
mark (
Gtk.TextMark
) –
The class handler for the
Gtk.TextBuffer
::mark-deleted
signal.
- do_mark_set(location, mark) virtual¶
- Parameters:
location (
Gtk.TextIter
) –mark (
Gtk.TextMark
) –
The class handler for the
Gtk.TextBuffer
::mark-set
signal.
- do_modified_changed() virtual¶
The class handler for the
Gtk.TextBuffer
::modified-changed
signal.
- do_paste_done(clipboard) virtual¶
- Parameters:
clipboard (
Gtk.Clipboard
) –
The class handler for the
Gtk.TextBuffer
::paste-done
signal.
- do_remove_tag(tag, start, end) virtual¶
- Parameters:
tag (
Gtk.TextTag
) – aGtk.TextTag
start (
Gtk.TextIter
) – one bound of range to be untaggedend (
Gtk.TextIter
) – other bound of range to be untagged
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.
Signal Details¶
- Gtk.TextBuffer.signals.apply_tag(text_buffer, tag, start, end)¶
- Signal Name:
apply-tag
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signaltag (
Gtk.TextTag
) – the applied tagstart (
Gtk.TextIter
) – the start of the range the tag is applied toend (
Gtk.TextIter
) – the end of the range the tag is applied to
The
::apply-tag
signal is emitted to apply a tag to a range of text in aGtk.TextBuffer
. 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:
Gtk.TextBuffer.apply_tag
(),Gtk.TextBuffer.insert_with_tags
(),Gtk.TextBuffer.insert_range
().
- Gtk.TextBuffer.signals.begin_user_action(text_buffer)¶
- Signal Name:
begin-user-action
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signal
The
::begin-user-action
signal is emitted at the beginning of a single user-visible operation on aGtk.TextBuffer
.See also:
Gtk.TextBuffer.begin_user_action
(),Gtk.TextBuffer.insert_interactive
(),Gtk.TextBuffer.insert_range_interactive
(),Gtk.TextBuffer.delete_interactive
(),Gtk.TextBuffer.backspace
(),Gtk.TextBuffer.delete_selection
().
- Gtk.TextBuffer.signals.changed(text_buffer)¶
- Signal Name:
changed
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signal
The
::changed
signal is emitted when the content of aGtk.TextBuffer
has changed.
- Gtk.TextBuffer.signals.delete_range(text_buffer, start, end)¶
- Signal Name:
delete-range
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signalstart (
Gtk.TextIter
) – the start of the range to be deletedend (
Gtk.TextIter
) – the end of the range to be deleted
The
::delete-range
signal is emitted to delete a range from aGtk.TextBuffer
.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 g_signal_connect_after()) do not have access to the deleted text.
See also:
Gtk.TextBuffer.delete
().
- Gtk.TextBuffer.signals.end_user_action(text_buffer)¶
- Signal Name:
end-user-action
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signal
The
::end-user-action
signal is emitted at the end of a single user-visible operation on theGtk.TextBuffer
.See also:
Gtk.TextBuffer.end_user_action
(),Gtk.TextBuffer.insert_interactive
(),Gtk.TextBuffer.insert_range_interactive
(),Gtk.TextBuffer.delete_interactive
(),Gtk.TextBuffer.backspace
(),Gtk.TextBuffer.delete_selection
(),Gtk.TextBuffer.backspace
().
- Gtk.TextBuffer.signals.insert_child_anchor(text_buffer, location, anchor)¶
- Signal Name:
insert-child-anchor
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signallocation (
Gtk.TextIter
) – position to insert anchor in textbufferanchor (
Gtk.TextChildAnchor
) – theGtk.TextChildAnchor
to be inserted
The
::insert-child-anchor
signal is emitted to insert aGtk.TextChildAnchor
in aGtk.TextBuffer
. 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:
Gtk.TextBuffer.insert_child_anchor
().
- Gtk.TextBuffer.signals.insert_pixbuf(text_buffer, location, pixbuf)¶
- Signal Name:
insert-pixbuf
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signallocation (
Gtk.TextIter
) – position to insert pixbuf in textbufferpixbuf (
GdkPixbuf.Pixbuf
) – theGdkPixbuf.Pixbuf
to be inserted
The
::insert-pixbuf
signal is emitted to insert aGdkPixbuf.Pixbuf
in aGtk.TextBuffer
. 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 pixbuf.
See also:
Gtk.TextBuffer.insert_pixbuf
().
- Gtk.TextBuffer.signals.insert_text(text_buffer, location, text, len)¶
- Signal Name:
insert-text
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signallocation (
Gtk.TextIter
) – position to insert text in textbuffertext (
str
) – the UTF-8 text to be insertedlen (
int
) – length of the inserted text in bytes
The
::insert-text
signal is emitted to insert text in aGtk.TextBuffer
. 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:
Gtk.TextBuffer.insert
(),Gtk.TextBuffer.insert_range
().
- Gtk.TextBuffer.signals.mark_deleted(text_buffer, mark)¶
- Signal Name:
mark-deleted
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signalmark (
Gtk.TextMark
) – The mark that was deleted
The
::mark-deleted
signal is emitted as notification after aGtk.TextMark
is deleted.See also:
Gtk.TextBuffer.delete_mark
().
- Gtk.TextBuffer.signals.mark_set(text_buffer, location, mark)¶
- Signal Name:
mark-set
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signallocation (
Gtk.TextIter
) – The location of mark in textbuffermark (
Gtk.TextMark
) – The mark that is set
The
::mark-set
signal is emitted as notification after aGtk.TextMark
is set.See also:
Gtk.TextBuffer.create_mark
(),Gtk.TextBuffer.move_mark
().
- Gtk.TextBuffer.signals.modified_changed(text_buffer)¶
- Signal Name:
modified-changed
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signal
The
::modified-changed
signal is emitted when the modified bit of aGtk.TextBuffer
flips.See also:
Gtk.TextBuffer.set_modified
().
- Gtk.TextBuffer.signals.paste_done(text_buffer, clipboard)¶
- Signal Name:
paste-done
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signalclipboard (
Gtk.Clipboard
) – theGtk.Clipboard
pasted from
The paste-done signal is emitted after paste operation has been completed. This is useful to properly scroll the view to the end of the pasted text. See
Gtk.TextBuffer.paste_clipboard
() for more details.New in version 2.16.
- Gtk.TextBuffer.signals.remove_tag(text_buffer, tag, start, end)¶
- Signal Name:
remove-tag
- Flags:
- Parameters:
text_buffer (
Gtk.TextBuffer
) – The object which received the signaltag (
Gtk.TextTag
) – the tag to be removedstart (
Gtk.TextIter
) – the start of the range the tag is removed fromend (
Gtk.TextIter
) – the end of the range the tag is removed from
The
::remove-tag
signal is emitted to remove all occurrences of tag from a range of text in aGtk.TextBuffer
. 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:
Gtk.TextBuffer.remove_tag
().
Property Details¶
- Gtk.TextBuffer.props.copy_target_list¶
- Name:
copy-target-list
- Type:
- Default Value:
- Flags:
The list of targets this buffer supports for clipboard copying and as DND source.
New in version 2.10.
- Gtk.TextBuffer.props.cursor_position¶
-
The position of the insert mark (as offset from the beginning of the buffer). It is useful for getting notified when the cursor moves.
New in version 2.10.
- Gtk.TextBuffer.props.has_selection¶
-
Whether the buffer has some text currently selected.
New in version 2.10.
- Gtk.TextBuffer.props.paste_target_list¶
- Name:
paste-target-list
- Type:
- Default Value:
- Flags:
The list of targets this buffer supports for clipboard pasting and as DND destination.
New in version 2.10.
- Gtk.TextBuffer.props.tag_table¶
- Name:
tag-table
- Type:
- Default Value:
- Flags:
Text Tag Table
- Gtk.TextBuffer.props.text¶
-
The text content of the buffer. Without child widgets and images, see
Gtk.TextBuffer.get_text
() for more information.New in version 2.8.