PrintSettings

class PrintSettings(**properties: Any)

Superclasses: Object

A GtkPrintSettings object represents 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

class PrintSettings
classmethod new() PrintSettings

Creates a new GtkPrintSettings object.

classmethod new_from_file(file_name: str) 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 to_file.

Parameters:

file_name – the filename to read the settings from

classmethod new_from_gvariant(variant: Variant) PrintSettings

Deserialize print settings from an a{sv} variant.

The variant must be in the format produced by to_gvariant.

Parameters:

variant – an a{sv} GVariant

classmethod new_from_key_file(key_file: KeyFile, group_name: str | None = 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

class PrintSettings
foreach(func: Callable[[...], None], *user_data: Any) None

Calls func for each key-value pair of settings.

Parameters:
  • func – the function to call

  • user_data – user data for func

get(key: str) str | None

Looks up the string value associated with key.

Parameters:

key – a key

get_bool(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() bool

Gets the value of PRINT_SETTINGS_COLLATE.

get_default_source() str | None

Gets the value of PRINT_SETTINGS_DEFAULT_SOURCE.

get_dither() str | None

Gets the value of PRINT_SETTINGS_DITHER.

get_double(key: str) float

Returns the double value associated with key, or 0.

Parameters:

key – a key

get_double_with_default(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 ascii_strtod().

Parameters:
  • key – a key

  • def

get_duplex() PrintDuplex

Gets the value of PRINT_SETTINGS_DUPLEX.

get_finishings() str | None

Gets the value of PRINT_SETTINGS_FINISHINGS.

get_int(key: str) int

Returns the integer value of key, or 0.

Parameters:

key – a key

get_int_with_default(key: str, def_: int) int

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

Parameters:
  • key – a key

  • def

get_length(key: str, unit: Unit) 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() 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() int

Gets the value of PRINT_SETTINGS_N_COPIES.

get_number_up() int

Gets the value of PRINT_SETTINGS_NUMBER_UP.

get_number_up_layout() NumberUpLayout

Gets the value of PRINT_SETTINGS_NUMBER_UP_LAYOUT.

get_orientation() PageOrientation

Get the value of PRINT_SETTINGS_ORIENTATION, converted to a GtkPageOrientation.

get_output_bin() str | None

Gets the value of PRINT_SETTINGS_OUTPUT_BIN.

get_page_ranges() list[PageRange]

Gets the value of PRINT_SETTINGS_PAGE_RANGES.

get_page_set() PageSet

Gets the value of PRINT_SETTINGS_PAGE_SET.

get_paper_height(unit: Unit) float

Gets the value of PRINT_SETTINGS_PAPER_HEIGHT, converted to unit.

Parameters:

unit – the unit for the return value

get_paper_size() PaperSize | None

Gets the value of PRINT_SETTINGS_PAPER_FORMAT, converted to a GtkPaperSize.

get_paper_width(unit: Unit) float

Gets the value of PRINT_SETTINGS_PAPER_WIDTH, converted to unit.

Parameters:

unit – the unit for the return value

get_print_pages() PrintPages

Gets the value of PRINT_SETTINGS_PRINT_PAGES.

get_printer() str | None

Convenience function to obtain the value of PRINT_SETTINGS_PRINTER.

get_printer_lpi() float

Gets the value of PRINT_SETTINGS_PRINTER_LPI.

get_quality() PrintQuality

Gets the value of PRINT_SETTINGS_QUALITY.

get_resolution() int

Gets the value of PRINT_SETTINGS_RESOLUTION.

get_resolution_x() int

Gets the value of PRINT_SETTINGS_RESOLUTION_X.

get_resolution_y() int

Gets the value of PRINT_SETTINGS_RESOLUTION_Y.

get_reverse() bool

Gets the value of PRINT_SETTINGS_REVERSE.

get_scale() float

Gets the value of PRINT_SETTINGS_SCALE.

get_use_color() bool

Gets the value of PRINT_SETTINGS_USE_COLOR.

has_key(key: str) bool

Returns True, if a value is associated with key.

Parameters:

key – a key

load_file(file_name: str) 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 to_file.

Parameters:

file_name – the filename to read the settings from

load_key_file(key_file: KeyFile, group_name: str | None = 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(key: str, value: str | None = None) None

Associates value with key.

Parameters:
  • key – a key

  • value – a string value

set_bool(key: str, value: bool) None

Sets key to a boolean value.

Parameters:
  • key – a key

  • value – a boolean

set_collate(collate: bool) None

Sets the value of PRINT_SETTINGS_COLLATE.

Parameters:

collate – whether to collate the output

set_default_source(default_source: str) None

Sets the value of PRINT_SETTINGS_DEFAULT_SOURCE.

Parameters:

default_source – the default source

set_dither(dither: str) None

Sets the value of PRINT_SETTINGS_DITHER.

Parameters:

dither – the dithering that is used

set_double(key: str, value: float) None

Sets key to a double value.

Parameters:
  • key – a key

  • value – a double value

set_duplex(duplex: PrintDuplex) None

Sets the value of PRINT_SETTINGS_DUPLEX.

Parameters:

duplex – a GtkPrintDuplex value

set_finishings(finishings: str) None

Sets the value of PRINT_SETTINGS_FINISHINGS.

Parameters:

finishings – the finishings

set_int(key: str, value: int) None

Sets key to an integer value.

Parameters:
  • key – a key

  • value – an integer

set_length(key: str, value: float, unit: Unit) 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(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(num_copies: int) None

Sets the value of PRINT_SETTINGS_N_COPIES.

Parameters:

num_copies – the number of copies

set_number_up(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(number_up_layout: NumberUpLayout) None

Sets the value of PRINT_SETTINGS_NUMBER_UP_LAYOUT.

Parameters:

number_up_layout – a GtkNumberUpLayout value

set_orientation(orientation: PageOrientation) None

Sets the value of PRINT_SETTINGS_ORIENTATION.

Parameters:

orientation – a page orientation

set_output_bin(output_bin: str) None

Sets the value of PRINT_SETTINGS_OUTPUT_BIN.

Parameters:

output_bin – the output bin

set_page_ranges(page_ranges: Sequence[PageRange]) None

Sets the value of PRINT_SETTINGS_PAGE_RANGES.

Parameters:

page_ranges – an array of GtkPageRange’s

set_page_set(page_set: PageSet) None

Sets the value of PRINT_SETTINGS_PAGE_SET.

Parameters:

page_set – a GtkPageSet value

set_paper_height(height: float, unit: Unit) None

Sets the value of PRINT_SETTINGS_PAPER_HEIGHT.

Parameters:
  • height – the paper height

  • unit – the units of height

set_paper_size(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(width: float, unit: Unit) None

Sets the value of PRINT_SETTINGS_PAPER_WIDTH.

Parameters:
  • width – the paper width

  • unit – the units of width

set_print_pages(pages: PrintPages) None

Sets the value of PRINT_SETTINGS_PRINT_PAGES.

Parameters:

pages – a GtkPrintPages value

set_printer(printer: str) None

Convenience function to set PRINT_SETTINGS_PRINTER to printer.

Parameters:

printer – the printer name

set_printer_lpi(lpi: float) None

Sets the value of PRINT_SETTINGS_PRINTER_LPI.

Parameters:

lpi – the resolution in lpi (lines per inch)

set_quality(quality: PrintQuality) None

Sets the value of PRINT_SETTINGS_QUALITY.

Parameters:

quality – a GtkPrintQuality value

set_resolution(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(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(reverse: bool) None

Sets the value of PRINT_SETTINGS_REVERSE.

Parameters:

reverse – whether to reverse the output

set_scale(scale: float) None

Sets the value of PRINT_SETTINGS_SCALE.

Parameters:

scale – the scale in percent

set_use_color(use_color: bool) None

Sets the value of PRINT_SETTINGS_USE_COLOR.

Parameters:

use_color – whether to use color

to_file(file_name: str) 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() Variant

Serialize print settings to an a{sv} variant.

to_key_file(key_file: KeyFile, group_name: str | None = 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(key: str) None

Removes any value associated with key.

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

Parameters:

key – a key