FontChooser

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

class FontChooser(*args, **kwargs)

Implementations: FontButton, FontChooserDialog, FontChooserWidget

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

class FontChooser
get_font() str | None

Gets the currently-selected font name.

Note that this can be a different string than what you set with 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 equal if you want to compare two font descriptions.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_desc() FontDescription | None

Gets the currently-selected font.

Note that this can be a different string than what you set with 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 equal if you want to compare two font descriptions.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_face() FontFace | None

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.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_family() FontFamily | None

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.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_features() str

Gets the currently-selected font features.

The format of the returned string is compatible with the CSS font-feature-settings property <https://www.w3.org/TR/css-fonts-4/``font`-rend-desc>`_. It can be passed to new.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_map() FontMap | None

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_font_size() int

The selected font size.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_language() str

Gets the language that is used for font features.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_level() FontChooserLevel

Returns the current level of granularity for selecting fonts.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_preview_text() str

Gets the text displayed in the preview area.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

get_show_preview_entry() bool

Returns whether the preview entry is shown or not.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

set_filter_func(filter: Callable[[...], bool] | None = None, *user_data: Any) None

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:
  • filter – a GtkFontFilterFunc

  • user_data – data to pass to filter

set_font(fontname: str) None

Sets the currently-selected font.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

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

set_font_desc(font_desc: FontDescription) None

Sets the currently-selected font from font_desc.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

font_desc – a PangoFontDescription

set_font_map(fontmap: FontMap | None = None) None

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);

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

fontmap – a PangoFontMap

set_language(language: str) None

Sets the language to use for font features.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

language – a language

set_level(level: FontChooserLevel) None

Sets the desired level of granularity for selecting fonts.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

level – the desired level of granularity

set_preview_text(text: str) None

Sets the text displayed in the preview area.

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

text – the text to display in the preview area

set_show_preview_entry(show_preview_entry: bool) None

Shows or hides the editable preview entry.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

show_preview_entry – whether to show the editable preview entry or not

Properties

class FontChooser
props.font: str

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.font_desc: FontDescription

The font description as a PangoFontDescription.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.font_features: str

The selected font features.

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.language: str

The language for which the font features were selected.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.level: FontChooserLevel

The level of granularity to offer for selecting fonts.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.preview_text: str

The string with which to preview the font.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

props.show_preview_entry: bool

Whether to show an entry to change the preview text.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Signals

class FontChooser.signals
font_activated(fontname: str) None

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.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

fontname – the font name

Virtual Methods

class FontChooser
do_font_activated(fontname: str) None
Parameters:

fontname

do_get_font_face() FontFace | None

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.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

do_get_font_family() FontFamily | None

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.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

do_get_font_map() FontMap | None

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

do_get_font_size() int

The selected font size.

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

do_set_filter_func(filter: Callable[[...], bool] | None = None, *user_data: Any) None

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

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:
  • filter – a GtkFontFilterFunc

  • user_data – data to pass to filter

do_set_font_map(fontmap: FontMap | None = None) None

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);

Deprecated since version 4.10: Use FontDialog and FontDialogButton instead

Parameters:

fontmap – a PangoFontMap