Gtk.TextBuffer
Gtk.TextBuffer — Stores attributed text for display in a Gtk.TextView
Object Hierarchy:
GObject
╰── Gtk.TextBuffer
See also:
Gtk.TextView, Gtk.TextIter, Gtk.TextMark
Functions:
- new
(table:Gtk.TextTagTable=None) -> Gtk.TextBuffer
- get_line_count
(self) -> int
- get_char_count
(self) -> int
- get_tag_table
(self) -> Gtk.TextTagTable
- insert
(self, iter:Gtk.TextIter, text:str, len:int)
- insert_at_cursor
(self, text:str, len:int)
- insert_interactive
(self, iter:Gtk.TextIter, text:str, len:int, default_editable:bool) -> bool
- insert_interactive_at_cursor
(self, text:str, len:int, default_editable:bool) -> bool
- insert_range
(self, iter:Gtk.TextIter, start:Gtk.TextIter, end:Gtk.TextIter)
- insert_range_interactive
(self, iter:Gtk.TextIter, start:Gtk.TextIter, end:Gtk.TextIter, default_editable:bool) -> bool
- insert_markup
(self, iter:Gtk.TextIter, markup:str, len:int)
- delete
(self, start:Gtk.TextIter, end:Gtk.TextIter)
- delete_interactive
(self, start_iter:Gtk.TextIter, end_iter:Gtk.TextIter, default_editable:bool) -> bool
- backspace
(self, iter:Gtk.TextIter, interactive:bool, default_editable:bool) -> bool
- set_text
(self, text:str, len:int)
- get_text
(self, start:Gtk.TextIter, end:Gtk.TextIter, include_hidden_chars:bool) -> str
- get_slice
(self, start:Gtk.TextIter, end:Gtk.TextIter, include_hidden_chars:bool) -> str
- insert_pixbuf
(self, iter:Gtk.TextIter, pixbuf:GdkPixbuf.Pixbuf)
- insert_child_anchor
(self, iter:Gtk.TextIter, anchor:Gtk.TextChildAnchor)
- create_child_anchor
(self, iter:Gtk.TextIter) -> Gtk.TextChildAnchor
- create_mark
(self, mark_name:str=None, where:Gtk.TextIter, left_gravity:bool) -> Gtk.TextMark
- move_mark
(self, mark:Gtk.TextMark, where:Gtk.TextIter)
- move_mark_by_name
(self, name:str, where:Gtk.TextIter)
- add_mark
(self, mark:Gtk.TextMark, where:Gtk.TextIter)
- delete_mark
(self, mark:Gtk.TextMark)
- delete_mark_by_name
(self, name:str)
- get_mark
(self, name:str) -> Gtk.TextMark
- get_insert
(self) -> Gtk.TextMark
- get_selection_bound
(self) -> Gtk.TextMark
- get_has_selection
(self) -> bool
- place_cursor
(self, where:Gtk.TextIter)
- select_range
(self, ins:Gtk.TextIter, bound:Gtk.TextIter)
- apply_tag
(self, tag:Gtk.TextTag, start:Gtk.TextIter, end:Gtk.TextIter)
- remove_tag
(self, tag:Gtk.TextTag, start:Gtk.TextIter, end:Gtk.TextIter)
- apply_tag_by_name
(self, name:str, start:Gtk.TextIter, end:Gtk.TextIter)
- remove_tag_by_name
(self, name:str, start:Gtk.TextIter, end:Gtk.TextIter)
- remove_all_tags
(self, start:Gtk.TextIter, end:Gtk.TextIter)
- get_iter_at_line_offset
(self, line_number:int, char_offset:int) -> iter:Gtk.TextIter
- get_iter_at_offset
(self, char_offset:int) -> iter:Gtk.TextIter
- get_iter_at_line
(self, line_number:int) -> iter:Gtk.TextIter
- get_iter_at_line_index
(self, line_number:int, byte_index:int) -> iter:Gtk.TextIter
- get_iter_at_mark
(self, mark:Gtk.TextMark) -> iter:Gtk.TextIter
- get_iter_at_child_anchor
(self, anchor:Gtk.TextChildAnchor) -> iter:Gtk.TextIter
- get_start_iter
(self) -> iter:Gtk.TextIter
- get_end_iter
(self) -> iter:Gtk.TextIter
- get_bounds
(self) -> start:Gtk.TextIter, end:Gtk.TextIter
- get_modified
(self) -> bool
- set_modified
(self, setting:bool)
- delete_selection
(self, interactive:bool, default_editable:bool) -> bool
- paste_clipboard
(self, clipboard:Gtk.Clipboard, override_location:Gtk.TextIter=None, default_editable:bool)
- copy_clipboard
(self, clipboard:Gtk.Clipboard)
- cut_clipboard
(self, clipboard:Gtk.Clipboard, default_editable:bool)
- begin_user_action
(self)
- end_user_action
(self)
- add_selection_clipboard
(self, clipboard:Gtk.Clipboard)
- remove_selection_clipboard
(self, clipboard:Gtk.Clipboard)
- deserialize
(self, content_buffer:Gtk.TextBuffer, format:Gdk.Atom, iter:Gtk.TextIter, data:list) -> bool
- deserialize_get_can_create_tags
(self, format:Gdk.Atom) -> bool
- deserialize_set_can_create_tags
(self, format:Gdk.Atom, can_create_tags:bool)
- get_copy_target_list
(self) -> Gtk.TargetList
- get_deserialize_formats
(self) -> list, n_formats:int
- get_paste_target_list
(self) -> Gtk.TargetList
- get_serialize_formats
(self) -> list, n_formats:int
- register_deserialize_format
(self, mime_type:str, function:Gtk.TextBufferDeserializeFunc, user_data=None) -> Gdk.Atom
- register_deserialize_tagset
(self, tagset_name:str=None) -> Gdk.Atom
- register_serialize_format
(self, mime_type:str, function:Gtk.TextBufferSerializeFunc, user_data=None) -> Gdk.Atom
- register_serialize_tagset
(self, tagset_name:str=None) -> Gdk.Atom
- serialize
(self, content_buffer:Gtk.TextBuffer, format:Gdk.Atom, start:Gtk.TextIter, end:Gtk.TextIter) -> list, length:int
- unregister_deserialize_format
(self, format:Gdk.Atom)
- unregister_serialize_format
(self, format:Gdk.Atom)
Signals:
- “apply-tag”
(textbuffer, tag, start, end, user_data)
- “begin-user-action”
(textbuffer, user_data)
- “changed”
(textbuffer, user_data)
- “delete-range”
(textbuffer, start, end, user_data)
- “end-user-action”
(textbuffer, user_data)
- “insert-child-anchor”
(textbuffer, location, anchor, user_data)
- “insert-pixbuf”
(textbuffer, location, pixbuf, user_data)
- “insert-text”
(textbuffer, location, text, len, user_data)
- “mark-deleted”
(textbuffer, mark, user_data)
- “mark-set”
(textbuffer, location, mark, user_data)
- “modified-changed”
(textbuffer, user_data)
- “paste-done”
(textbuffer, clipboard, user_data)
Description:
You may wish to begin by reading the [text widget conceptual overview][TextWidget] which gives an overview of all the objects and data types related to the text widget and how they work together.
Function Details:
new()
new (table:Gtk.TextTagTable=None) -> Gtk.TextBuffer
Creates a new text buffer.
- Returns: a new text buffer
get_line_count()
get_line_count (self) -> int
Obtains the number of lines in the buffer. This value is cached, sothe function is very fast.
- Returns: number of lines in the buffer
get_char_count()
get_char_count (self) -> int
Gets the number of characters in the buffer; note that charactersand bytes are not the same, you can’t e.g. expect the contents ofthe buffer in string form to be this many bytes long. The charactercount is cached, so this function is very fast.
- Returns: number of characters in the buffer
get_tag_table()
get_tag_table (self) -> Gtk.TextTagTable
Get the Gtk.TextTagTable
associated with this buffer.
- Returns: the buffer’s tag table.
insert()
insert (self, iter:Gtk.TextIter, text:str, len:int)
Inserts len
bytes of text
at position iter
. If len
is -1,text
must be nul-terminated and will be inserted in itsentirety. Emits the “insert-text” signal; insertion actually occursin the default handler for the signal. iter
is invalidated wheninsertion occurs (because the buffer contents change), but thedefault signal handler revalidates it to point to the end of theinserted text.
insert_at_cursor()
insert_at_cursor (self, text:str, len:int)
Simply calls Gtk.TextBuffer:insert()
, using the currentcursor position as the insertion point.
insert_interactive()
insert_interactive (self, iter:Gtk.TextIter, text:str, len:int, default_editable:bool) -> bool
Like Gtk.TextBuffer:insert()
, but the insertion will not occur ifiter
is at a non-editable location in the buffer. Usually youwant to prevent insertions at ineditable locations if the insertionresults from a user action (is interactive).
default_editable
indicates the editability of text that doesn'thave a tag affecting editability applied to it. Typically theresult of `Gtk.TextView:get_editable
()` is appropriate here.
- Returns: whether text was actually inserted
insert_interactive_at_cursor()
insert_interactive_at_cursor (self, text:str, len:int, default_editable:bool) -> bool
Calls Gtk.TextBuffer:insert_interactive()
at the cursorposition.
default_editable
indicates the editability of text that doesn'thave a tag affecting editability applied to it. Typically theresult of `Gtk.TextView:get_editable
()` is appropriate here.
- Returns: whether text was actually inserted
insert_range()
insert_range (self, iter:Gtk.TextIter, start:Gtk.TextIter, end:Gtk.TextIter)
Copies text, tags, and pixbufs between start
and end
(the orderof start
and end
doesn’t matter) and inserts the copy at iter
.Used instead of simply getting/inserting text because it preservesimages and tags. If start
and end
are 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.
insert_range_interactive()
insert_range_interactive (self, iter:Gtk.TextIter, start:Gtk.TextIter, end:Gtk.TextIter, default_editable:bool) -> bool
Same as Gtk.TextBuffer:insert_range()
, but does nothing if theinsertion point isn’t editable. The default_editable
parameterindicates whether the text is editable at iter
if no tagsenclosing iter
affect editability. Typically the result of`Gtk.TextView:get_editable
()` is appropriate here.
- Returns:
whether an insertion was possible at
iter
insert_markup()
insert_markup (self, iter:Gtk.TextIter, markup:str, len:int)
Inserts the text in markup
at position iter
. markup
will be insertedin its entirety and must be nul-terminated and valid UTF-8. Emits the“insert-text” signal, possibly multiple times; insertionactually occurs in the default handler for the signal. iter
will pointto the end of the inserted text on return.
- Since: 3.16
delete()
delete (self, start:Gtk.TextIter, end:Gtk.TextIter)
Deletes text between start
and end
. The order of start
and end
is not actually relevant; Gtk.TextBuffer:delete()
will reorderthem. This function actually emits the “delete-range” signal, andthe default handler of that signal deletes the text. Because thebuffer is modified, all outstanding iterators become invalid aftercalling this function; however, the start
and end
will bere-initialized to point to the location where text was deleted.
delete_interactive()
delete_interactive (self, start_iter:Gtk.TextIter, end_iter:Gtk.TextIter, default_editable:bool) -> bool
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 tothe location of the last deleted range, or left untouched ifno text was deleted.
- Returns: whether some text was actually deleted
backspace()
backspace (self, iter:Gtk.TextIter, interactive:bool, default_editable:bool) -> bool
Performs the appropriate action as if the user hit the deletekey with the cursor at the position specified by iter
. In thenormal case a single character will be deleted, but whencombining accents are involved, more than one character canbe deleted, and when precomposed character and accent combinationsare 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 bere-initialized to point to the location where text was deleted.
Returns:
True
if the buffer was modifiedSince: 2.6
set_text()
set_text (self, text:str, len:int)
Deletes current contents of buffer
, and inserts text
instead. Iflen
is -1, text
must be nul-terminated. text
must be valid UTF-8.
get_text()
get_text (self, start:Gtk.TextIter, end:Gtk.TextIter, include_hidden_chars:bool) -> str
Returns the text in the range [start
,end
). Excludes undisplayedtext (text marked with tags that set the invisibility attribute) ifinclude_hidden_chars
is FALSE
. Does not include charactersrepresenting embedded images, so byte and character indexes intothe returned string do not correspond to byteand character indexes into the buffer. Contrast withGtk.TextBuffer:get_slice()
.
- Returns: an allocated UTF-8 string
get_slice()
get_slice (self, start:Gtk.TextIter, end:Gtk.TextIter, include_hidden_chars:bool) -> str
Returns the text in the range [start
,end
). Excludes undisplayedtext (text marked with tags that set the invisibility attribute) ifinclude_hidden_chars
is FALSE
. The returned string includes a0xFFFC character whenever the buffer containsembedded images, so byte and character indexes intothe returned string do correspond to byteand character indexes into the buffer. Contrast withGtk.TextBuffer:get_text()
. Note that 0xFFFC can occur in normaltext as well, so it is not a reliable indicator that a pixbuf orwidget is in the buffer.
- Returns: an allocated UTF-8 string
insert_pixbuf()
insert_pixbuf (self, iter:Gtk.TextIter, pixbuf:GdkPixbuf.Pixbuf)
Inserts an image into the text buffer at iter
. The image will becounted as one character in character counts, and when obtainingthe 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 includethis character for pixbufs, but the “text” variants donot. e.g. see Gtk.TextBuffer:get_slice()
andGtk.TextBuffer:get_text()
.
insert_child_anchor()
insert_child_anchor (self, iter:Gtk.TextIter, anchor:Gtk.TextChildAnchor)
Inserts a child widget anchor into the text buffer at iter
. Theanchor will be counted as one character in character counts, andwhen obtaining the buffer contents as a string, will be representedby the Unicode “object replacement character” 0xFFFC. Note that the“slice” variants for obtaining portions of the buffer as a stringinclude this character for child anchors, but the “text” variants donot. E.g. see Gtk.TextBuffer:get_slice()
andGtk.TextBuffer:get_text()
. ConsiderGtk.TextBuffer:create_child_anchor()
as a more convenientalternative to this function. The buffer will add a reference tothe anchor, so you can unref it after insertion.
create_child_anchor()
create_child_anchor (self, iter:Gtk.TextIter) -> Gtk.TextChildAnchor
This is a convenience function which simply creates a child anchorwith `Gtk.TextChildAnchor:new
()and inserts it into the bufferwith
Gtk.TextBuffer:insert_child_anchor(). The new anchor isowned by the buffer; no reference count is returned tothe caller of
Gtk.TextBuffer:create_child_anchor()`.
- Returns: the created child anchor.
create_mark()
create_mark (self, mark_name:str=None, where:Gtk.TextIter, left_gravity:bool) -> Gtk.TextMark
Creates a mark at position where
. If mark_name
is None
, the markis anonymous; otherwise, the mark can be retrieved by name usingGtk.TextBuffer:get_mark()
. If a mark has left gravity, and text isinserted at the mark’s current location, the mark will be moved tothe left of the newly-inserted text. If the mark has right gravity(left_gravity
= FALSE
), the mark will end up on the right ofnewly-inserted text. The standard left-to-right cursor is a markwith right gravity (when you type, the cursor stays on the rightside 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 “mark-set” signal as notification of the mark'sinitial placement.
- Returns:
the new
Gtk.TextMark
object.
move_mark()
move_mark (self, mark:Gtk.TextMark, where:Gtk.TextIter)
Moves mark
to the new location where
. Emits the “mark-set”signal as notification of the move.
move_mark_by_name()
move_mark_by_name (self, name:str, where:Gtk.TextIter)
Moves the mark named name
(which must exist) to location where
.See Gtk.TextBuffer:move_mark()
for details.
add_mark()
add_mark (self, mark:Gtk.TextMark, where:Gtk.TextIter)
Adds the mark at position where
. The mark must not be added toanother buffer, and if its name is not None
then there must notbe another mark in the buffer with the same name.
Emits the “mark-set” signal as notification of the mark'sinitial placement.
- Since: 2.12
delete_mark()
delete_mark (self, mark:Gtk.TextMark)
Deletes mark
, so that it’s no longer located anywhere in thebuffer. Removes the reference the buffer holds to the mark, so ifyou haven’t called g_object_ref()
on the mark, it will be freed. Evenif the mark isn’t freed, most operations on mark
becomeinvalid, until it gets added to a buffer again with Gtk.TextBuffer:add_mark()
. Use `Gtk.TextMark:get_deleted
()` to find out if a mark has been removed from its buffer.The “mark-deleted” signal will be emitted as notification afterthe mark is deleted.
delete_mark_by_name()
delete_mark_by_name (self, name:str)
Deletes the mark named name
; the mark must exist. SeeGtk.TextBuffer:delete_mark()
for details.
get_mark()
get_mark (self, name:str) -> Gtk.TextMark
Returns the mark named name
in buffer buffer
, or None
if no suchmark exists in the buffer.
- Returns:
a
Gtk.TextMark
, orNone
.
get_insert()
get_insert (self) -> Gtk.TextMark
Returns the mark that represents the cursor (insertion point).Equivalent to calling Gtk.TextBuffer:get_mark()
to get the marknamed “insert”, but very slightly more efficient, and involves lesstyping.
- Returns: insertion point mark.
get_selection_bound()
get_selection_bound (self) -> Gtk.TextMark
Returns the mark that represents the selection bound. Equivalentto calling Gtk.TextBuffer:get_mark()
to get the mark named“selection_bound”, but very slightly more efficient, and involvesless 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.Gtk.TextBuffer:get_selection_bounds()
is another convenient functionfor handling the selection, if you just want to know whether there’s aselection and what its bounds are.
- Returns: selection bound mark.
get_has_selection()
get_has_selection (self) -> bool
Indicates whether the buffer has some text currently selected.
Returns:
True
if the there is text selectedSince: 2.10
place_cursor()
place_cursor (self, where:Gtk.TextIter)
This function moves the “insert” and “selection_bound” markssimultaneously. If you move them to the same place in two stepswith Gtk.TextBuffer:move_mark()
, you will temporarily select aregion in between their old and new locations, which can be prettyinefficient since the temporarily-selected region will force stuffto be recalculated. This function moves them as a unit, which canbe optimized.
select_range()
select_range (self, ins:Gtk.TextIter, bound:Gtk.TextIter)
This function moves the “insert” and “selection_bound” markssimultaneously. If you move them in two stepswith Gtk.TextBuffer:move_mark()
, you will temporarily select aregion in between their old and new locations, which can be prettyinefficient since the temporarily-selected region will force stuffto be recalculated. This function moves them as a unit, which canbe optimized.
- Since: 2.4
apply_tag()
apply_tag (self, tag:Gtk.TextTag, start:Gtk.TextIter, end:Gtk.TextIter)
Emits the “apply-tag” signal on buffer
. The defaulthandler for the signal applies tag
to the given range.start
and end
do not have to be in order.
remove_tag()
remove_tag (self, tag:Gtk.TextTag, start:Gtk.TextIter, end:Gtk.TextIter)
Emits the “remove-tag” signal. The default handler for the signalremoves all occurrences of tag
from the given range. start
andend
don’t have to be in order.
apply_tag_by_name()
apply_tag_by_name (self, name:str, start:Gtk.TextIter, end:Gtk.TextIter)
Calls `Gtk.TextTagTable:lookup
()on the buffer’s tag table toget a
Gtk.TextTag, then calls
Gtk.TextBuffer:apply_tag()`.
remove_tag_by_name()
remove_tag_by_name (self, name:str, start:Gtk.TextIter, end:Gtk.TextIter)
Calls `Gtk.TextTagTable:lookup
()on the buffer’s tag table toget a
Gtk.TextTag, then calls
Gtk.TextBuffer:remove_tag()`.
remove_all_tags()
remove_all_tags (self, start:Gtk.TextIter, end:Gtk.TextIter)
Removes all tags in the range between start
and end
. Be carefulwith this function; it could remove tags added in code unrelated tothe code you’re currently writing. That is, using this function isprobably a bad idea if you have two or more unrelated code sectionsthat add tags.
get_iter_at_line_offset()
get_iter_at_line_offset (self, line_number:int, char_offset:int) -> iter:Gtk.TextIter
Obtains an iterator pointing to char_offset
within the givenline. The char_offset
must exist, offsets off the end of the lineare not allowed. Note characters, not bytes;UTF-8 may encode one character as multiple bytes.
get_iter_at_offset()
get_iter_at_offset (self, char_offset:int) -> iter:Gtk.TextIter
Initializes iter
to a position char_offset
chars from the startof the entire buffer. If char_offset
is -1 or greater than the numberof characters in the buffer, iter
is initialized to the end iterator,the iterator one past the last valid character in the buffer.
get_iter_at_line()
get_iter_at_line (self, line_number:int) -> iter:Gtk.TextIter
Initializes iter
to the start of the given line. If line_number
is greaterthan the number of lines in the buffer
, the end iterator is returned.
get_iter_at_line_index()
get_iter_at_line_index (self, line_number:int, byte_index:int) -> 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, and must not bebeyond the end of the line. Note bytes, notcharacters; UTF-8 may encode one character as multiple bytes.
get_iter_at_mark()
get_iter_at_mark (self, mark:Gtk.TextMark) -> iter:Gtk.TextIter
Initializes iter
with the current position of mark
.
get_iter_at_child_anchor()
get_iter_at_child_anchor (self, anchor:Gtk.TextChildAnchor) -> iter:Gtk.TextIter
Obtains the location of anchor
within buffer
.
get_start_iter()
get_start_iter (self) -> iter:Gtk.TextIter
Initialized iter
with the first position in the text buffer. Thisis the same as using Gtk.TextBuffer:get_iter_at_offset()
to getthe iter at character offset 0.
get_end_iter()
get_end_iter (self) -> iter:Gtk.TextIter
Initializes iter
with the “end iterator,” one past the last validcharacter 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 inthe buffer (call
Gtk.TextBuffer:get_start_iter()` to getcharacter position 0) to the end iterator.
get_bounds()
get_bounds (self) -> start:Gtk.TextIter, end:Gtk.TextIter
Retrieves the first and last iterators in the buffer, i.e. theentire buffer lies within the range [start
,end
).
get_modified()
get_modified (self) -> bool
Indicates whether the buffer has been modified since the last callto Gtk.TextBuffer:set_modified()
set the modification flag toFALSE
. Used for example to enable a “save” function in a texteditor.
- Returns:
True
if the buffer has been modified
set_modified()
set_modified (self, setting:bool)
Used to keep track of whether the buffer has been modified since thelast time it was saved. Whenever the buffer is saved to disk, callGtk.TextBuffer:set_modified (buffer
, FALSE). When the buffer is modified,it will automatically toggled on the modified bit again. When the modifiedbit flips, the buffer emits the “modified-changed” signal.
delete_selection()
delete_selection (self, 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 True
,the editability of the selection will be considered (users can’t deleteuneditable text).
- Returns: whether there was a non-empty selection to delete
paste_clipboard()
paste_clipboard (self, clipboard:Gtk.Clipboard, override_location:Gtk.TextIter=None, default_editable:bool)
Pastes the contents of a clipboard. If override_location
is None
, thepasted text will be inserted at the cursor position, or the buffer selectionwill be replaced if the selection is non-empty.
Note: pasting is asynchronous, that is, we’ll ask for the paste data andreturn, and at some point later after the main loop runs, the paste data willbe inserted.
copy_clipboard()
copy_clipboard (self, clipboard:Gtk.Clipboard)
Copies the currently-selected text to a clipboard.
cut_clipboard()
cut_clipboard (self, clipboard:Gtk.Clipboard, default_editable:bool)
Copies the currently-selected text to a clipboard, then deletessaid text if it’s editable.
begin_user_action()
begin_user_action (self)
Called to indicate that the buffer operations between here and acall to Gtk.TextBuffer:end_user_action()
are part of a singleuser-visible operation. The operations betweenGtk.TextBuffer:begin_user_action()
andGtk.TextBuffer:end_user_action()
can then be grouped when creatingan undo stack. Gtk.TextBuffer
maintains a count of calls toGtk.TextBuffer:begin_user_action()
that have not been closed witha call to 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 asGtk.TextBuffer:insert_interactive()
, automatically call begin/enduser action around the buffer operations they perform, so there'sno need to add extra calls if you user action consists solely of asingle call to one of those functions.
end_user_action()
end_user_action (self)
Should be paired with a call to Gtk.TextBuffer:begin_user_action()
.See that function for a full explanation.
add_selection_clipboard()
add_selection_clipboard (self, clipboard:Gtk.Clipboard)
Adds clipboard
to the list of clipboards in which the selection contents of buffer
are available. In most cases, clipboard
will be the Gtk.Clipboard
of type GDK_SELECTION_PRIMARY
for a view of buffer
.
remove_selection_clipboard()
remove_selection_clipboard (self, clipboard:Gtk.Clipboard)
Removes a Gtk.Clipboard
added with Gtk.TextBuffer:add_selection_clipboard()
.
deserialize()
deserialize (self, content_buffer:Gtk.TextBuffer, format:Gdk.Atom, iter:Gtk.TextIter, data:list) -> bool
This function deserializes rich text in format format
and insertsit at iter
.
formats
to be used must be registered usingGtk.TextBuffer:register_deserialize_format()
orGtk.TextBuffer:register_deserialize_tagset()
beforehand.
Returns:
True
on success,FALSE
otherwise.Since: 2.10
deserialize_get_can_create_tags()
deserialize_get_can_create_tags (self, format:Gdk.Atom) -> bool
This functions returns the value set withGtk.TextBuffer:deserialize_set_can_create_tags()
Returns: whether deserializing this format may create tags
Since: 2.10
deserialize_set_can_create_tags()
deserialize_set_can_create_tags (self, format:Gdk.Atom, can_create_tags:bool)
Use this function to allow a rich text deserialization function tocreate new tags in the receiving buffer. Note that using thisfunction is almost always a bad idea, because the rich textfunctions you register should know how to map the rich text formatthey handler to your text buffers set of tags.
The ability of creating new (arbitrary!) tags in the receiving bufferis meant for special rich text formats like the internal one thatis registered using Gtk.TextBuffer:register_deserialize_tagset()
,because that format is essentially a dump of the internal structureof the source buffer, including its tag names.
You should allow creation of tags only if you know what you aredoing, e.g. if you defined a tagset name for your applicationsuite’s text buffers and you know that it’s fine to receive newtags from these buffers, because you know that your application canhandle the newly created tags.
- Since: 2.10
get_copy_target_list()
get_copy_target_list (self) -> Gtk.TargetList
This function returns the list of targets this text buffer canprovide for copying and as DND source. The targets in the list areadded with info
values from the Gtk.TextBufferTargetInfo
enum,using Gtk.TargetList:add_rich_text_targets`()` and
Gtk.TargetList:add_text_targets()
.
Returns: the
Gtk.TargetList
.Since: 2.10
get_deserialize_formats()
get_deserialize_formats (self) -> list, n_formats:int
This function returns the rich text deserialize formats registeredwith buffer
using Gtk.TextBuffer:register_deserialize_format()
orGtk.TextBuffer:register_deserialize_tagset()
Returns: an array ofGdkAtoms representing the registered formats.
Since: 2.10
get_paste_target_list()
get_paste_target_list (self) -> Gtk.TargetList
This function returns the list of targets this text buffer supportsfor pasting and as DND destination. The targets in the list areadded with info
values from the Gtk.TextBufferTargetInfo
enum,using Gtk.TargetList:add_rich_text_targets`()` and
Gtk.TargetList:add_text_targets()
.
Returns: the
Gtk.TargetList
.Since: 2.10
get_serialize_formats()
get_serialize_formats (self) -> list, n_formats:int
This function returns the rich text serialize formats registeredwith buffer
using Gtk.TextBuffer:register_serialize_format()
orGtk.TextBuffer:register_serialize_tagset()
Returns: an array ofGdkAtoms representing the registered formats.
Since: 2.10
register_deserialize_format()
register_deserialize_format (self, mime_type:str, function:Gtk.TextBufferDeserializeFunc, user_data=None) -> Gdk.Atom
This function registers a rich text deserialization function
along withits mime_type
with the passed buffer
.
Returns: the GdkAtom that corresponds to thenewly registered format’s mime-type.
Since: 2.10
register_deserialize_tagset()
register_deserialize_tagset (self, tagset_name:str=None) -> Gdk.Atom
This function registers GTK+’s internal rich text serializationformat with the passed buffer
. SeeGtk.TextBuffer:register_serialize_tagset()
for details.
Returns: the GdkAtom that corresponds to thenewly registered format’s mime-type.
Since: 2.10
register_serialize_format()
register_serialize_format (self, mime_type:str, function:Gtk.TextBufferSerializeFunc, user_data=None) -> Gdk.Atom
This function registers a rich text serialization function
along withits mime_type
with the passed buffer
.
Returns: the GdkAtom that corresponds to thenewly registered format’s mime-type.
Since: 2.10
register_serialize_tagset()
register_serialize_tagset (self, tagset_name:str=None) -> Gdk.Atom
This function registers GTK+’s internal rich text serializationformat with the passed buffer
. The internal format does not complyto any standard rich text format and only works between Gtk.TextBufferinstances
. It is capable of serializing all of a text buffer’s tagsand embedded pixbufs.
This function is just a wrapper aroundGtk.TextBuffer:register_serialize_format()
. The mime type usedfor registering is “application/x-gtk-text-buffer-rich-text”, or“application/x-gtk-text-buffer-rich-text;format=tagset_name
” if atagset_name
was passed.
The tagset_name
can be used to restrict the transfer of rich textto buffers with compatible sets of tags, in order to avoid unknowntags from being pasted. It is probably the common case to pass anidentifier != None
here, since the None
tagset requires thereceiving buffer to deal with with pasting of arbitrary tags.
Returns: the GdkAtom that corresponds to thenewly registered format’s mime-type.
Since: 2.10
serialize()
serialize (self, content_buffer:Gtk.TextBuffer, format:Gdk.Atom, start:Gtk.TextIter, end:Gtk.TextIter) -> list, length:int
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 usingGtk.TextBuffer:register_serialize_format()
orGtk.TextBuffer:register_serialize_tagset()
beforehand.
Returns: the serializeddata, encoded as
format
.Since: 2.10
unregister_deserialize_format()
unregister_deserialize_format (self, format:Gdk.Atom)
This function unregisters a rich text format that was previouslyregistered using Gtk.TextBuffer:register_deserialize_format()
orGtk.TextBuffer:register_deserialize_tagset()
.
- Since: 2.10
unregister_serialize_format()
unregister_serialize_format (self, format:Gdk.Atom)
This function unregisters a rich text format that was previouslyregistered using Gtk.TextBuffer:register_serialize_format()
orGtk.TextBuffer:register_serialize_tagset()
- Since: 2.10