gtk.TextIter — an object pointing at a location in a gtk.TextBuffer
A gtk.TextIter
points to a position between two characters in a gtk.TextBuffer
.
A gtk.TextIter
is
usually created using a gtk.TextBuffer
method and are invalidated when the number of characters in the gtk.TextBuffer
changes (with some exceptions when inserting or deleting) including
inserting or deleting pixbufs or child anchors. There are a huge number of
gtk.TextIter
methods mostly dealing with moving the textiter location in the textbuffer,
checking the location or retrieving text or objects at a location.
def get_buffer()
Returns : | the textbuffer |
The get_buffer
() method returns the
gtk.TextBuffer
object this iterator is associated with.
def copy()
Returns : | a copy of the textiter |
The copy
() method creates a copy of the
textiter.
def get_offset()
Returns : | a character offset |
The get_offset
() method returns the
character offset of the textiter. Each character in a gtk.TextBuffer
has an offset, starting with 0 for the first character in the textbuffer.
Use gtk.TextBuffer.get_iter_at_offset
()
to convert an offset back into a textiter.
def get_line()
Returns : | a line number |
The get_line
() method returns the line
number containing the textiter. Lines in a gtk.TextBuffer
are numbered beginning with 0 for the first line.
def get_line_offset()
Returns : | the offset from the start of the line |
The get_line_offset
() method returns
the character offset of the textiter location, counting from the start of
the line containing the textiter location. The first character on the line
has offset 0.
def get_line_index()
Returns : | the number of bytes from the start of the line |
The get_line_offset
() method returns
the byte index of the textiter location, counting from the start of the line
containing the textiter location. Remember that gtk.TextBuffer
encodes text in UTF-8, and that characters can require a variable number of
bytes to represent.
def get_visible_line_offset()
Returns : | the offset in visible characters from the start of the line |
The get_visible_line_offset
() method
returns the offset in characters of the textiter location from the start of
the line containing the textiter location, not counting characters that are
invisible due to tags with the "invisible" attribute set.
def get_visible_line_index()
Returns : | a byte index from the start of the line |
The get_visible_line_index
() method
returns the byte index of the textiter location from the start of the line,
not counting bytes that are invisible due to tags with the "invisible"
attribute set.
def get_char()
Returns : | a Unicode character, or \0 character if the textiter is not dereferenceable |
The get_char
() method returns the
Unicode character at this textiter location. If the textiter points at a
non-character element, such as an image embedded in the buffer, the Unicode
"unknown" character 0xFFFC is returned. If invoked on the end textiter, the null
character is returned; \0 is not a valid Unicode character. So you can write a loop
which ends when the get_char
()
method returns \0.
def get_slice(end
)
| the textiter at the end of a range |
Returns : | a slice of text from the textbuffer |
The get_slice
() method returns the text
in the range between the locations specified by the textiter and
end
. A "slice" is an array of characters encoded in
UTF-8 format, including the Unicode "unknown" character 0xFFFC for iterable
non-character elements in the textbuffer, such as images. Because images
are encoded in the slice, byte and character offsets in the returned array
will correspond to byte offsets in the textbuffer. 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 textbuffer.
def get_text(end
)
| textiter at end of a range |
Returns : | array of characters from the buffer |
The get_text
() method returns the text
in the range between the locations specified by the textiter and
end
. If the range contains non-text elements such as
images, the character and byte offsets in the returned string will not
correspond to character and byte offsets in the textbuffer. If you want the
offsets to correspond, use the get_slice
()
method.
def get_visible_slice(end
)
| textiter at end of range |
Returns : | a slice of visible text from the textbuffer |
The get_visible_slice
() method is
similar to the get_slice
()
method, but invisible text is excluded. Invisible text is text with the
"invisible" attribute set on it.
def get_visible_text(end
)
| textiter at end of range |
Returns : | a string containing visible text from the textbuffer |
The get_visible_text
() method is
similar to the get_text
(),
but invisible text is excluded. Invisible text is text with the "invisible"
attribute set on it.
def get_pixbuf()
Returns : | a pixbuf or
None |
The get_pixbuf
() method returns the
gtk.gdk.Pixbuf
object at the textiter location, if any; otherwise, None
is returned.
def get_marks()
Returns : | a list of gtk.TextMark
objects |
The get_marks
() method returns a list
of all gtk.TextMark
objects at the textiter location. Because marks don't take up any "space" in
the buffer, multiple marks can exist in the same location. The returned list
is not in any meaningful order.
def get_child_anchor()
Returns : | a child anchor or
None |
The get_child_anchor
() method returns
the gtk.TextChildAnchor
at the textiter location, if any; otherwise, None
is
returned.
def get_toggled_tags(toggled_on
)
| if True get toggled-on tags;
otherwise get toggle-off tags |
Returns : | a list of tags toggled at this point |
The get_toggled_tags
() method returns a
list of gtk.TextTag
objects
that are toggled on or off at this point. If
toggled_on
is True
, the list
contains tags that are toggled on. If a tag is toggled on at the textiter
location, some non-empty range of characters following the textiter has that
tag applied to it. If a tag is toggled off, then some non-empty range
following the textiter location does not have the tag applied to it.
def begins_tag(tag
=None)
| a gtk.TextTag , or
None |
Returns : | True if the textiter is the
start of a range tagged with tag |
The begins_tag
() method returns
True
if tag
is toggled on at
exactly this point. If tag
is
None
, this method returns True
if any
tag is toggled on at this point. Note that the
begins_tag
() method returns True
only if the
textiter location is the start of the tagged range; the
has_tag
()
indicates if a textiter location is within a tagged
range.
def ends_tag(tag
=None)
| a gtk.TextTag , or
None |
Returns : | True if the textiter is the
end of a range tagged with tag |
The ends_tag
() method returns
True
if tag
is toggled off at the
location the textiter points to. If tag
is
None
, this method returns True
if any
tag is toggled off at this point. Note that the
ends_tag
() returns True
only if
the textiter location is the end of the tagged range;
the has_tag
()
indicates if a textiter location is within a tagged
range.
def toggles_tag(tag
=None)
| a gtk.TextTag , or
None |
Returns : | True if
tag is toggled on or off at the textiter
location |
The toggles_tag
() method returns
True
if a range of text with tag
applied to it begins or ends at the textiter location.
If tag
is None
this method returns
True
if any tag begins or ends at the textiter
location.
def has_tag(tag
)
| a gtk.TextTag |
Returns : | True if the textiter
location is tagged with tag |
The has_tag
() method returns
True
if the textiter location is within a range of text
tagged with tag
.
def get_tags()
Returns : | a list of gtk.TextTag
objects |
The get_tags
() method returns a list of
tags that apply to the textiter location, in ascending order of priority
(highest-priority tags are last).
def editable(default_setting
)
| if True the text is editable
by default |
Returns : | True if the textiter
location is inside an editable range or text |
The editable
() method returns
True
if the character at the textiter location is within
an editable range of text. Non-editable text is "locked" and can't be
changed by the user via a gtk.TextView
. This
method is a convenience wrapper around the get_attributes
()
method. If no tags applied to this text location affect editability, the
value of default_setting
will be returned.
Do not use this method to determine if text can be inserted at
the textiter location. For insertion you don't want to know if the char at
the textiter location is inside an editable range of text, you want to know
whether a new character inserted at the textiter location would be inside an
editable range of text. Use the can_insert
()
method to determine if text can be inserted.
def can_insert(default_editability
)
| if True the text is editable
by default |
Returns : | True if text inserted at
iter would be editable |
The can_insert
() method considers the
default editability of the buffer, and the tags that affect editability, to
determine if text inserted at the textiter location would be editable. If
so, the user should be allowed to insert text at the textiter location. The
gtk.TextBuffer.insert_interactive
()
uses this function to determine if insertions are allowed at a given
position.
def starts_word()
Returns : | True if the textiter
location is at the start of a word |
The starts_word
() method returns
True
if the textiter location begins a natural-language
word. Word breaks are determined by Pango and should be correct for nearly
any language (if not, the correct fix would be to the Pango word break
algorithms).
def ends_word()
Returns : | True if the textiter
location is at the end of a word |
The ends_word
() method returns
True
if the textiter location ends a natural-language
word. Word breaks are determined by Pango and should be correct for nearly
any language (if not, the correct fix would be to the Pango word break
algorithms).
def inside_word()
Returns : | True if the textiter
location is inside a word |
The inside_word
() method returns
True
if the textiter location is inside a
natural-language word (as opposed to say inside some whitespace). Word
breaks are determined by Pango and should be correct for nearly any language
(if not, the correct fix would be to the Pango word break
algorithms).
def starts_sentence()
Returns : | True if the textiter
location is at the start of a sentence. |
The starts_sentence
() method returns
True
if the textiter location begins a sentence.
Sentence boundaries are determined by Pango and should be correct for nearly
any language (if not, the correct fix would be to the Pango text boundary
algorithms).
def ends_sentence()
Returns : | True if the textiter
location is at the end of a sentence. |
The ends_sentence
() method returns
True
if the textiter location ends a sentence. Sentence
boundaries are determined by Pango and should be correct for nearly any
language (if not, the correct fix would be to the Pango text boundary
algorithms).
def inside_sentence()
Returns : | True if the textiter
location is inside a sentence. |
The inside_sentence
() method returns
True
if the textiter location is inside a sentence (as
opposed to in between two sentences, e.g. after a period and before the
first letter of the next sentence). Sentence boundaries are determined by
Pango and should be correct for nearly any language (if not, the correct fix
would be to the Pango text boundary algorithms).
def starts_line()
Returns : | True if the textiter
location begins a line |
The starts_line
() method returns
True
if the textiter location begins a paragraph, i.e. if
the .get_line_offset
()
method would return 0.
def ends_line()
Returns : | True if the textiter
location is at the end of a line |
The ends_line
() method returns
True
if the textiter location points to the start of the
paragraph delimiter characters for a line (delimiters will be either a
newline, a carriage return, a carriage return followed by a newline, or a
Unicode paragraph separator character). Note that an textiter pointing to
the \n of a \r\n pair will not be counted as the end of a line, the line
ends before the \r. The end textiter is considered to be at the end of a
line, even though there are no paragraph delimiter chars there.
def is_cursor_position()
Returns : | True if the cursor can be
placed at the textiter location |
The is_cursor_position
() method returns
True
if the cursor can be placed at the textiter
location. See the forward_cursor_position
()
method for details on what a cursor position is.
def get_chars_in_line()
Returns : | the number of characters in the line |
The get_chars_in_line
() method returns
the number of characters in the line containing the textiter location,
including the paragraph delimiters.
def get_bytes_in_line()
Returns : | the number of bytes in the line |
The get_bytes_in_line
() method returns
the number of bytes in the line containing the textiter location, including
the paragraph delimiters.
def get_attributes(values
)
| a gtk.TextAttributes
object to be filled in |
Returns : | True if
values was modified |
The get_attributes
() method computes
the effect of any tags applied to the textiter location and applies those
attributes to the gtk.TextAttributes
object specified by values
(which should be
initialized to the default settings you wish to use if no tags are in
effect). Typically the default attributes are obtained from the gtk.TextView.get_default_attributes
()
method. If any tags affected values
, the method
returns True
.
def get_language()
Returns : | the pango language in effect at the textiter location |
The get_language
() method is a
convenience wrapper around the get_attributes
()
method, that returns the language in effect at the textiter location. If no
tags affecting language apply to the textiter location, the return value is
identical to that of the gtk.get_default_language()
function.
def is_end()
Returns : | True if the textiter is the
end textiter |
The is_end
() method returns
True
if the textiter is the end textiter, i.e. one past
the last dereferenceable textiter in the buffer. The
is_end
() method is the most efficient way to check
whether an textiter is the end textiter.
def is_start()
Returns : | True if the textiter
location is at the start of the textbuffer |
The is_start
() method returns
True
if the textiter location is at the start of the
textbuffer, that is if the textiter location has a character offset of
0.
def forward_char()
Returns : | True if the textiter
location moved and is dereferenceable |
The forward_char
() method moves the
textiter location forward by one character offset and returns
True
if the textiter location moved and the new location
is dereferenceable. Note that images embedded in the buffer occupy 1
character slot, so the forward_char
() method may
actually move onto an image instead of a character, if you have images in
your buffer. If the textiter location is the end textiter or one character
before it, the textiter location will now point at the end textiter, and the
forward_char
() method returns
False
.
def backward_char()
Returns : | True if the textiter location moved and is not the start textiter |
The backward_char
() method moves the
textiter location backward by one character offset and returns
True
if the textiter location moved. If the old textiter
location was the first in the buffer (character offset 0), the
backward_char
() method returns
False
.
def forward_chars(count
)
| the number of characters to move, may be negative |
Returns : | True if the textiter
location moved and is dereferenceable |
The forward_chars
() method moves the
textiter location forward count
characters if
possible. If the textiter location would move past the start or end of the
buffer, the location moves to the start or end of the textbuffer. The
forward_chars
() method returns
True
if the new position of the resulting textiter
location is different from its original position, and is dereferenceable
(the last textiter in the buffer is not dereferenceable). If
count
is 0, the function does nothing and returns
False
.
def backward_chars(count
)
| the number of characters to move, may be negative |
Returns : | True if the textiter
location moved and is dereferenceable |
The backward_chars
() method moves the
textiter location backward forward count
characters,
if possible. If the textiter location would move past the start or end of
the buffer, the location moves to the start or end of the textbuffer. The
backward_chars
() method returns
True
if the new position of the resulting textiter
location is different from its original position, and is dereferenceable
(the last textiter in the buffer is not dereferenceable). If
count
is 0, the function does nothing and returns
False
.
def forward_line()
Returns : | True if the textiter
location can be dereferenced |
The forward_line
() method moves the
textiter location to the start of the next line and returns
True
if the textiter location moved to a dereferenceable
position, and False
if the textiter location moved to the
end of the buffer, or if the textiter location was originally at the end of
the buffer.
def backward_line()
Returns : | True if the textiter
location moved |
The backward_line
() method moves the
textiter location to the start of the previous line and returns
True
if the textiter location was moved. If the textiter
location was at the textbuffer start, this method returns
False
. For example if the textiter location was already
on line 0, but not at the start of the line, the textiter location is
snapped to the start of the line and the method returns
True
.
def forward_lines(count
)
| the number of lines to move forward, may be negative |
Returns : | True if the textiter
location moved and is dereferenceable |
The forward_lines
() method moves the
textiter location forward count
lines, if possible.
If the textiter location would move past the start or end of the buffer, the
location moves to the start or end of the textbuffer. The method
returns:
True
if the textiter moved to a
dereferenceable position; or,False
if the textiter location didn't
move, or moved onto the end textiter or if count
was
0.If count
is negative, the textiter
location moves backward by count
lines.
def backward_lines(count
)
| the number of lines to move backward, may be negative |
Returns : | True if the textiter
location moved to a dereferenceable position |
The backward_lines
() method moves the
textiter location backward by count
lines, if
possible. If the textiter location would move past the start or end of the
buffer, the location moves to the start or end of the textbuffer. The
method returns:
True
if the textiter moved to a
dereferenceable position; or,False
if the textiter location didn't
move, or moved onto the end textiter or if count
was
0.If count
is negative, the textiter
location moves forward by count
lines.
def forward_word_ends(count
)
| the number of times to move |
Returns : | True if the textiter
location moved and is not the end textiter |
The forward_word_ends
() method calls
the forward_word_end
()
method up to count
times or the backward_word_starts
()
method if count
is negative. The method returns
True
if the textiter location changed and the resulting
location is not at the end of the textbuffer.
def backward_word_starts(count
)
| the number of times to move |
Returns : | True if the textiter
location moved and is not the end textiter |
The backward_word_starts(
) method calls the
backward_word_start
()
method up to count
times or the forward_word_ends
()
method if count
is negative. The method returns
True
if the textiter location changed and the resulting
location is not at the end of the textbuffer.
def forward_word_end()
Returns : | True if the textiter
location moved to a dereferenceable position |
The forward_word_end
() method moves the
textiter location forward to the next word end. If the textiter location is
currently on a word end, the location moves forward to the next one after
that. Word breaks are determined by Pango and should be correct for nearly
any language (if not, the correct fix would be to the Pango word break
algorithms). The method returns True if the textiter location moved to a
dereferenceable position
def backward_word_start()
Returns : | True if the textiter
location moved |
The backward_word_start
() method moves
the textiter location backward to the previous word start. If the textiter
location is currently on a word start, the location moves backward to the
next one before that. Word breaks are determined by Pango and should be
correct for nearly any language (if not, the correct fix would be to the
Pango word break algorithms). The method returns True
if
the textiter location moved.
def forward_cursor_position()
Returns : | True if we moved and the new
position is dereferenceable |
The forward_cursor_position
() method
moves the textiter location forward by a single cursor position. Cursor
positions are (unsurprisingly) positions where the cursor can appear.
Surprisingly, there may not be a cursor position between all characters. The
most common example for European languages would be a carriage
return/newline sequence. For some Unicode characters, the equivalent of say
the letter "a" with an accent mark will be represented as two characters,
first the letter then a "combining mark" that causes the accent to be
rendered; so the cursor can't go between those two characters. The method
returns True
if the textiter location changed and the
resulting location is not at the end of the textbuffer.
def backward_cursor_position()
Returns : | True if we moved and the new
position is dereferenceable |
The backward_cursor_position
() method
is similar to the forward_cursor_position
()
method, except the location moves backward.
def forward_cursor_positions(count
)
| the number of positions to move |
Returns : | True if the textiter
location moved and the new position is dereferenceable |
The forward_cursor_positions
() method
moves up to count
cursor positions. See the forward_cursor_position
()
method for more details. The method returns True
if the
textiter moved to a dereferenceable location.
def backward_cursor_positions(count
)
| the number of positions to move |
Returns : | True if the textiter
location moved and the new position is dereferenceable |
The backward_cursor_positions
() method
moves the textiter location up to count
cursor
positions. See the forward_cursor_position
()
method for details.
def backward_sentence_start()
Returns : | True if the textiter
location moved |
The backward_sentence_start
() method
moves the textiter location backward to the previous sentence start. If the
textiter location is already at the start of a sentence, the location moves
backward to the next one. Sentence boundaries are determined by Pango and
should be correct for nearly any language (if not, the correct fix would be
to the Pango text boundary algorithms).
def forward_sentence_end()
Returns : | True if the textiter
location moved and is not the end textiter |
The forward_sentence_end
() method moves
the textiter location forward to the next sentence end. (If the textiter
location is at the end of a sentence, the location moves to the next end of
sentence.) Sentence boundaries are determined by Pango and should be
correct for nearly any language (if not, the correct fix would be to the
Pango text boundary algorithms). The method returns True
if the textiter location changed and the resulting location is not at the
end of the textbuffer.
def backward_sentence_starts(count
)
| the number of sentences to move |
Returns : | True if the textiter
location moved and is not the end textiter |
The backward_sentence_starts
() method
calls the backward_sentence_start
()
method (or the forward_sentence_end
()()
method if count is negative) up to count
times, or
until it returns False
. If count
is negative, the location moves forward instead of backward. The method
returns True
if the textiter location changed and the
resulting location is not at the end of the textbuffer.
def forward_sentence_ends(count
)
| the number of sentences to move |
Returns : | True if the textiter
location moved and is not the end textiter |
The forward_sentence_ends
() method
calls the forward_sentence_end
()
method count
times (or until the forward_sentence_end
()
method returns False
). If count
is
negative, the location moves backward instead of forward. The method returns
True
if the textiter location changed and the resulting
location is not at the end of the textbuffer.
def forward_visible_word_ends(count
)
| the number of times to move |
Returns : | True if the textiter moved
and is not the end iterator |
This method is available in PyGTK 2.4 and above.
The forward_visible_word_ends
() method
calls the forward_visible_word_end()
method the number of times specified by count
.
def backward_visible_word_starts(count
)
| the number of times to move |
Returns : | True if the textiter moved
and is not the end iterator |
This method is available in PyGTK 2.4 and above.
The backward_visible_word_starts
()
method calls the backward_visible_word_start()
method the number of times specified by count
.
def forward_visible_word_end()
Returns : | True if the textiter moved
and is not the end iterator |
This method is available in PyGTK 2.4 and above.
The forward_visible_word_end
() method
moves the textiter forward to the next visible word end. (If the textiter is
currently on a word end, it moves forward to the next one after that.) Word
breaks are determined by Pango and should be correct for nearly any language
(if not, the correct fix would be to the Pango word break
algorithms).
def backward_visible_word_start()
Returns : | True if the textiter moved
and is not the end iterator |
This method is available in PyGTK 2.4 and above.
The backward_visible_word_start
()
method moves the textiter backward to the previous visible word start. (If
textiter is currently on a word start, it moves backward to the next one
after that.) Word breaks are determined by Pango and should be correct for
nearly any language (if not, the correct fix would be to the Pango word
break algorithms).
def forward_visible_cursor_position()
Returns : | True if we moved and the new
position is dereferenceable |
This method is available in PyGTK 2.4 and above.
The forward_visible_cursor_position
()
method moves the textiter location forward by a single visible cursor
position. Cursor positions are (unsurprisingly) positions where the cursor
can appear. Surprisingly, there may not be a cursor position between all
characters. The most common example for European languages would be a
carriage return/newline sequence. For some Unicode characters, the
equivalent of say the letter "a" with an accent mark will be represented as
two characters, first the letter then a "combining mark" that causes the
accent to be rendered; so the cursor can't go between those two
characters. The method returns True
if the textiter
location changed and the resulting location is not at the end of the
textbuffer.
def backward_visible_cursor_position()
Returns : | True if we moved and the new
position is dereferenceable |
This method is available in PyGTK 2.4 and above.
The backward_visible_cursor_position
()
method is similar to the forward_visible_cursor_position
()
method, except the location moves backward.
def forward_visible_cursor_positions(count
)
| the number of positions to move |
Returns : | True if the textiter
location moved and the new position is dereferenceable |
This method is available in PyGTK 2.4 and above.
The forward_visible_cursor_positions
()
method moves up to count
visible cursor
positions. See the forward_visible_cursor_position
()
method for more details. The method returns True
if the
textiter moved to a dereferenceable location.
def backward_visible_cursor_positions(count
)
| the number of positions to move |
Returns : | True if the textiter
location moved and the new position is dereferenceable |
This method is available in PyGTK 2.4 and above.
The backward_visible_cursor_positions
()
method moves the textiter location up to count
visible cursor positions. See the forward_visible_cursor_position
()
method for details.
def forward_visible_line()
Returns : | True if the textiter
location can be dereferenced |
This method is available in PyGTK 2.8 and above.
The forward_visible_line
() method moves
the textiter location to the start of the next visible line and returns
True
if the textiter location moved to a dereferenceable
position, and False
if the textiter location moved to the
end of the buffer, or if the textiter location was originally at the end of
the buffer.
def backward_visible_line()
Returns : | True if the textiter
location moved |
This method is available in PyGTK 2.8 and above.
The backward_visible_line
() method
moves the textiter location to the start of the previous visible line and
returns True
if the textiter location was moved. If the
textiter location was at the textbuffer start, this method returns
False
. For example if the textiter location was already
on line 0, but not at the start of the line, the textiter location is
snapped to the start of the line and the method returns
True
.
def forward_visible_lines(count
)
| the number of visible lines to move forward, may be negative |
Returns : | True if the textiter
location moved and is dereferenceable |
This method is available in PyGTK 2.8 and above.
The forward_visible_lines
() method
moves the textiter location forward count
visible
lines, if possible. If the textiter location would move past the start or
end of the buffer, the location moves to the start or end of the textbuffer.
The method returns:
True
if the textiter moved to a
dereferenceable position; or,False
if the textiter location didn't
move, or moved onto the end textiter or if count
was
0.If count
is negative, the textiter
location moves backward by count
visible lines.
def backward_visible_lines(count
)
| the number of visible lines to move backward, may be negative |
Returns : | True if the textiter
location moved to a dereferenceable position |
This method is available in PyGTK 2.8 and above.
The backward_visible_lines
() method
moves the textiter location backward by count
lines,
if possible. If the textiter location would move past the start or end of
the buffer, the location moves to the start or end of the textbuffer. The
method returns:
True
if the textiter moved to a
dereferenceable position; or,False
if the textiter location didn't
move, or moved onto the end textiter or if count
was
0.If count
is negative, the textiter
location moves forward by count
visible lines.
def set_offset(char_offset
)
| a character number |
The set_offset
() method sets the
textiter location to point to the location that is
char_offset
counts from the start of the textbuffer
(starting with 0).
def set_line(line_number
)
| a line number (counted from 0) |
The set_line
() method sets the textiter
location to the start of the line specified by
line_number
. If line_number
is negative or larger than the number of lines in the textbuffer, the method
moves the textiter location to the start of the last line in the
buffer.
def set_line_offset(char_on_line
)
| a character offset relative to the start of the textiter location's current line |
The set_line_offset
() method moves the
textiter location within a line, to the new character
(not byte) offset specified by char_on_line
. The
character offset must be less than or equal to the number of characters in
the line; if equal, the textiter location moves to the start of the next
line. See the set_line_index
()
method if you have a byte index rather than a character offset.
def set_line_index(byte_on_line
)
| a byte index relative to the start of the textiter location's current line |
The set_line_index
() method is similar
to the set_line_offset
(),
but works with a byte index instead of a character
index. The given byte index must be at the start of a character, it can't be
in the middle of a UTF-8 encoded character.
def forward_to_end()
The forward_to_end
() method moves the
textiter location forward to the "end textiter," that points one past the
last valid character in the buffer. The get_char
()
method called on the end textiter returns 0, which is convenient for writing
loops.
def forward_to_line_end()
Returns : | True if we moved and the new
location is not the end textiter |
The forward_to_line_end
() method moves
the textiter to point to the paragraph delimiter characters at the end of
the current line. The paragraph delimiter characters are a newline, a
carriage return, a carriage return-newline in sequence, or the Unicode
paragraph separator character. If the textiter is already at the paragraph
delimiter characters, moves to the paragraph delimiter characters for the
next line. If the textiter location is on the last line in the buffer, which
does not end in paragraph delimiters, moves to the end textiter (end of the
last line), and returns False
.
def set_visible_line_offset(char_on_line
)
| a character offset |
The set_visible_char_offset
() method is
similar to the set_line_offset
()
method, but the offset is in visible characters, i.e. text with the
invisible attribute set is not counted in the offset.
def set_visible_line_index(byte_on_line
)
| a byte index |
The set_visible_line_index
() method is
similar to the set_line_index
()
method, but the index is in visible bytes, i.e. text with the attribute set
is not counted in the index.
def forward_to_tag_toggle(tag
)
| a gtk.TextTag , or
None |
Returns : | True if a tag toggle was
found after the textiter location |
The forward_to_tag_toggle
() method
moves the textiter location forward to the next toggle (on or off) of the
gtk.TextTag
specified by tag
, or to the next toggle of any tag if
tag
is None
. If no matching tag
toggles are found, this method returns False
and sets the
textiter location to the end of the textbuffer; otherwise, returns
True
. The
forward_to_tag_toggle
() method does not recognize
toggles located at the textiter location, only toggles after the textiter
location.
def backward_to_tag_toggle(tag
)
| a gtk.TextTag , or
None |
Returns : | True if a tag toggle was
found before the textiter location |
The backward_to_tag_toggle
() method
moves the textiter location backward to the next toggle (on or off) of the
gtk.TextTag
specified by tag
, or to the next toggle of any tag if
tag
is None
. If no matching tag
toggles are found, this method returns False
and sets the
textiter location to the start of the textbuffer; otherwise, returns
True
. The
backward_to_tag_toggle
() method does not recognize
toggles located at the textiter location, only toggles before the textiter
location.
def forward_find_char(pred
, user_data
, limit
)
| a function to be called on each character |
| user data for
pred |
| a gtk.TextIter
pointing at a position to end the search, or
None for the end of the
buffer. |
Returns : | True if a match was
found |
This method is available in PyGTK 2.4 and above.
The forward_find_char
() method advances
the textiter, calling the function specified by pred
on each character. If pred
returns
True
, forward_find_char
stops
scanning and returns True
. If pred
never returns True
, the textiter location is set to
limit
or the end textiter, if
limit
is None
.
This method is likely to be very slow since the Python
function pred
is called for every character.
def backward_find_char(pred
, user_data
, limit
)
| a function to be called on each character |
| user data for pred |
| a gtk.TextIter
pointing at a position to end the search, or
None for the beginning of the
buffer. |
Returns : | True if a match was
found |
This method is available in PyGTK 2.4 and above.
The backward_find_char
() method is
similar to the forward_find_char()
method, but goes backward from the textiter location.
This method is likely to be very slow since the Python
function pred
is called for every character.
def forward_search(str
, flags
, limit
=None)
| a search string |
| the flags affecting how the search is done |
| a bound for the search, or
None to set the bound to the end of the buffer |
Returns : | a tuple containing gtk.TextIter
objects pointing at the start and end locations of the
match |
The forward_search
() method searches
forward for the text string specified by str
and
returns a tuple containing gtk.TextIter
objects that point at the start and end locations of the match. The search
will stop at the location specified by limit
or the
end of the textbuffer if limit
is
None
or is not specified. Note that a search is a linear
or O(n) operation, so you may wish to use limit
to
avoid locking up your UI when searching large buffers.
If the gtk.TEXT_SEARCH_VISIBLE_ONLY
flag is
present, the match may have invisible text interspersed in
str
(i.e. str
will be a
possibly-noncontiguous subsequence of the matched range). Likewise, if
gtk.TEXT_SEARCH_TEXT_ONLY
is present, the match may have
pixbufs or child anchors mixed inside the matched range. If these flags are
not given, the match must be exact i.e. the special 0xFFFC character in
str
will match embedded pixbufs or child
widgets.
def backward_search(str
, flags
, limit
=None)
| a search string |
| the flags affecting the search |
| a bound for the search, or
None to set the bound to the end of the
buffer |
Returns : | start of match and end of match |
The backward_search
() method is the
same as the forward_search
()
method, except searches backward.
def equal(rhs
)
| another gtk.TextIter
object |
Returns : | True if the textiters point
to the same place in the buffer |
The equal
() method tests if the
textiter specified by rhs
points to the same location
in the textbuffer as the textiter.
def compare(rhs
)
| another gtk.TextIter
object |
Returns : | -1 if the textiter location is less than the
rhs location, 1 if the textiter location is greater,
0 if they are equal |
The compare
() method returns:
rhs
;rhs
; and,rhs
.Ordering is in character offset order, i.e. the first character in the buffer is less than the second character in the buffer.
def in_range(start
, end
)
| the start of the text range |
| the end of the text range |
Returns : | True if the textiter
location is in the text range |
The in_range
() method returns
True
if the textiter location is in the text range
specified by the gtk.TextIter
objects start
and end
.
start
and end
must be in
ascending order.
def order(second
)
| another gtk.TextIter
object |
The order() method swaps the locations of
first
and second
if
second
comes before first
in
the buffer. This method can be used to ensure that
first
and second
are in
sequence. Most text buffer methods that take a range call this
automatically, so there's no real reason to call it yourself in those cases.
There are some exceptions, such as the in_range
(),
that expect a pre-sorted range.