Skip to content

Gtk.PaperSize

record (struct)

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

new

@classmethod
def new(cls, name: str | 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 PaperSize.get_default.

Parameters:

  • name — a paper size name

new_custom

@classmethod
def new_custom(cls, name: str, display_name: str, width: float, height: float, unit: Unit | int) -> 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 Unit.NONE.

new_from_gvariant

@classmethod
def new_from_gvariant(cls, variant: GLib.Variant) -> PaperSize

Deserialize a paper size from a GVariant.

The GVariant must be in the format produced by [PaperSize.to_gvariant`](./PaperSize.md#method-to_gvariant).

Parameters:

  • variant — an a{sv} GVariant

new_from_ipp

@classmethod
def new_from_ipp(cls, 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

new_from_key_file

@classmethod
def new_from_key_file(cls, key_file: GLib.KeyFile, group_name: str | 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

new_from_ppd

@classmethod
def new_from_ppd(cls, 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

copy

def copy(self) -> PaperSize

Copies an existing GtkPaperSize.

free

def free(self) -> None

Free the given GtkPaperSize object.

get_default_bottom_margin

def get_default_bottom_margin(self, unit: Unit | int) -> float

Gets the default bottom margin for the GtkPaperSize.

Parameters:

  • unit — the unit for the return value, not Unit.NONE

get_default_left_margin

def get_default_left_margin(self, unit: Unit | int) -> float

Gets the default left margin for the GtkPaperSize.

Parameters:

  • unit — the unit for the return value, not Unit.NONE

get_default_right_margin

def get_default_right_margin(self, unit: Unit | int) -> float

Gets the default right margin for the GtkPaperSize.

Parameters:

  • unit — the unit for the return value, not Unit.NONE

get_default_top_margin

def get_default_top_margin(self, unit: Unit | int) -> float

Gets the default top margin for the GtkPaperSize.

Parameters:

  • unit — the unit for the return value, not Unit.NONE

get_display_name

def get_display_name(self) -> str

Gets the human-readable name of the GtkPaperSize.

get_height

def get_height(self, unit: Unit | int) -> float

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

Parameters:

  • unit — the unit for the return value, not Unit.NONE

get_name

def get_name(self) -> str

Gets the name of the GtkPaperSize.

get_ppd_name

def get_ppd_name(self) -> str

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

get_width

def get_width(self, unit: Unit | int) -> float

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

Parameters:

  • unit — the unit for the return value, not Unit.NONE

is_custom

def is_custom(self) -> bool

Returns True if size is not a standard paper size.

is_equal

def is_equal(self, size2: PaperSize) -> bool

Compares two GtkPaperSize objects.

Parameters:

  • size2 — another GtkPaperSize object

is_ipp

def is_ipp(self) -> bool

Returns True if size is an IPP standard paper size.

set_size

def set_size(self, width: float, height: float, unit: Unit | int) -> 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

def to_gvariant(self) -> GLib.Variant

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

to_key_file

def to_key_file(self, key_file: GLib.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

Static functions

get_default

@staticmethod
def get_default() -> str

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

get_paper_sizes

@staticmethod
def 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