Skip to content

Gtk.TextTag

class — extends GObject.Object

Can be applied to text contained 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.

Tags should be in the TextTagTable for a given GtkTextBuffer before using them with that buffer.

TextBuffer.create_tag is the best way to create tags. See “gtk4-demo” for numerous examples.

For each property of GtkTextTag, there is a “set” property, e.g. “font-set” corresponds to “font”. These “set” properties reflect whether a property has been set or not.

They are maintained by GTK and you should not set them independently.

Constructors

new

@classmethod
def new(cls, name: str | None = ...) -> TextTag

Creates a GtkTextTag.

Parameters:

  • name — tag name

Methods

changed

def changed(self, size_changed: bool) -> None

Emits the TextTagTable.tag-changed signal on the GtkTextTagTable where the tag is included.

The signal is already emitted when setting a GtkTextTag property. This function is useful for a GtkTextTag subclass.

Parameters:

  • size_changed — whether the change affects the GtkTextView layout

get_priority

def get_priority(self) -> int

Get the tag priority.

set_priority

def set_priority(self, priority: int) -> None

Sets the priority of a GtkTextTag.

Valid priorities start at 0 and go to one less than TextTagTable.get_size. Each tag in a table has a unique priority; setting the priority of one tag shifts the priorities of all the other tags in the table to maintain a unique priority for each tag.

Higher priority tags “win” if two tags both set the same text attribute. When adding a tag to a tag table, it will be assigned the highest priority in the table by default; so normally the precedence of a set of tags is the order in which they were added to the table, or created with TextBuffer.create_tag, which adds the tag to the buffer’s table automatically.

Parameters:

  • priority — the new priority

Properties

accumulative_margin

accumulative_margin: bool  # read/write

Whether the margins accumulate or override each other.

When set to True the margins of this tag are added to the margins of any other non-accumulative margins present. When set to False the margins override one another (the default).

allow_breaks

allow_breaks: bool  # read/write

Whether breaks are allowed.

allow_breaks_set

allow_breaks_set: bool  # read/write

Whether the allow-breaks property is set.

background

background: str  # read/write

Background color as a string.

background_full_height

background_full_height: bool  # read/write

Whether the background color fills the entire line height or only the height of the tagged characters.

background_full_height_set

background_full_height_set: bool  # read/write

Whether the background-full-height property is set.

background_rgba

background_rgba: Gdk.RGBA  # read/write

Background color as a GdkRGBA.

background_set

background_set: bool  # read/write

Whether the background property is set.

direction

direction: TextDirection | int  # read/write

Text direction, e.g. right-to-left or left-to-right.

editable

editable: bool  # read/write

Whether the text can be modified by the user.

editable_set

editable_set: bool  # read/write

Whether the editable property is set.

fallback

fallback: bool  # read/write

Whether font fallback is enabled.

When set to True, other fonts will be substituted where the current font is missing glyphs.

fallback_set

fallback_set: bool  # read/write

Whether the fallback property is set.

family

family: str  # read/write

Name of the font family, e.g. Sans, Helvetica, Times, Monospace.

family_set

family_set: bool  # read/write

Whether the family property is set.

font

font: str  # read/write

Font description as string, e.g. \"Sans Italic 12\".

Note that the initial value of this property depends on the internals of PangoFontDescription.

font_desc

font_desc: Pango.FontDescription  # read/write

Font description as a PangoFontDescription.

font_features

font_features: str  # read/write

OpenType font features, as a string.

font_features_set

font_features_set: bool  # read/write

Whether the font-features property is set.

foreground

foreground: str  # read/write

Foreground color as a string.

foreground_rgba

foreground_rgba: Gdk.RGBA  # read/write

Foreground color as a GdkRGBA.

foreground_set

foreground_set: bool  # read/write

Whether the foreground property is set.

indent

indent: int  # read/write

Amount to indent the paragraph, in pixels.

A negative value of indent will produce a hanging indentation. That is, the first line will have the full width, and subsequent lines will be indented by the absolute value of indent.

indent_set

indent_set: bool  # read/write

Whether the indent property is set.

insert_hyphens

insert_hyphens: bool  # read/write

Whether to insert hyphens at breaks.

insert_hyphens_set

insert_hyphens_set: bool  # read/write

Whether the insert-hyphens property is set.

invisible

invisible: bool  # read/write

Whether this text is hidden.

Note that there may still be problems with the support for invisible text, in particular when navigating programmatically inside a buffer containing invisible segments.

invisible_set

invisible_set: bool  # read/write

Whether the invisible property is set.

justification

justification: Justification | int  # read/write

Left, right, or center justification.

justification_set

justification_set: bool  # read/write

Whether the justification property is set.

language

language: str  # read/write

The language this text is in, as an ISO code.

Pango can use this as a hint when rendering the text. If not set, an appropriate default will be used.

Note that the initial value of this property depends on the current locale, see also get_default_language.

language_set

language_set: bool  # read/write

Whether the language property is set.

left_margin

left_margin: int  # read/write

Width of the left margin in pixels.

left_margin_set

left_margin_set: bool  # read/write

Whether the left-margin property is set.

letter_spacing

letter_spacing: int  # read/write

Extra spacing between graphemes, in Pango units.

letter_spacing_set

letter_spacing_set: bool  # read/write

Whether the letter-spacing property is set.

line_height

line_height: float  # read/write

Factor to scale line height by.

line_height_set

line_height_set: bool  # read/write

Whether the line-height property is set.

name

name: str  # read/write

The name used to refer to the tag.

None for anonymous tags.

overline

overline: Pango.Overline | int  # read/write

Style of overline for this text.

overline_rgba

overline_rgba: Gdk.RGBA  # read/write

This property modifies the color of overlines.

If not set, overlines will use the foreground color.

overline_rgba_set

overline_rgba_set: bool  # read/write

Whether the overline-rgba property is set.

overline_set

overline_set: bool  # read/write

Whether the overline property is set.

paragraph_background

paragraph_background: str  # read/write

The paragraph background color as a string.

paragraph_background_rgba

paragraph_background_rgba: Gdk.RGBA  # read/write

The paragraph background color as a GdkRGBA.

paragraph_background_set

paragraph_background_set: bool  # read/write

Whether the paragraph-background property is set.

pixels_above_lines

pixels_above_lines: int  # read/write

Pixels of blank space above paragraphs.

pixels_above_lines_set

pixels_above_lines_set: bool  # read/write

Whether the pixels-above-lines property is set.

pixels_below_lines

pixels_below_lines: int  # read/write

Pixels of blank space below paragraphs.

pixels_below_lines_set

pixels_below_lines_set: bool  # read/write

Whether the pixels-below-lines property is set.

pixels_inside_wrap

pixels_inside_wrap: int  # read/write

Pixels of blank space between wrapped lines in a paragraph.

pixels_inside_wrap_set

pixels_inside_wrap_set: bool  # read/write

Whether the pixels-inside-wrap property is set.

right_margin

right_margin: int  # read/write

Width of the right margin, in pixels.

right_margin_set

right_margin_set: bool  # read/write

Whether the right-margin property is set.

rise

rise: int  # read/write

Offset of text above the baseline, in Pango units.

Negative values go below the baseline.

rise_set

rise_set: bool  # read/write

Whether the rise property is set.

scale

scale: float  # read/write

Font size as a scale factor relative to the default font size.

This properly adapts to theme changes, etc. so is recommended. Pango predefines some scales such as PANGO_SCALE_X_LARGE.

scale_set

scale_set: bool  # read/write

Whether the scale property is set.

sentence

sentence: bool  # read/write

Whether this tag represents a single sentence.

This affects cursor movement.

sentence_set

sentence_set: bool  # read/write

Whether the sentence property is set.

show_spaces

show_spaces: Pango.ShowFlags | int  # read/write

How to render invisible characters.

show_spaces_set

show_spaces_set: bool  # read/write

Whether the show-spaces property is set.

size

size: int  # read/write

Font size in Pango units.

size_points

size_points: float  # read/write

Font size in points.

size_set

size_set: bool  # read/write

Whether the size property is set.

stretch

stretch: Pango.Stretch | int  # read/write

Font stretch as a PangoStretch, e.g. Pango.Stretch.CONDENSED.

stretch_set

stretch_set: bool  # read/write

Whether the stretch property is set.

strikethrough

strikethrough: bool  # read/write

Whether to strike through the text.

strikethrough_rgba

strikethrough_rgba: Gdk.RGBA  # read/write

This property modifies the color of strikeouts.

If not set, strikeouts will use the foreground color.

strikethrough_rgba_set

strikethrough_rgba_set: bool  # read/write

If the strikethrough-rgba property has been set.

strikethrough_set

strikethrough_set: bool  # read/write

Whether the strikethrough property is set.

style

style: Pango.Style | int  # read/write

Font style as a PangoStyle, e.g. Pango.Style.ITALIC.

style_set

style_set: bool  # read/write

Whether the style property is set.

tabs

tabs: Pango.TabArray  # read/write

Custom tabs for this text.

tabs_set

tabs_set: bool  # read/write

Whether the tabs property is set.

text_transform

text_transform: Pango.TextTransform | int  # read/write

How to transform the text for display.

text_transform_set

text_transform_set: bool  # read/write

Whether the text-transform property is set.

underline

underline: Pango.Underline | int  # read/write

Style of underline for this text.

underline_rgba

underline_rgba: Gdk.RGBA  # read/write

This property modifies the color of underlines.

If not set, underlines will use the foreground color.

If TextTag.underline is set to Pango.Underline.ERROR, an alternate color may be applied instead of the foreground. Setting this property will always override those defaults.

underline_rgba_set

underline_rgba_set: bool  # read/write

If the underline-rgba property has been set.

underline_set

underline_set: bool  # read/write

Whether the underline property is set.

variant

variant: Pango.Variant | int  # read/write

Font variant as a PangoVariant, e.g. Pango.Variant.SMALL_CAPS.

variant_set

variant_set: bool  # read/write

Whether the variant property is set.

weight

weight: int  # read/write

Font weight as an integer.

weight_set

weight_set: bool  # read/write

Whether the weight property is set.

word

word: bool  # read/write

Whether this tag represents a single word.

This affects line breaks and cursor movement.

word_set

word_set: bool  # read/write

Whether the word property is set.

wrap_mode

wrap_mode: WrapMode | int  # read/write

Whether to wrap lines never, at word boundaries, or at character boundaries.

wrap_mode_set

wrap_mode_set: bool  # read/write

Whether the wrap-mode property is set.