Skip to content

Gtk.FontDialog

class — extends GObject.Object

Asynchronous API to present a font chooser dialog.

GtkFontDialog collects the arguments that are needed to present the dialog to the user, such as a title for the dialog and whether it should be modal.

The dialog is shown with the FontDialog.choose_font function or its variants.

See FontDialogButton for a convenient control that uses GtkFontDialog and presents the results.

Constructors

new

@classmethod
def new(cls) -> FontDialog

Creates a new GtkFontDialog object.

Methods

choose_face

def choose_face(self, parent: Window | None = ..., initial_value: Pango.FontFace | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Presents a font chooser dialog to the user.

The font chooser dialog will be set up for selecting a font face.

A font face represents a font family and style, but no specific font size.

Parameters:

  • parent — the parent window
  • initial_value — the initial value
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

choose_face_finish

def choose_face_finish(self, result: Gio.AsyncResult) -> Pango.FontFace

Finishes the FontDialog.choose_face call.

Note that this function returns a DialogError.DISMISSED error if the user cancels the dialog.

Parameters:

  • result — the result

choose_family

def choose_family(self, parent: Window | None = ..., initial_value: Pango.FontFamily | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Presents a font chooser dialog to the user.

The font chooser dialog will be set up for selecting a font family.

Parameters:

  • parent — the parent window
  • initial_value — the initial value
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

choose_family_finish

def choose_family_finish(self, result: Gio.AsyncResult) -> Pango.FontFamily

Finishes the FontDialog.choose_family call.

Note that this function returns a DialogError.DISMISSED error if the user cancels the dialog.

Parameters:

  • result — the result

choose_font

def choose_font(self, parent: Window | None = ..., initial_value: Pango.FontDescription | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Presents a font chooser dialog to the user.

The font chooser dialog will be set up for selecting a font.

If you want to let the user select font features as well, use FontDialog.choose_font_and_features instead.

Parameters:

  • parent — the parent window
  • initial_value — the font to select initially
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

choose_font_and_features

def choose_font_and_features(self, parent: Window | None = ..., initial_value: Pango.FontDescription | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Presents a font chooser dialog to the user.

The font chooser dialog will be set up for selecting a font and specify features for the selected font.

Font features affect how the font is rendered, for example enabling glyph variants or ligatures.

Parameters:

  • parent — the parent window
  • initial_value — the font to select initially
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

choose_font_and_features_finish

def choose_font_and_features_finish(self, result: Gio.AsyncResult) -> tuple[bool, Pango.FontDescription, str, Pango.Language]

Finishes the FontDialog.choose_font_and_features call.

The selected font and features are returned in font_desc and font_features.

Note that this function returns a DialogError.DISMISSED error if the user cancels the dialog.

Parameters:

  • result — the result

choose_font_finish

def choose_font_finish(self, result: Gio.AsyncResult) -> Pango.FontDescription

Finishes the FontDialog.choose_font call.

Note that this function returns a DialogError.DISMISSED error if the user cancels the dialog.

Parameters:

  • result — the result

get_filter

def get_filter(self) -> Filter | None

Returns the filter that decides which fonts to display in the font chooser dialog.

get_font_map

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

Returns the fontmap from which fonts are selected, or NULL for the default fontmap.

get_language

def get_language(self) -> Pango.Language | None

Returns the language for which font features are applied.

get_modal

def get_modal(self) -> bool

Returns whether the font chooser dialog blocks interaction with the parent window while it is presented.

get_title

def get_title(self) -> str

Returns the title that will be shown on the font chooser dialog.

set_filter

def set_filter(self, filter: Filter | None = ...) -> None

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

The filter must be able to handle both PangoFontFamily and PangoFontFace objects.

Parameters:

  • filter — the filter

set_font_map

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

Sets the fontmap from which fonts are selected.

If fontmap is NULL, the default fontmap is used.

Parameters:

  • fontmap — the fontmap

set_language

def set_language(self, language: Pango.Language) -> None

Sets the language for which font features are applied.

Parameters:

  • language — the language for font features

set_modal

def set_modal(self, modal: bool) -> None

Sets whether the font chooser dialog blocks interaction with the parent window while it is presented.

Parameters:

  • modal — the new value

set_title

def set_title(self, title: str) -> None

Sets the title that will be shown on the font chooser dialog.

Parameters:

  • title — the new title

Properties

filter

filter: Filter  # read/write

A filter to restrict what fonts are shown in the font chooser dialog.

font_map

font_map: Pango.FontMap  # read/write

A custom font map to select fonts from.

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

language

language: Pango.Language  # read/write

The language for which the font features are selected.

modal

modal: bool  # read/write

Whether the font chooser dialog is modal.

title

title: str  # read/write

A title that may be shown on the font chooser dialog that is presented by FontDialog.choose_font.