AttrList
- class AttrList(**kwargs)
A PangoAttrList
represents a list of attributes that apply to a section
of text.
The attributes in a PangoAttrList
are, in general, allowed to overlap in
an arbitrary fashion. However, if the attributes are manipulated only through
change
, the overlap between properties will meet
stricter criteria.
Since the PangoAttrList
structure is stored as a linear list, it is not
suitable for storing attributes for large amounts of text. In general, you
should not use a single PangoAttrList
for more than one paragraph of text.
Constructors
Methods
- class AttrList
- change(attr: Attribute) None
Insert the given attribute into the
PangoAttrList
.It will replace any attributes of the same type on that segment and be merged with any adjoining attributes that are identical.
This function is slower than
insert
for creating an attribute list in order (potentially much slower for large lists). However,insert
is not suitable for continually changing a set of attributes since it never removes or combines existing attributes.- Parameters:
attr – the attribute to insert
- equal(other_list: AttrList) bool
Checks whether
list
andother_list
contain the same attributes and whether those attributes apply to the same ranges.Beware that this will return wrong values if any list contains duplicates.
Added in version 1.46.
- Parameters:
other_list – the other
PangoAttrList
- filter(func: Callable[[...], bool], *data: Any) AttrList | None
Given a
PangoAttrList
and callback function, removes any elements oflist
for whichfunc
returnsTrue
and inserts them into a new list.Added in version 1.2.
- Parameters:
func – callback function; returns
True
if an attribute should be filtered outdata – Data to be passed to
func
- from_string(text: str) AttrList | None
Deserializes a
PangoAttrList
from a string.This is the counterpart to
to_string
. See that functions for details about the format.Added in version 1.50.
- Parameters:
text – a string
- get_iterator() AttrIterator
Create a iterator initialized to the beginning of the list.
list
must not be modified until this iterator is freed.
- insert(attr: Attribute) None
Insert the given attribute into the
PangoAttrList
.It will be inserted after all other attributes with a matching
start_index
.- Parameters:
attr – the attribute to insert
- insert_before(attr: Attribute) None
Insert the given attribute into the
PangoAttrList
.It will be inserted before all other attributes with a matching
start_index
.- Parameters:
attr – the attribute to insert
- splice(other: AttrList, pos: int, len: int) None
This function opens up a hole in
list
, fills it in with attributes from the left, and then mergesother
on top of the hole.This operation is equivalent to stretching every attribute that applies at position
pos
inlist
by an amountlen
, and then callingchange
with a copy of each attribute inother
in sequence (offset in position bypos
, and limited in length tolen
).This operation proves useful for, for instance, inserting a pre-edit string in the middle of an edit buffer.
For backwards compatibility, the function behaves differently when
len
is 0. In this case, the attributes fromother
are not imited tolen
, and are just overlayed on top oflist
.This mode is useful for merging two lists of attributes together.
- Parameters:
other – another
PangoAttrList
pos – the position in
list
at which to insertother
len – the length of the spliced segment. (Note that this must be specified since the attributes in
other
may only be present at some subsection of this range)
- to_string() str
Serializes a
PangoAttrList
to a string.In the resulting string, serialized attributes are separated by newlines or commas. Individual attributes are serialized to a string of the form
START END TYPE VALUE
Where START and END are the indices (with -1 being accepted in place of MAXUINT), TYPE is the nickname of the attribute value type, e.g. weight or stretch, and the value is serialized according to its type:
enum values as nick or numeric value
boolean values as true or false
integers and floats as numbers
strings as string, optionally quoted
font features as quoted string
PangoLanguage as string
PangoFontDescription as serialized by
to_string
, quotedPangoColor as serialized by
to_string
Examples:
0 10 foreground red, 5 15 weight bold, 0 200 font-desc "Sans 10"
0 -1 weight 700 0 100 family Times
To parse the returned value, use
from_string
.Note that shape attributes can not be serialized.
Added in version 1.50.
- update(pos: int, remove: int, add: int) None
Update indices of attributes in
list
for a change in the text they refer to.The change that this function applies is removing
remove
bytes at positionpos
and insertingadd
bytes instead.Attributes that fall entirely in the (
pos
,pos
+remove
) range are removed.Attributes that start or end inside the (
pos
,pos
+remove
) range are shortened to reflect the removal.Attributes start and end positions are updated if they are behind
pos
+remove
.Added in version 1.44.
- Parameters:
pos – the position of the change
remove – the number of removed bytes
add – the number of added bytes