Skip to content

Gtk.PrintSettings

class — extends GObject.Object

Collects the settings of a print dialog in a system-independent way.

The main use for this object is that once you’ve printed you can get a settings object that represents the settings the user chose, and the next time you print you can pass that object in so that the user doesn’t have to re-set all his settings.

Its also possible to enumerate the settings so that you can easily save the settings for the next time your app runs, or even store them in a document. The predefined keys try to use shared values as much as possible so that moving such a document between systems still works.

Constructors

new

@classmethod
def new(cls) -> PrintSettings

Creates a new GtkPrintSettings object.

new_from_file

@classmethod
def new_from_file(cls, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> PrintSettings

Reads the print settings from file_name.

Returns a new GtkPrintSettings object with the restored settings, or None if an error occurred. If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

See PrintSettings.to_file.

Parameters:

  • file_name — the filename to read the settings from

new_from_gvariant

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

Deserialize print settings from an a{sv} variant.

The variant must be in the format produced by PrintSettings.to_gvariant.

Parameters:

  • variant — an a{sv} GVariant

new_from_key_file

@classmethod
def new_from_key_file(cls, key_file: GLib.KeyFile, group_name: str | None = ...) -> PrintSettings

Reads the print settings from the group group_name in key_file.

Returns a new GtkPrintSettings object with the restored settings, or None if an error occurred. If the file could not be loaded then error is set to either GFileError or GKeyFileError.

Parameters:

  • key_file — the GKeyFile to retrieve the settings from
  • group_name — the name of the group to use, or None to use the default “Print Settings”

Methods

copy

def copy(self) -> PrintSettings

Copies a GtkPrintSettings object.

foreach

def foreach(self, func: PrintSettingsFunc) -> None

Calls func for each key-value pair of settings.

Parameters:

  • func — the function to call

get

def get(self, key: str) -> str | None

Looks up the string value associated with key.

Parameters:

  • key — a key

get_bool

def get_bool(self, key: str) -> bool

Returns the boolean represented by the value that is associated with key.

The string “true” represents True, any other string False.

Parameters:

  • key — a key

get_collate

def get_collate(self) -> bool

Gets the value of PRINT_SETTINGS_COLLATE.

get_default_source

def get_default_source(self) -> str | None

Gets the value of PRINT_SETTINGS_DEFAULT_SOURCE.

get_dither

def get_dither(self) -> str | None

Gets the value of PRINT_SETTINGS_DITHER.

get_double

def get_double(self, key: str) -> float

Returns the double value associated with key, or 0.

Parameters:

  • key — a key

get_double_with_default

def get_double_with_default(self, key: str, def_: float) -> float

Returns the floating point number represented by the value that is associated with key, or default_val if the value does not represent a floating point number.

Floating point numbers are parsed with GLib.ascii_strtod.

Parameters:

  • key — a key
  • def_ — the default value

get_duplex

def get_duplex(self) -> PrintDuplex

Gets the value of PRINT_SETTINGS_DUPLEX.

get_finishings

def get_finishings(self) -> str | None

Gets the value of PRINT_SETTINGS_FINISHINGS.

get_int

def get_int(self, key: str) -> int

Returns the integer value of key, or 0.

Parameters:

  • key — a key

get_int_with_default

def get_int_with_default(self, key: str, def_: int) -> int

Returns the value of key, interpreted as an integer, or the default value.

Parameters:

  • key — a key
  • def_ — the default value

get_length

def get_length(self, key: str, unit: Unit | int) -> float

Returns the value associated with key, interpreted as a length.

The returned value is converted to units.

Parameters:

  • key — a key
  • unit — the unit of the return value

get_media_type

def get_media_type(self) -> str | None

Gets the value of PRINT_SETTINGS_MEDIA_TYPE.

The set of media types is defined in PWG 5101.1-2002 PWG.

get_n_copies

def get_n_copies(self) -> int

Gets the value of PRINT_SETTINGS_N_COPIES.

get_number_up

def get_number_up(self) -> int

Gets the value of PRINT_SETTINGS_NUMBER_UP.

get_number_up_layout

def get_number_up_layout(self) -> NumberUpLayout

Gets the value of PRINT_SETTINGS_NUMBER_UP_LAYOUT.

get_orientation

def get_orientation(self) -> PageOrientation

Get the value of PRINT_SETTINGS_ORIENTATION, converted to a GtkPageOrientation.

get_output_bin

def get_output_bin(self) -> str | None

Gets the value of PRINT_SETTINGS_OUTPUT_BIN.

get_page_ranges

def get_page_ranges(self) -> list[PageRange]

Gets the value of PRINT_SETTINGS_PAGE_RANGES.

get_page_set

def get_page_set(self) -> PageSet

Gets the value of PRINT_SETTINGS_PAGE_SET.

get_paper_height

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

Gets the value of PRINT_SETTINGS_PAPER_HEIGHT, converted to unit.

Parameters:

  • unit — the unit for the return value

get_paper_size

def get_paper_size(self) -> PaperSize | None

Gets the value of PRINT_SETTINGS_PAPER_FORMAT, converted to a GtkPaperSize.

get_paper_width

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

Gets the value of PRINT_SETTINGS_PAPER_WIDTH, converted to unit.

Parameters:

  • unit — the unit for the return value

get_print_pages

def get_print_pages(self) -> PrintPages

Gets the value of PRINT_SETTINGS_PRINT_PAGES.

get_printer

def get_printer(self) -> str | None

Convenience function to obtain the value of PRINT_SETTINGS_PRINTER.

get_printer_lpi

def get_printer_lpi(self) -> float

Gets the value of PRINT_SETTINGS_PRINTER_LPI.

get_quality

def get_quality(self) -> PrintQuality

Gets the value of PRINT_SETTINGS_QUALITY.

get_resolution

def get_resolution(self) -> int

Gets the value of PRINT_SETTINGS_RESOLUTION.

get_resolution_x

def get_resolution_x(self) -> int

Gets the value of PRINT_SETTINGS_RESOLUTION_X.

get_resolution_y

def get_resolution_y(self) -> int

Gets the value of PRINT_SETTINGS_RESOLUTION_Y.

get_reverse

def get_reverse(self) -> bool

Gets the value of PRINT_SETTINGS_REVERSE.

get_scale

def get_scale(self) -> float

Gets the value of PRINT_SETTINGS_SCALE.

get_use_color

def get_use_color(self) -> bool

Gets the value of PRINT_SETTINGS_USE_COLOR.

has_key

def has_key(self, key: str) -> bool

Returns True, if a value is associated with key.

Parameters:

  • key — a key

load_file

def load_file(self, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

Reads the print settings from file_name.

If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

See PrintSettings.to_file.

Parameters:

  • file_name — the filename to read the settings from

load_key_file

def load_key_file(self, key_file: GLib.KeyFile, group_name: str | None = ...) -> bool

Reads the print settings from the group group_name in key_file.

If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

Parameters:

  • key_file — the GKeyFile to retrieve the settings from
  • group_name — the name of the group to use, or None to use the default “Print Settings”

set

def set(self, key: str, value: str | None = ...) -> None

Associates value with key.

Parameters:

  • key — a key
  • value — a string value

set_bool

def set_bool(self, key: str, value: bool) -> None

Sets key to a boolean value.

Parameters:

  • key — a key
  • value — a boolean

set_collate

def set_collate(self, collate: bool) -> None

Sets the value of PRINT_SETTINGS_COLLATE.

Parameters:

  • collate — whether to collate the output

set_default_source

def set_default_source(self, default_source: str) -> None

Sets the value of PRINT_SETTINGS_DEFAULT_SOURCE.

Parameters:

  • default_source — the default source

set_dither

def set_dither(self, dither: str) -> None

Sets the value of PRINT_SETTINGS_DITHER.

Parameters:

  • dither — the dithering that is used

set_double

def set_double(self, key: str, value: float) -> None

Sets key to a double value.

Parameters:

  • key — a key
  • value — a double value

set_duplex

def set_duplex(self, duplex: PrintDuplex | int) -> None

Sets the value of PRINT_SETTINGS_DUPLEX.

Parameters:

  • duplex — a GtkPrintDuplex value

set_finishings

def set_finishings(self, finishings: str) -> None

Sets the value of PRINT_SETTINGS_FINISHINGS.

Parameters:

  • finishings — the finishings

set_int

def set_int(self, key: str, value: int) -> None

Sets key to an integer value.

Parameters:

  • key — a key
  • value — an integer

set_length

def set_length(self, key: str, value: float, unit: Unit | int) -> None

Associates a length in units of unit with key.

Parameters:

  • key — a key
  • value — a length
  • unit — the unit of length

set_media_type

def set_media_type(self, media_type: str) -> None

Sets the value of PRINT_SETTINGS_MEDIA_TYPE.

The set of media types is defined in PWG 5101.1-2002 PWG.

Parameters:

  • media_type — the media type

set_n_copies

def set_n_copies(self, num_copies: int) -> None

Sets the value of PRINT_SETTINGS_N_COPIES.

Parameters:

  • num_copies — the number of copies

set_number_up

def set_number_up(self, number_up: int) -> None

Sets the value of PRINT_SETTINGS_NUMBER_UP.

Parameters:

  • number_up — the number of pages per sheet

set_number_up_layout

def set_number_up_layout(self, number_up_layout: NumberUpLayout | int) -> None

Sets the value of PRINT_SETTINGS_NUMBER_UP_LAYOUT.

Parameters:

  • number_up_layout — a GtkNumberUpLayout value

set_orientation

def set_orientation(self, orientation: PageOrientation | int) -> None

Sets the value of PRINT_SETTINGS_ORIENTATION.

Parameters:

  • orientation — a page orientation

set_output_bin

def set_output_bin(self, output_bin: str) -> None

Sets the value of PRINT_SETTINGS_OUTPUT_BIN.

Parameters:

  • output_bin — the output bin

set_page_ranges

def set_page_ranges(self, page_ranges: list[PageRange]) -> None

Sets the value of PRINT_SETTINGS_PAGE_RANGES.

Parameters:

  • page_ranges — an array of GtkPageRanges

set_page_set

def set_page_set(self, page_set: PageSet | int) -> None

Sets the value of PRINT_SETTINGS_PAGE_SET.

Parameters:

  • page_set — a GtkPageSet value

set_paper_height

def set_paper_height(self, height: float, unit: Unit | int) -> None

Sets the value of PRINT_SETTINGS_PAPER_HEIGHT.

Parameters:

  • height — the paper height
  • unit — the units of height

set_paper_size

def set_paper_size(self, paper_size: PaperSize) -> None

Sets the value of PRINT_SETTINGS_PAPER_FORMAT, PRINT_SETTINGS_PAPER_WIDTH and PRINT_SETTINGS_PAPER_HEIGHT.

Parameters:

  • paper_size — a paper size

set_paper_width

def set_paper_width(self, width: float, unit: Unit | int) -> None

Sets the value of PRINT_SETTINGS_PAPER_WIDTH.

Parameters:

  • width — the paper width
  • unit — the units of width

set_print_pages

def set_print_pages(self, pages: PrintPages | int) -> None

Sets the value of PRINT_SETTINGS_PRINT_PAGES.

Parameters:

  • pages — a GtkPrintPages value

set_printer

def set_printer(self, printer: str) -> None

Convenience function to set PRINT_SETTINGS_PRINTER to printer.

Parameters:

  • printer — the printer name

set_printer_lpi

def set_printer_lpi(self, lpi: float) -> None

Sets the value of PRINT_SETTINGS_PRINTER_LPI.

Parameters:

  • lpi — the resolution in lpi (lines per inch)

set_quality

def set_quality(self, quality: PrintQuality | int) -> None

Sets the value of PRINT_SETTINGS_QUALITY.

Parameters:

  • quality — a GtkPrintQuality value

set_resolution

def set_resolution(self, resolution: int) -> None

Sets the values of PRINT_SETTINGS_RESOLUTION, PRINT_SETTINGS_RESOLUTION_X and PRINT_SETTINGS_RESOLUTION_Y.

Parameters:

  • resolution — the resolution in dpi

set_resolution_xy

def set_resolution_xy(self, resolution_x: int, resolution_y: int) -> None

Sets the values of PRINT_SETTINGS_RESOLUTION, PRINT_SETTINGS_RESOLUTION_X and PRINT_SETTINGS_RESOLUTION_Y.

Parameters:

  • resolution_x — the horizontal resolution in dpi
  • resolution_y — the vertical resolution in dpi

set_reverse

def set_reverse(self, reverse: bool) -> None

Sets the value of PRINT_SETTINGS_REVERSE.

Parameters:

  • reverse — whether to reverse the output

set_scale

def set_scale(self, scale: float) -> None

Sets the value of PRINT_SETTINGS_SCALE.

Parameters:

  • scale — the scale in percent

set_use_color

def set_use_color(self, use_color: bool) -> None

Sets the value of PRINT_SETTINGS_USE_COLOR.

Parameters:

  • use_color — whether to use color

to_file

def to_file(self, file_name: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -> bool

This function saves the print settings from settings to file_name.

If the file could not be written then error is set to either a GFileError or GKeyFileError.

Parameters:

  • file_name — the file to save to

to_gvariant

def to_gvariant(self) -> GLib.Variant

Serialize print settings to an a{sv} variant.

to_key_file

def to_key_file(self, key_file: GLib.KeyFile, group_name: str | None = ...) -> None

This function adds the print settings from settings to key_file.

Parameters:

  • key_file — the GKeyFile to save the print settings to
  • group_name — the group to add the settings to in key_file, or None to use the default “Print Settings”

unset

def unset(self, key: str) -> None

Removes any value associated with key.

This has the same effect as setting the value to None.

Parameters:

  • key — a key