gtk.TextBuffer — stores attributed text for display in a gtk.TextView
class gtk.TextBuffer( |
|
def callback( | |
def callback( | |
"changed" | def callback( |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
def callback( | |
"mark-set" | def callback( |
def callback( | |
def callback( | |
def callback( |
A gtk.TextBuffer
is the core component of the PyGTK text editing system. A gtk.TextBuffer
contains the text, pixbufs and child widget anchors that are displayed in
one or more gtk.TextView
widgets. A gtk.TextBuffer
has an associated gtk.TextTagTable
that contains the gtk.TextTag
objects
that can be used to set attributes on the text in the textbuffer.
A gtk.TextBuffer
can be automatically created when creating a gtk.TextView
or it
can be created with the gtk.TextBuffer() constructor and
associated with a gtk.TextView
using
the set_buffer
()
method or the gtk.TextView()
constructor.
gtk.TextBuffer(table
=None)
| a tag table, or None to create a new one |
Returns : | a new text buffer object |
Creates a new gtk.TextBuffer
object.
def get_line_count()
Returns : | the number of lines in the buffer |
The get_line_count
() method returns the
number of lines in the buffer. This value is cached, so the function is very
fast.
def get_char_count()
Returns : | the number of characters in the buffer |
The get_char_count
() method returns 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.
def get_tag_table()
Returns : | the buffer's tag table |
The get_tag_table
() method returns the
gtk.TextTagTable
object associated with the textbuffer.
def set_text(text
)
| UTF-8 text to insert |
The set_text
() method replaces the
current contents of the textbuffer with the contents of
text
. text
must be valid
UTF-8.
def insert(iter
, text
)
| a gtk.TextIter
specifying a position in the buffer |
| UTF-8 format text to insert |
The insert
() method inserts the
contents of text
into the textbuffer at the position
specified by iter
. The "insert_text" signal is
emitted and the text 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.
def insert_at_cursor(text
)
| some text in UTF-8 format |
The insert_at_cursor
() method is a
convenience method that calls the insert
()
method, using the current cursor position as the insertion point.
def insert_interactive(iter
, text
, default_editable
)
| a gtk.TextIter
specifying a position in
buffer |
| some UTF-8 text |
| default editability of buffer |
Returns : | True if the text was
actually inserted |
The insert_interactive
() method is
similar to the insert
()
method, except the insertion of text
at
iter
will not occur if iter
is
at a non-editable location in the buffer. A location is non-editable if a
gtk.TextTag
applied at that location has its "editable" attribute set to
False
or the gtk.TextView
used
by the user is set non-editable. Usually you want to prevent insertions at
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 the gtk.TextView.get_editable
()
method is appropriate here.
def insert_interactive_at_cursor(text
, default_editable
)
| text in UTF-8 format |
| default editability of buffer |
Returns : | True if the text was
actually inserted |
The insert_interactive_at_cursor
()
method calls the insert_interactive
()
method to insert text
at the cursor (insert)
position. default_editable
indicates the editability
of text that doesn't have a tag affecting editability applied to it.
Typically the result of the gtk.TextView.get_editable
()
method is appropriate here.
def insert_range(iter
, start
, end
)
| a gtk.TextIter
specifying a position in the
textbuffer |
| a gtk.TextIter
specifying a position in a (possibly different) gtk.TextBuffer |
| a gtk.TextIter
specifying another position in the same buffer as
start |
The insert_range
() method copies text,
tags, and pixbufs (but not child anchors) between
start
and end
(the order of
start
and end
doesn't matter)
form a gtk.TextBuffer
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 buffer
, the two buffers must
share the same tag table. This method is implemented via emissions of the
"insert_text" and "apply_tag" signals.
def insert_range_interactive(iter
, start
, end
, default_editable
)
| a gtk.TextIter
specifying a position in the
textbuffer |
| a gtk.TextIter
specifying a position in a (possibly different) gtk.TextBuffer |
| a gtk.TextIter
specifying another position in the same buffer as
start |
| default editability of the buffer |
Returns : | True if an insertion was
possible at iter |
The insert_range_interactive
() method
is similar to the insert_range
()
method, except the insertion of text
at
iter
will not occur if the insertion position is
non-editable. A location is non-editable if a gtk.TextTag
applied
at that location has its "editable" attribute set to
False
or the gtk.TextView
used
by the user is set non-editable. The default_editable
parameter indicates whether the text is editable at
iter
if no tags enclosing iter
affect editability. Typically the result of the gtk.TextView.get_editable
()
method is appropriate here.
def insert_with_tags(iter
, text
, ...
)
| a gtk.TextIter
specifying a position in buffer |
| UTF-8 text |
| one or more optional gtk.TextTag objects
to apply to text |
The insert_with_tags
() method inserts
the specified text
into the textbuffer at the
location specified by iter
, applying any optional
tags following the first two parameters to the newly-inserted text. This
method is a convenience method that is equivalent to calling the insert
()
method, then the apply_tag
()
method on the inserted text.
def insert_with_tags_by_name(iter
, text
, ...
)
| a gtk.TextIter
specifying a position in buffer |
| UTF-8 text |
| one or more optional gtk.TextTag names
to apply to text |
The insert_with_tags_by_name
() method
is similar to the insert_with_tags
()
method, but uses tag names instead of tag objects.
def delete(start
, end
)
| a gtk.TextIter
specifying a position in the textbuffer |
| a gtk.TextIter
specifying another position in the textbuffer |
The delete
() method deletes the text
between start
and end
. The
order of start
and end
is not
actually relevant as the delete
() method will
reorder them. This method emits the "delete_range" signal, and the default
handler of that signal deletes the text. Because the textbuffer is modified,
all outstanding iterators become invalid after calling this function;
however, start
and end
will be
re-initialized to point to the location where text was deleted.
def delete_interactive(start_iter
, end_iter
, default_editable
)
| a gtk.TextIter
specifying the start of the text to delete |
| a gtk.TextIter
specifying the end of the text to delete |
| whether the buffer is editable by default |
Returns : | True if some text was
actually deleted |
The delete_interactive
() method deletes
all editable text in the given range. This method calls
the delete
()
method 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. A range of text
is non-editable if
a gtk.TextTag
applied to that range has its "editable" attribute set to
False
or the gtk.TextView
used
by the user is set non-editable. The default_editable
parameter indicates whether text
is editable if no
tags enclosing any part of text
affect editability.
Typically the result of the gtk.TextView.get_editable
()
method is appropriate here.
def get_text(start
, end
, include_hidden_chars
=True)
| a gtk.TextIter
specifying the start of a range |
| a gtk.TextIter
specifying the end of a range |
| if True include invisible
text |
Returns : | the text in the range |
The get_text
() method returns the text
in the specified range
[start
,end
). Undisplayed text
(text marked with tags that set the invisibility attribute) are excluded if
include_hidden_chars
is False
.
get_text
() does not return 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 this behavior with the get_slice
()
method.
def get_slice(start
, end
, include_hidden_chars
)
| a gtk.TextIter
specifying the start of a range |
| a gtk.TextIter
specifying the end of a range |
| if True include invisible
text |
Returns : | the contents of the range including text and indicators for pixbufs and child anchors |
The get_slice
() method returns the text
in the range [start
,end
).
Undisplayed text (text marked with tags that set the invisibility attribute)
is excluded if include_hidden_chars
is
False
. The returned string includes a 0xFFFC character
whenever the textbuffer contains embedded images or child anchors, so byte
and character indexes into the returned string do
correspond to byte and character indexes into the buffer. Contrast this
behavior with the get_text
()
method. 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.
def insert_pixbuf(iter
, pixbuf
)
| a gtk.TextIter
specifying the location to insert the pixbuf |
| a gtk.gdk.Pixbuf |
The insert_pixbuf
() method inserts an
image specified by pixbuf
into the text buffer at the
location specified by 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 the get_slice
()
and get_text
()
methods.
def insert_child_anchor(iter
, anchor
)
| a gtk.TextIter
specifying the location to insert the anchor |
| a gtk.TextChildAnchor |
The insert_child_anchor
() method
inserts a child widget anchor specified by anchor
into the textbuffer at the location specified by
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 the get_slice
()
and get_text
()
methods. The create_child_anchor
()
is a more convenient alternative to this function.
def create_child_anchor(iter
)
| a gtk.TextIter
specifying a location in the buffer |
Returns : | the new child anchor |
The create_child_anchor
() method is a
convenience function that creates a child anchor with the gtk.TextChildAnchor()
constructor and inserts it into the textbuffer at the location specified by
iter
with the insert_child_anchor
()
method.
def create_mark(mark_name
, where
, left_gravity
)
| the name for the new mark, or
None |
| a gtk.TextIter
specifying the location to place the mark |
| if True the mark has left
gravity |
Returns : | the new gtk.TextMark
object |
The create_mark
() method creates a mark
with the name specified by mark_name
at the position
specified by where
and left gravity specified by
left_gravity
. If mark_name
is
None
, the mark is anonymous; otherwise, the mark can be
retrieved by name using the get_mark
()
method. 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). Marks are owned by the buffer and go away when the buffer
does. This method emits the "mark_set" signal as notification of the mark's
initial placement.
def move_mark(mark
, where
)
| a gtk.TextMark |
| a gtk.TextIter
specifying a new location for mark |
The move_mark
() method moves the gtk.TextMark
specified by mark
to the new location specified by
where
.This method emits the "mark_set" signal as
notification of the move.
def delete_mark(mark
)
| a gtk.TextMark in
the textbuffer |
The delete_mark
() method deletes the
gtk.TextMark
specified by mark
, so that it's no longer located
anywhere in the textbuffer. Most operations on mark
become invalid and there is no way to undelete a mark. The get_deleted
()
method will return True
after this method has been called
on a mark to indicate that a mark no longer belongs to a textbuffer. The
"mark_deleted" signal will be emitted as notification after the mark is
deleted.
def get_mark(name
)
| a mark name |
Returns : | a gtk.TextMark , or
None |
The get_mark() method returns the mark named
name
in the textbuffer, or None
if
no such mark exists in the buffer.
def move_mark_by_name(name
, where
)
| the name of a mark |
| a gtk.TextIter
specifying the new location for mark |
The move_mark_by_name
() method moves
the mark named name
(which must exist) to the
textbuffer location specified by where
. See the move_mark
()
method for details.
def delete_mark_by_name(name
)
| the name of a mark in
buffer |
The delete_mark_by_name
() method
deletes the mark (which must exist) named name
. See
the delete_mark
()
for details.
def get_insert()
Returns : | the insertion point mark |
The get_insert
() method returns the
mark that represents the cursor (insertion point). Equivalent to calling the
get_mark
()
method to get the mark named "insert", but very slightly more efficient, and
involving less typing.
def get_selection_bound()
Returns : | the selection bound mark |
The get_selection_bound
() method
returns the mark that represents the selection bound. Equivalent to calling
the get_mark
()
method to get the mark named "selection_bound", but very slightly more
efficient, and involving less typing. The currently-selected text in a
textbuffer 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. The get_selection_bounds
()
method is a convenience method for handling the selection, if you just
want to know whether there's a selection and what its bounds are.
def place_cursor(where
)
| a gtk.TextIter
specifying where to put the cursor |
The place_cursor
() method moves the
"insert" and "selection_bound" marks simultaneously to the location
specified by where
. If you move them to the same
place in two steps with the move_mark
()
method, you will temporarily select a region in between their old and new
locations, which is inefficient. This method moves them as a unit, which can
be optimized.
def select_range(ins
, bound
)
| a gtk.TextIter
specifying where to put the "insert" mark |
| a gtk.TextIter
specifying where to put the "selection_bound" mark |
This method is available in PyGTK 2.4 and above.
The select_range
() method moves the
"insert" and "selection_bound" marks simultaneously to the locations
specified by ins
and bound
respectively. If you move them to the same place in two steps with the
move_mark
()
method, you will temporarily select a region in between their old and new
locations, which is inefficient. This method moves them as a unit, which can
be optimized.
def apply_tag(tag
, start
, end
)
| a gtk.TextTag |
| a gtk.TextIter
specifying the start of the range |
| a gtk.TextIter
specifying the end of the range |
The apply_tag
() method emits the
"apply-tag" signal that causes the gtk.TextTag
specified by tag
to be applied to the range of text
between start
and end
by the
default signal handler. start
and
end
do not have to be in order.
def remove_tag(tag
, start
, end
)
| a gtk.TextTag |
| a gtk.TextIter
specifying the start of the range |
| a gtk.TextIter
specifying the end of the range |
The delete_tag
() method emits the
"remove_tag" signal that causes the default handler for the signal to remove
all occurrences of the gtk.TextTag
specified by tag
from the text in the range between
start
and end
.
start
and end
don't have to be
in order.
def apply_tag_by_name(name
, start
, end
)
| the name of a gtk.TextTag |
| a gtk.TextIter
specifying the start of the range |
| a gtk.TextIter
specifying the end of the range |
The apply_tag_by_name
() method calls
the gtk.TextTagTable.lookup
()
method on the textbuffer's tag table to find the gtk.TextTag
with
the specified name
, then calls the apply_tag
()
method to apply that tag to the text in the range between
start
and end
.
start
and end
don't have to be
in order.
def remove_tag_by_name(name
, start
, end
)
| the name of a gtk.TextTag |
| a gtk.TextIter
specifying the start of the range |
| a gtk.TextIter
specifying the end of the range |
The delete_tag_by_name
() method calls
the gtk.TextTagTable.lookup
()
method on the textbuffer's tag table to find the gtk.TextTag
, then
calls the remove_tag
()
method to remove that that tag from the text in the range between
start
and end
.
start
and end
don't have to be
in order.
def remove_all_tags(start
, end
)
| a gtk.TextIter
specifying the start of the range |
| a gtk.TextIter
specifying the end of the range |
The remove_all_tags
() method removes
all tags in the text 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. start
and
end
don't have to be in order.
def create_tag(tag_name
=None, ...
)
| the name of the new tag, or
None if the tag is anonymous |
| one or more property_name= value pairs |
Returns : | a new tag |
The create_tag
() method creates a tag
with the name specified by tag_name
and adds it to
the tag table for the textbuffer. If one or more
property_name=value
pairs are available they are used to
set the properties of the tag. Note the property_name
must be specified using underscores instead of dashes e.g. use
pixels_above_lines=10 instead of pixels-above-lines=10. This method is
equivalent to calling the gtk.TextTag() constructor and then
adding the tag to the buffer's tag table with the gtk.TextTagTable.add
()
method. If tag_name
is None
, the
tag is anonymous. If tag_name
is
non-None
, a tag called tag_name
must not already exist in the tag table for this buffer.
def get_iter_at_line_offset(line_number
, char_offset
)
| the line number counting from 0 |
| the char offset from start of line |
Returns : | a gtk.TextIter |
The get_iter_at_line_offset
() returns
an iterator pointing to the position specified by
char_offset
within the line specified by
line_number
. The char_offset
must exist, offsets off the end of the line are not allowed. Note specify
characters, not bytes; UTF-8 may encode one character
as multiple bytes.
def get_iter_at_line_index(line_number
, byte_index
)
| the line number counting from 0 |
| the byte index from start of line |
Returns : | a gtk.TextIter |
The get_iter_at_line_index
() method
returns an iterator pointing to the position specified by
byte_index
within the line specified by
line_number
. byte_index
must
be the start of a UTF-8 character, and must not be beyond the end of the
line. Note specify bytes, not characters; UTF-8 may
encode one character as multiple bytes.
def get_iter_at_offset(char_offset
)
| the char offset from start of buffer, counting from 0 |
Returns : | a gtk.TextIter |
The get_iter_at_offset
() method returns
an iterator pointing to the location specified by
char_offset
characters from the start of the entire
buffer.
def get_iter_at_line(line_number
)
| line number counting from 0 |
Returns : | a gtk.TextIter |
The get_iter_at_line
() method returns
an iterator pointing to the start of the line specified by
line_number
.
def get_start_iter()
Returns : | a gtk.TextIter |
The get_start_iter
() method returns an
iterator pointing at the location of the first position in the text buffer.
This is the same as using the get_iter_at_offset
()
with an argument of 0.
def get_end_iter()
Returns : | a gtk.TextIter |
The get_end_iter
() method returns an
iterator pointing at the "end iterator," one past the last valid character
in the text buffer. If passed to the gtk.TextIter.get_char
()
method, the end iterator has a character value of 0. The entire buffer lies
in the range from the first position in the buffer (call the get_start_iter
()
method to get character position 0) to the end iterator.
def get_bounds()
Returns : | a tuple containing gtk.TextIter objects
that point at the first and last positions in the buffer |
The get_bounds
() method returns a tuple
containing the first and last iterators in the buffer, i.e. the entire
buffer lies within the range.
def get_iter_at_mark(mark
)
| a gtk.TextMark in
the textbuffer |
Returns : | a gtk.TextIter |
The get_iter_at_mark
() method returns
an iterator that points at the current position of
mark
.
def get_iter_at_child_anchor(iter
, anchor
)
| a child anchor that appears in the textbuffer |
Returns : | a gtk.TextIter |
The get_iter_at_child_anchor
() method
returns an iterator that points at the location of
anchor
within the textbuffer.
def get_modified()
Returns : | True if the buffer has been
modified |
The get_modified
() method returns
True
if the buffer has been modified since the last call
to the set_modified
()
method set the modification flag to False
. Used for
example to enable a "save" function in a text editor.
def set_modified(setting
)
| the modification flag setting |
The set_modified
() method sets the
modification flag of the textbuffer to the value specified by
setting
. The modification flag is 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 this method with a
setting
of False
. When the buffer
is modified, it will automatically set the modification flag to
True
and emit a "modified_changed" signal.
def add_selection_clipboard(clipboard
)
| a gtk.Clipboard |
This method is available in PyGTK 2.2 and above.
The add_selection_clipboard
() method
adds the gtk.Clipboard
specified by clipboard
to the list of clipboards in
which the selection contents of the buffer are available. In most cases,
clipboard
will be the
gtk.gdk.SELECTION_PRIMARY
clipboard
def remove_selection_clipboard(clipboard
)
| a gtk.Clipboard
added to the buffer by the add_selection_clipboard()
method. |
This method is available in PyGTK 2.2 and above.
The remove_selection_clipboard
() method
removes the gtk.Clipboard
added with the add_selection_clipboard
()
method.
def cut_clipboard(clipboard
, default_editable
)
| the gtk.Clipboard
object to cut to. |
| the default editability of the buffer |
This method is available in PyGTK 2.2 and above.
The cut_clipboard
() method copies the
currently-selected text to the gtk.Clipboard
specified by clipboard
, then deletes said text if
it's editable as specified by
default_editable
. Typically the result of the gtk.TextView.get_editable
()
method is appropriate here.
def copy_clipboard(clipboard
)
| the gtk.Clipboard
object to copy to. |
This method is available in PyGTK 2.2 and above.
The copy_clipboard
() method copies the
currently-selected text to the gtk.ClipBoard
specified by clipboard
.
def paste_clipboard(clipboard
, override_location
, default_editable
)
| the gtk.Clipboard
to paste from |
| the gtk.TextIter
specifying the location to insert pasted text, or
None for at the cursor |
| the default editability of the buffer |
This method is available in PyGTK 2.2 and above.
The paste_clipboard
() method pastes the
contents of the gtk.ClipBoard
specified by clipboard
at the insertion point, or at
the location specified by override_location
(if not
None
). (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.)
def get_selection_bounds()
Returns : | a tuple containing gtk.TextIter objects pointing to the selection start and end or an empty tuple if there is no
selection |
The get_selection_bounds
() method
returns a tuple containing iterators that point at the start and end of the
selection, if any. If there is no selection an empty tuple is
returned.
def delete_selection(interactive
, default_editable
)
| if True the deletion is
caused by user interaction |
| if True the buffer is
editable by default |
Returns : | True if there was a
non-empty selection to delete |
The delete_selection
() method deletes
the text in the range between the "insert" and "selection_bound" marks, i.e.
the currently-selected text. If interactive
is
True
, the editability of the selection will be considered
(users can't delete uneditable text) and default_editable is used to
determine the default editability of the textbuffer usually as a result of a
call to the gtk.TextView.get_editable
()
method.
def begin_user_action()
The begin_user_action
() method is
called to indicate that the textbuffer operations until a call to the end_user_action
()
method are part of a single user-visible operation. The operations between
the begin_user_action
() and end_user_action
()
methods can then be grouped when creating an undo stack. gtk.TextBuffer
maintains a count of calls to the
begin_user_action
() method that have not been
closed with a call to the end_user_action
()
method, and emits the "begin_user_action" and "end_user_action" signals only
for the outermost pair of calls. This allows you to chain user
actions.
The "interactive" textbuffer mutation methods, such as the insert_interactive
()
method, automatically call the begin and end user action methods around the
textbuffer 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
methods.
def end_user_action()
The end_user_action
() method should be
paired with a call to the begin_user_action
()
method.
def backspace(iter
, interactive
, default_editable
)
| a gtk.TextIter |
| if True the deletion is
caused by user interaction |
| if True the buffer is
editable by default |
Returns : | True if the buffer was
modified |
This method is available in PyGTK 2.6 and above.
The backspace
() method 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, iter
will be re-initialized to point to the location where text was
deleted.
def get_has_selection()
Returns : | True if there is text
selected |
This method is available in PyGTK 2.10 and above.
Indicates whether the buffer has some text currently selected.
def get_copy_target_list()
Returns : | a list of the targets each represented as a 3-tuple containing the target name, a combination of the GTK Target Flags Constants and an application assigned integer |
This method is available in PyGTK 2.10 and above.
This method 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 TextBuffer Target Info Constants, using
the gtk.target_list_add_rich_text_targets
()
and gtk.target_list_add_text_targets
()
functions.
def get_paste_target_list()
Returns : | a list of the targets each represented as a 3-tuple containing the target name, a combination of the GTK Target Flags Constants and an application assigned integer |
This method is available in PyGTK 2.10 and above.
This method 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 TextBuffer Target Info Constants, using
the gtk.target_list_add_rich_text_targets
()
and gtk.target_list_add_text_targets
()
functions.
def register_serialize_format(mime_type
, function
, user_data
)
| the format's mime-type |
| the serialize function to register |
| function 's user_data |
Returns : | the newly registered format's mime-type. |
This method is available in PyGTK 2.10 and above.
This method registers a rich text serialization
function
along with its
mime_type
with the passed
buffer
.
The signature of function is:
def function(register_buf, content_buf, start, end, data):
where register_buf
is the textbuffer that
the format is registered with, content_buf
is
the textbuffer containing the text to be serialized,
start
and end
are
textiters bounding the text to be serialized and
data
is
user_data
. function
should return the serialized data.
def register_serialize_tagset(tagset_name
=NULL)
| an optional tagset name, or
None |
Returns : | the newly registered format's mime-type. |
This method is available in PyGTK 2.10 and above.
This method registers GTK+'s internal rich text serialization
format with this textbuffer. 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 method 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 a non-None
tagset here,
since the None
tagset requires the receiving buffer
to deal with with pasting of arbitrary tags.
def register_deserialize_format(mime_type
, function
, user_data
)
| the format's mime-type |
| the deserialize function to register |
| function 's user_data |
Returns : | the newly registered format's mime-type. |
This method is available in PyGTK 2.10 and above.
This method registers a rich text deserialization
function
along with its
mime_type
with the passed
buffer
.
The signature of function is:
def function(register_buf, content_buf, iter, data, create_tags, udata):
where register_buf
is the textbuffer that
the format is registered with, content_buf
is
the textbuffer that data will be deserialized into,
iter
is a textiter indicating the start of the
deserialized data in content_buf
, create_tags
is a boolean indicating if tags should be created during
deserializtion and udata
is
user_data
. function
should return True
if the data was successfully
deserialized.
def register_deserialize_tagset(tagset_name
=NULL)
| an optional tagset name, or
None |
Returns : | the newly registered format's mime-type. |
This method is available in PyGTK 2.10 and above.
This method registers GTK+'s internal rich text serialization
format with this buffer. See the gtk.TextBuffer.register_serialize_tagset()
method for details.
def unregister_serialize_format(format
)
| a target string representing a registered rich text format. |
This method is available in PyGTK 2.10 and above.
This method unregisters a rich text format that was previously
registered using the gtk.TextBuffer.register_serialize_format()
or gtk.TextBuffer.register_serialize_tagset()
methods.
def unregister_deserialize_format(format
)
| a target string representing a registered rich text format. |
This method is available in PyGTK 2.10 and above.
This method unregisters a rich text format that was previously
registered using the gtk.TextBuffer.register_deserialize_format()
or gtk.TextBuffer.register_deserialize_tagset()
methods.
def deserialize_set_can_create_tags(format
, can_create_tags
)
| a target string representing a registered rich text format |
| if True deserializing
format may create tags |
This method is available in PyGTK 2.10 and above.
Use this method to allow a rich text deserialization function to create new tags in the receiving buffer. Note that using this method is almost always a bad idea, because the rich text functions you register should know how to map the rich text format they handle 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.
def deserialize_get_can_create_tags(format
)
| a target string representing a registered rich text format |
Returns : | True if deserializing
format may create tags |
This method is available in PyGTK 2.10 and above.
This method returns the value set with the gtk.TextBuffer.deserialize_set_can_create_tags()
method.
def get_serialize_formats()
Returns : | a list of target strings representing the registered formats. |
This method is available in PyGTK 2.10 and above.
This method returns a list of the rich text serialize formats
registered using the gtk.TextBuffer.register_serialize_format()
or gtk.TextBuffer.register_serialize_tagset()
methods.
def get_deserialize_formats()
Returns : | a list of target strings representing the registered formats. |
This method is available in PyGTK 2.10 and above.
This method returns the rich text deserialize formats registered
using the gtk.TextBuffer.register_deserialize_format()
or gtk.TextBuffer.register_deserialize_tagset()
methods.
def serialize(content_buffer
, format
, start
, end
)
| the gtk.TextBuffer
to serialize |
| the rich text format to use for serializing |
| start of block of text to serialize |
| end of block of test to serialize |
Returns : | the serialized data, encoded as
format |
This method is available in PyGTK 2.10 and above.
This method serializes the portion of text between start
and end
in the rich text format represented by format
.
The formats to be used must be registered using the gtk.TextBuffer.register_serialize_format()
or gtk.TextBuffer.register_serialize_tagset()
methods beforehand.
def deserialize(content_buffer
, format
, iter
, data
)
| the gtk.TextBuffer
to deserialize into |
| the rich text format to use for deserializing |
| insertion point for the deserialized text |
| data to deserialize |
Returns : | True on success,
False otherwise. |
This method is available in PyGTK 2.10 and above.
This method deserializes rich text in format
format
and inserts it at iter
in
content_buffer
.
The formats to be used must be registered using the gtk.TextBuffer.register_deserialize_format()
or gtk.TextBuffer.register_deserialize_tagset()
methods beforehand.
def add_mark(mark
, where
)
| the gtk.TextMark
to add |
| the location to place mark. |
This method is available in PyGTK 2.12 and above.
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 "mark_set" signal as notification of the mark's initial placement.
def callback(textbuffer
, texttag
, start
, end
, user_param1
, ...
)
| the textbuffer that received the signal |
| the gtk.TextTag being
applied |
| a gtk.TextIter
pointing to the start of the range of text |
| a gtk.TextIter
pointing to the end of the range of text |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "apply-tag" signal is emitted when
texttag
is applied to the text in
textbuffer
in the range specified by
start
and end
.
def callback(textbuffer
, user_param1
, ...
)
| the textbuffer that received the signal |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "begin-user-action" signal is emitted on the first call to
the begin_user_action
()
method.
def callback(textbuffer
, user_param1
, ...
)
| the textbuffer that received the signal |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "changed" signal is emitted when text is inserted in
textbuffer
.
def callback(textbuffer
, start
, end
, user_param1
, ...
)
| the textbuffer that received the signal |
| a gtk.TextIter
pointing to the start of the range of text |
| a gtk.TextIter
pointing to the end of the range of text |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "delete-range" signal is emitted when the text in the range
specified by start
and end
is
to be deleted.
def callback(textbuffer
, user_param1
, ...
)
| the textbuffer that received the signal |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "end-user-action" signal is emitted when the call to the
end_user_action
()
method reduces the user action count to zero i.e. undoes the first call to
the begin_user_action
()
method.
def callback(textbuffer
, iter
, anchor
, user_param1
, ...
)
| the textbuffer that received the signal |
| a gtk.TextIter |
| a gtk.TextChildAnchor |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "insert-child-anchor" signal is emitted when
anchor
is inserted into
textbuffer
at the location specified by
iter
.
def callback(textbuffer
, iter
, pixbuf
, user_param1
, ...
)
| the textbuffer that received the signal |
| a gtk.TextIter |
| a gtk.gdk.Pixbuf |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "insert-pixbuf" signal is emitted when
pixbuf
is inserted into
textbuffer
at the location specified by
iter
.
def callback(textbuffer
, iter
, text
, length
, user_param1
, ...
)
| the textbuffer that received the signal |
| a gtk.TextIter |
| the text inserted in
textbuffer |
| the length of the text inserted in
textbuffer |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "insert-text" signal is emitted when
text
of the size specified by
length
is inserted into
textbuffer
at the location specified by
iter
.
def callback(textbuffer
, textmark
, user_param1
, ...
)
| the textbuffer that received the signal |
| the gtk.TextMark
that is being deleted |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "mark-deleted" signal is emitted when
textmark
is being deleted from
textbuffer
.
def callback(textbuffer
, iter
, textmark
, user_param1
, ...
)
| the textbuffer that received the signal |
| a gtk.TextIter
pointing at the location where textmark will be
set. |
| the gtk.TextMark
that is being set |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "mark-set" signal is emitted when
textmark
is being set at the location specified by
iter
in textbuffer
.
def callback(textbuffer
, user_param1
, ...
)
| the textbuffer that received the signal |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "modified-changed" signal is emitted when the modification flag is changed.
def callback(textbuffer
, user_param1
, ...
)
| the textbuffer that received the signal |
| the first user parameter (if any) specified with the
connect () |
| additional user parameters (if any) |
This signal is available in GTK+ 2.16 and above.
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.
def callback(textbuffer
, texttag
, start
, end
, user_param1
, ...
)
| the textbuffer that received the signal |
| the gtk.TextTag being
removed |
| a gtk.TextIter
pointing to the start of the range of text |
| a gtk.TextIter
pointing to the end of the range of text |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "remove-tag" signal is emitted when
texttag
is being removed from the
textbuffer
text in the range specified by
start
and end
.