Skip to content

Gtk.FontChooser

interface

:::warning Deprecated since 4.10 This API is deprecated. :::

GtkFontChooser is an interface that can be implemented by widgets for choosing fonts.

In GTK, the main objects that implement this interface are FontChooserWidget, FontChooserDialog and FontButton.

Methods

get_font

def get_font(self) -> str | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the currently-selected font name.

Note that this can be a different string than what you set with FontChooser.set_font, as the font chooser widget may normalize font names and thus return a string with a different structure. For example, “Helvetica Italic Bold 12” could be normalized to “Helvetica Bold Italic 12”.

Use Pango.FontDescription.equal if you want to compare two font descriptions.

get_font_desc

def get_font_desc(self) -> Pango.FontDescription | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the currently-selected font.

Note that this can be a different string than what you set with FontChooser.set_font, as the font chooser widget may normalize font names and thus return a string with a different structure. For example, “Helvetica Italic Bold 12” could be normalized to “Helvetica Bold Italic 12”.

Use Pango.FontDescription.equal if you want to compare two font descriptions.

get_font_face

def get_font_face(self) -> Pango.FontFace | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the PangoFontFace representing the selected font group details (i.e. family, slant, weight, width, etc).

If the selected font is not installed, returns None.

get_font_family

def get_font_family(self) -> Pango.FontFamily | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the PangoFontFamily representing the selected font family.

Font families are a collection of font faces.

If the selected font is not installed, returns None.

get_font_features

def get_font_features(self) -> str

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the currently-selected font features.

The format of the returned string is compatible with the CSS font-feature-settings property. It can be passed to Pango.AttrFontFeatures.new.

get_font_map

def get_font_map(self) -> Pango.FontMap | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the custom font map of this font chooser widget, or None if it does not have one.

get_font_size

def get_font_size(self) -> int

:::warning Deprecated since 4.10 This API is deprecated. :::

The selected font size.

get_language

def get_language(self) -> str

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the language that is used for font features.

get_level

def get_level(self) -> FontChooserLevel

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the current level of granularity for selecting fonts.

get_preview_text

def get_preview_text(self) -> str

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the text displayed in the preview area.

get_show_preview_entry

def get_show_preview_entry(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns whether the preview entry is shown or not.

set_filter_func

def set_filter_func(self, filter: FontFilterFunc | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Adds a filter function that decides which fonts to display in the font chooser.

Parameters:

  • filter — a GtkFontFilterFunc

set_font

def set_font(self, fontname: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the currently-selected font.

Parameters:

  • fontname — a font name like “Helvetica 12” or “Times Bold 18”

set_font_desc

def set_font_desc(self, font_desc: Pango.FontDescription) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the currently-selected font from font_desc.

Parameters:

  • font_desc — a PangoFontDescription

set_font_map

def set_font_map(self, fontmap: Pango.FontMap | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets a custom font map to use for this font chooser widget.

A custom font map can be used to present application-specific fonts instead of or in addition to the normal system fonts.

FcConfig *config;
PangoFontMap *fontmap;

config = FcInitLoadConfigAndFonts ();
FcConfigAppFontAddFile (config, my_app_font_file);

fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config);

gtk_font_chooser_set_font_map (font_chooser, fontmap);

Note that other GTK widgets will only be able to use the application-specific font if it is present in the font map they use:

context = gtk_widget_get_pango_context (label);
pango_context_set_font_map (context, fontmap);

Parameters:

  • fontmap — a PangoFontMap

set_language

def set_language(self, language: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the language to use for font features.

Parameters:

  • language — a language

set_level

def set_level(self, level: FontChooserLevel | int) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the desired level of granularity for selecting fonts.

Parameters:

  • level — the desired level of granularity

set_preview_text

def set_preview_text(self, text: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the text displayed in the preview area.

The text is used to show how the selected font looks.

Parameters:

  • text — the text to display in the preview area

set_show_preview_entry

def set_show_preview_entry(self, show_preview_entry: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Shows or hides the editable preview entry.

Parameters:

  • show_preview_entry — whether to show the editable preview entry or not

Virtual methods

do_font_activated

def do_font_activated(self, fontname: str) -> None

do_get_font_face

def do_get_font_face(self) -> Pango.FontFace | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the PangoFontFace representing the selected font group details (i.e. family, slant, weight, width, etc).

If the selected font is not installed, returns None.

do_get_font_family

def do_get_font_family(self) -> Pango.FontFamily | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the PangoFontFamily representing the selected font family.

Font families are a collection of font faces.

If the selected font is not installed, returns None.

do_get_font_map

def do_get_font_map(self) -> Pango.FontMap | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the custom font map of this font chooser widget, or None if it does not have one.

do_get_font_size

def do_get_font_size(self) -> int

:::warning Deprecated since 4.10 This API is deprecated. :::

The selected font size.

do_set_filter_func

def do_set_filter_func(self, filter: FontFilterFunc | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Adds a filter function that decides which fonts to display in the font chooser.

Parameters:

  • filter — a GtkFontFilterFunc

do_set_font_map

def do_set_font_map(self, fontmap: Pango.FontMap | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets a custom font map to use for this font chooser widget.

A custom font map can be used to present application-specific fonts instead of or in addition to the normal system fonts.

FcConfig *config;
PangoFontMap *fontmap;

config = FcInitLoadConfigAndFonts ();
FcConfigAppFontAddFile (config, my_app_font_file);

fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config);

gtk_font_chooser_set_font_map (font_chooser, fontmap);

Note that other GTK widgets will only be able to use the application-specific font if it is present in the font map they use:

context = gtk_widget_get_pango_context (label);
pango_context_set_font_map (context, fontmap);

Parameters:

  • fontmap — a PangoFontMap

Properties

font

font: str  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

The font description as a string, e.g. "Sans Italic 12".

font_desc

font_desc: Pango.FontDescription  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

The font description as a PangoFontDescription.

font_features

font_features: str  # read-only

:::warning Deprecated since 4.10 This API is deprecated. :::

The selected font features.

The format of the string is compatible with CSS and with Pango attributes.

language

language: str  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

The language for which the font features were selected.

level

level: FontChooserLevel | int  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

The level of granularity to offer for selecting fonts.

preview_text

preview_text: str  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

The string with which to preview the font.

show_preview_entry

show_preview_entry: bool  # read/write

:::warning Deprecated since 4.10 This API is deprecated. :::

Whether to show an entry to change the preview text.

Signals

font-activated

def on_font_activated(self, fontname: str) -> None: ...

:::warning Deprecated since 4.10 This API is deprecated. :::

Emitted when a font is activated.

This usually happens when the user double clicks an item, or an item is selected and the user presses one of the keys Space, Shift+Space, Return or Enter.