Skip to content

Gtk.TextTagTable

class — extends GObject.Object, Buildable

Collects the tags in a GtkTextBuffer.

You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.

GtkTextTagTables as GtkBuildable

The GtkTextTagTable implementation of the GtkBuildable interface supports adding tags by specifying “tag” as the “type” attribute of a <child> element.

An example of a UI definition fragment specifying tags:

<object class="GtkTextTagTable">
 <child type="tag">
   <object class="GtkTextTag"/>
 </child>
</object>

Constructors

new

@classmethod
def new(cls) -> TextTagTable

Creates a new GtkTextTagTable.

The table contains no tags by default.

Methods

add

def add(self, tag: TextTag) -> bool

Add a tag to the table.

The tag is assigned the highest priority in the table.

tag must not be in a tag table already, and may not have the same name as an already-added tag.

Parameters:

  • tag — a GtkTextTag

foreach

def foreach(self, func: TextTagTableForeach) -> None

Calls func on each tag in table, with user data data.

Note that the table may not be modified while iterating over it (you can’t add/remove tags).

Parameters:

  • func — a function to call on each tag

get_size

def get_size(self) -> int

Returns the size of the table (number of tags)

lookup

def lookup(self, name: str) -> TextTag | None

Look up a named tag.

Parameters:

  • name — name of a tag

remove

def remove(self, tag: TextTag) -> None

Remove a tag from the table.

If a GtkTextBuffer has table as its tag table, the tag is removed from the buffer. The table’s reference to the tag is removed, so the tag will end up destroyed if you don’t have a reference to it.

Parameters:

  • tag — a GtkTextTag

Signals

tag-added

def on_tag_added(self, tag: TextTag) -> None: ...

Emitted every time a new tag is added in the GtkTextTagTable.

tag-changed

def on_tag_changed(self, tag: TextTag, size_changed: bool) -> None: ...

Emitted every time a tag in the GtkTextTagTable changes.

tag-removed

def on_tag_removed(self, tag: TextTag) -> None: ...

Emitted every time a tag is removed from the GtkTextTagTable.

The tag is still valid by the time the signal is emitted, but it is not associated with a tag table any more.