TextTags specify attributes that can be applied to a range of text in a TextBuffer. Each TextBuffer has a TextTagTable that contains the TextTags that can be applied within the TextBuffer. TextTagTables can be used with more than one TextBuffer to provide consistent text styles. TextTags can be named or anonymous. A TextTag is created using the function:
If name is not specified or is None the tag will be anonymous. TextTags can also be created using the TextBuffer convenience method create_tag() which also allows you specify the tag attributes and adds the tag to the buffer's tag table (see Section 13.3, “Text Buffers”). The attributes that can be contained in a TextTag are:
The attributes can be set by using the method:
Where name is a string containing the name of the property and value is what the property should be set to. Likewise the attribute value can be retrieved with the method:
Since the tag does not have a value set for every attribute there are a set of boolean properties that indicate whether the attribute has been set in the tag:
Therefore to obtain the attribute from a tag, you have to first check whether the attribute has been set in the tag. For example to get a valid justification attribute you may have to do something like:
The priority of a tag is by default the order in which they are added to the TextTagTable. The higher priority tag takes precedence if multiple tags try to set the same attribute for a range of text. The priority can be obtained and set with the methods:
The priority of a tag must be between 0 and one less than the TextTagTable size. A TextTagTable will be created by default when a TextBuffer is created. A TextTagTable can also be created with the function:
A TextTag can be added to a TextTagTable using the method:
The tag must not be in the table and must not have the same name as another tag in the table. You can find a TextTag in a TextTagTable using the method:
The method returns the tag in the table with the given name or None if no tag has that name. A TextTag can be removed from a TextTagTable with the method:
The size of the TextTagTable can be obtained with the method:
|