Gtk.FontChooser

g GObject.GInterface GObject.GInterface Gtk.FontChooser Gtk.FontChooser GObject.GInterface->Gtk.FontChooser

Implementations:

Gtk.FontButton, Gtk.FontChooserDialog, Gtk.FontChooserWidget

Methods

get_font ()

get_font_desc ()

get_font_face ()

get_font_family ()

get_font_features ()

get_font_map ()

get_font_size ()

get_language ()

get_level ()

get_preview_text ()

get_show_preview_entry ()

set_filter_func (filter, *user_data)

set_font (fontname)

set_font_desc (font_desc)

set_font_map (fontmap)

set_language (language)

set_level (level)

set_preview_text (text)

set_show_preview_entry (show_preview_entry)

Virtual Methods

do_font_activated (fontname)

do_get_font_face ()

do_get_font_family ()

do_get_font_map ()

do_get_font_size ()

do_set_filter_func (filter, *user_data)

do_set_font_map (fontmap)

Properties

Name

Type

Flags

Short Description

font

str

r/w

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

font-desc

Pango.FontDescription

r/w

Font description as a Pango.FontDescription struct

font-features

str

r

Font features as a string

language

str

r/w/en

Language for which features have been selected

level

Gtk.FontChooserLevel

r/w/en

Whether to select family, face or font

preview-text

str

r/w

The text to display in order to demonstrate the selected font

show-preview-entry

bool

r/w/en

Whether the preview text entry is shown or not

Signals

Name

Short Description

font-activated

Emitted when a font is activated.

Fields

None

Class Details

class Gtk.FontChooser
Bases:

GObject.GInterface

Structure:

Gtk.FontChooserIface

Gtk.FontChooser is an interface that can be implemented by widgets displaying the list of fonts. In GTK+, the main objects that implement this interface are Gtk.FontChooserWidget, Gtk.FontChooserDialog and Gtk.FontButton. The Gtk.FontChooser interface has been introducted in GTK+ 3.2.

get_font()[source]
Returns:

A string with the name of the current font, or None if no font is selected. You must free this string with GLib.free().

Return type:

str or None

Gets the currently-selected font name.

Note that this can be a different string than what you set with Gtk.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.

New in version 3.2.

get_font_desc()[source]
Returns:

A Pango.FontDescription for the current font, or None if no font is selected.

Return type:

Pango.FontDescription or None

Gets the currently-selected font.

Note that this can be a different string than what you set with Gtk.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.

New in version 3.2.

get_font_face()[source]
Returns:

A Pango.FontFace representing the selected font group details, or None. The returned object is owned by self and must not be modified or freed.

Return type:

Pango.FontFace or None

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

If the selected font is not installed, returns None.

New in version 3.2.

get_font_family()[source]
Returns:

A Pango.FontFamily representing the selected font family, or None. The returned object is owned by self and must not be modified or freed.

Return type:

Pango.FontFamily or None

Gets the Pango.FontFamily representing the selected font family. Font families are a collection of font faces.

If the selected font is not installed, returns None.

New in version 3.2.

get_font_features()[source]
Returns:

the currently selected font features

Return type:

str

Gets the currently-selected font features.

New in version 3.24.

get_font_map()[source]
Returns:

a Pango.FontMap, or None

Return type:

Pango.FontMap or None

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

New in version 3.18.

get_font_size()[source]
Returns:

A n integer representing the selected font size, or -1 if no font size is selected.

Return type:

int

The selected font size.

New in version 3.2.

get_language()[source]
Returns:

the currently selected language

Return type:

str

Gets the language that is used for font features.

New in version 3.24.

get_level()[source]
Returns:

the current granularity level

Return type:

Gtk.FontChooserLevel

Returns the current level of granularity for selecting fonts.

New in version 3.24.

get_preview_text()[source]
Returns:

the text displayed in the preview area

Return type:

str

Gets the text displayed in the preview area.

New in version 3.2.

get_show_preview_entry()[source]
Returns:

True if the preview entry is shown or False if it is hidden.

Return type:

bool

Returns whether the preview entry is shown or not.

New in version 3.2.

set_filter_func(filter, *user_data)[source]
Parameters:

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

New in version 3.2.

set_font(fontname)[source]
Parameters:

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

Sets the currently-selected font.

New in version 3.2.

set_font_desc(font_desc)[source]
Parameters:

font_desc (Pango.FontDescription) – a Pango.FontDescription

Sets the currently-selected font from font_desc.

New in version 3.2.

set_font_map(fontmap)[source]
Parameters:

fontmap (Pango.FontMap or None) – a Pango.FontMap

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

New in version 3.18.

set_language(language)[source]
Parameters:

language (str) – a language

Sets the language to use for font features.

New in version 3.24.

set_level(level)[source]
Parameters:

level (Gtk.FontChooserLevel) – the desired level of granularity

Sets the desired level of granularity for selecting fonts.

New in version 3.24.

set_preview_text(text)[source]
Parameters:

text (str) – the text to display in the preview area

Sets the text displayed in the preview area. The text is used to show how the selected font looks.

New in version 3.2.

set_show_preview_entry(show_preview_entry)[source]
Parameters:

show_preview_entry (bool) – whether to show the editable preview entry or not

Shows or hides the editable preview entry.

New in version 3.2.

do_font_activated(fontname) virtual
Parameters:

fontname (str) –

do_get_font_face() virtual
Returns:

A Pango.FontFace representing the selected font group details, or None. The returned object is owned by fontchooser and must not be modified or freed.

Return type:

Pango.FontFace or None

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

If the selected font is not installed, returns None.

New in version 3.2.

do_get_font_family() virtual
Returns:

A Pango.FontFamily representing the selected font family, or None. The returned object is owned by fontchooser and must not be modified or freed.

Return type:

Pango.FontFamily or None

Gets the Pango.FontFamily representing the selected font family. Font families are a collection of font faces.

If the selected font is not installed, returns None.

New in version 3.2.

do_get_font_map() virtual
Returns:

a Pango.FontMap, or None

Return type:

Pango.FontMap or None

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

New in version 3.18.

do_get_font_size() virtual
Returns:

A n integer representing the selected font size, or -1 if no font size is selected.

Return type:

int

The selected font size.

New in version 3.2.

do_set_filter_func(filter, *user_data) virtual
Parameters:

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

New in version 3.2.

do_set_font_map(fontmap) virtual
Parameters:

fontmap (Pango.FontMap or None) – a Pango.FontMap

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

New in version 3.18.

Signal Details

Gtk.FontChooser.signals.font_activated(font_chooser, fontname)
Signal Name:

font-activated

Flags:

RUN_FIRST

Parameters:
  • font_chooser (Gtk.FontChooser) – The object which received the signal

  • fontname (str) – the font name

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.

Property Details

Gtk.FontChooser.props.font
Name:

font

Type:

str

Default Value:

'Sans 10'

Flags:

READABLE, WRITABLE

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

Gtk.FontChooser.props.font_desc
Name:

font-desc

Type:

Pango.FontDescription

Default Value:

None

Flags:

READABLE, WRITABLE

The font description as a Pango.FontDescription.

Gtk.FontChooser.props.font_features
Name:

font-features

Type:

str

Default Value:

''

Flags:

READABLE

The selected font features, in a format that is compatible with CSS and with Pango attributes.

New in version 3.24.1.

Gtk.FontChooser.props.language
Name:

language

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The language for which the Gtk.FontChooser :font-features were selected, in a format that is compatible with CSS and with Pango attributes.

New in version 3.24.1.

Gtk.FontChooser.props.level
Name:

level

Type:

Gtk.FontChooserLevel

Default Value:

Gtk.FontChooserLevel.STYLE | Gtk.FontChooserLevel.SIZE

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The level of granularity to offer for selecting fonts.

New in version 3.24.1.

Gtk.FontChooser.props.preview_text
Name:

preview-text

Type:

str

Default Value:

'The quick brown fox jumps over the lazy dog.'

Flags:

READABLE, WRITABLE

The string with which to preview the font.

Gtk.FontChooser.props.show_preview_entry
Name:

show-preview-entry

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to show an entry to change the preview text.