PaperSize

class PaperSize(**kwargs)

GtkPaperSize handles paper sizes.

It uses the standard called PWG 5101.1-2002 PWG: Standard for Media Standardized Names to name the paper sizes (and to get the data for the page sizes). In addition to standard paper sizes, GtkPaperSize allows to construct custom paper sizes with arbitrary dimensions.

The GtkPaperSize object stores not only the dimensions (width and height) of a paper size and its name, it also provides default print margins.

Constructors

class PaperSize
classmethod new(name: str | None = None) PaperSize

Creates a new GtkPaperSize object by parsing a PWG 5101.1-2002 paper name.

If name is None, the default paper size is returned, see get_default.

Parameters:

name – a paper size name

classmethod new_custom(name: str, display_name: str, width: float, height: float, unit: Unit) PaperSize

Creates a new GtkPaperSize object with the given parameters.

Parameters:
  • name – the paper name

  • display_name – the human-readable name

  • width – the paper width, in units of unit

  • height – the paper height, in units of unit

  • unit – the unit for width and height. not NONE.

classmethod new_from_gvariant(variant: Variant) PaperSize

Deserialize a paper size from a GVariant.

The GVariant must be in the format produced by :obj:`~gi.repository.Gtk.PaperSize.to_gvariant.

Parameters:

variant – an a{sv} GVariant

classmethod new_from_ipp(ipp_name: str, width: float, height: float) PaperSize

Creates a new GtkPaperSize object by using IPP information.

If ipp_name is not a recognized paper name, width and height are used to construct a custom GtkPaperSize object.

Parameters:
  • ipp_name – an IPP paper name

  • width – the paper width, in points

  • height – the paper height in points

classmethod new_from_key_file(key_file: KeyFile, group_name: str | None = None) PaperSize

Reads a paper size from the group group_name in the key file key_file.

Parameters:
  • key_file – the GKeyFile to retrieve the papersize from

  • group_name – the name of the group in the key file to read, or None to read the first group

classmethod new_from_ppd(ppd_name: str, ppd_display_name: str, width: float, height: float) PaperSize

Creates a new GtkPaperSize object by using PPD information.

If ppd_name is not a recognized PPD paper name, ppd_display_name, width and height are used to construct a custom GtkPaperSize object.

Parameters:
  • ppd_name – a PPD paper name

  • ppd_display_name – the corresponding human-readable name

  • width – the paper width, in points

  • height – the paper height in points

Methods

class PaperSize
free() None

Free the given GtkPaperSize object.

get_default() str

Returns the name of the default paper size, which depends on the current locale.

get_default_bottom_margin(unit: Unit) float

Gets the default bottom margin for the GtkPaperSize.

Parameters:

unit – the unit for the return value, not NONE

get_default_left_margin(unit: Unit) float

Gets the default left margin for the GtkPaperSize.

Parameters:

unit – the unit for the return value, not NONE

get_default_right_margin(unit: Unit) float

Gets the default right margin for the GtkPaperSize.

Parameters:

unit – the unit for the return value, not NONE

get_default_top_margin(unit: Unit) float

Gets the default top margin for the GtkPaperSize.

Parameters:

unit – the unit for the return value, not NONE

get_display_name() str

Gets the human-readable name of the GtkPaperSize.

get_height(unit: Unit) float

Gets the paper height of the GtkPaperSize, in units of unit.

Parameters:

unit – the unit for the return value, not NONE

get_name() str

Gets the name of the GtkPaperSize.

get_paper_sizes(include_custom: bool) list[PaperSize]

Creates a list of known paper sizes.

Parameters:

include_custom – whether to include custom paper sizes as defined in the page setup dialog

get_ppd_name() str

Gets the PPD name of the GtkPaperSize, which may be None.

get_width(unit: Unit) float

Gets the paper width of the GtkPaperSize, in units of unit.

Parameters:

unit – the unit for the return value, not NONE

is_custom() bool

Returns True if size is not a standard paper size.

is_equal(size2: PaperSize) bool

Compares two GtkPaperSize objects.

Parameters:

size2 – another GtkPaperSize object

is_ipp() bool

Returns True if size is an IPP standard paper size.

set_size(width: float, height: float, unit: Unit) None

Changes the dimensions of a size to width x height.

Parameters:
  • width – the new width in units of unit

  • height – the new height in units of unit

  • unit – the unit for width and height

to_gvariant() Variant

Serialize a paper size to an a{sv} variant.

to_key_file(key_file: KeyFile, group_name: str) None

This function adds the paper size from size to key_file.

Parameters:
  • key_file – the GKeyFile to save the paper size to

  • group_name – the group to add the settings to in key_file