Skip to content

Gtk.Printer

class — extends GObject.Object

Represents a printer.

You only need to deal directly with printers if you use the non-portable PrintUnixDialog API.

A GtkPrinter allows to get status information about the printer, such as its description, its location, the number of queued jobs, etc. Most importantly, a GtkPrinter object can be used to create a PrintJob object, which lets you print to the printer.

Constructors

new

@classmethod
def new(cls, name: str, backend: PrintBackend, virtual_: bool) -> Printer

Creates a new GtkPrinter.

Parameters:

  • name — the name of the printer
  • backend — a GtkPrintBackend
  • virtual_ — whether the printer is virtual

Methods

accepts_pdf

def accepts_pdf(self) -> bool

Returns whether the printer accepts input in PDF format.

accepts_ps

def accepts_ps(self) -> bool

Returns whether the printer accepts input in PostScript format.

compare

def compare(self, b: Printer) -> int

Compares two printers.

Parameters:

  • b — another GtkPrinter

get_backend

def get_backend(self) -> PrintBackend

Returns the backend of the printer.

get_capabilities

def get_capabilities(self) -> PrintCapabilities

Returns the printer’s capabilities.

This is useful when you’re using GtkPrintUnixDialog’s manual-capabilities setting and need to know which settings the printer can handle and which you must handle yourself.

This will return 0 unless the printer’s details are available, see Printer.has_details and Printer.request_details.

get_default_page_size

def get_default_page_size(self) -> PageSetup

Returns default page size of printer.

get_description

def get_description(self) -> str

Gets the description of the printer.

get_hard_margins

def get_hard_margins(self) -> tuple[bool, float, float, float, float]

Retrieve the hard margins of printer.

These are the margins that define the area at the borders of the paper that the printer cannot print to.

Note: This will not succeed unless the printer’s details are available, see Printer.has_details and Printer.request_details.

get_hard_margins_for_paper_size

def get_hard_margins_for_paper_size(self, paper_size: PaperSize) -> tuple[bool, float, float, float, float]

Retrieve the hard margins of printer for paper_size.

These are the margins that define the area at the borders of the paper that the printer cannot print to.

Note: This will not succeed unless the printer’s details are available, see Printer.has_details and Printer.request_details.

Parameters:

  • paper_size — a GtkPaperSize

get_icon_name

def get_icon_name(self) -> str

Gets the name of the icon to use for the printer.

get_job_count

def get_job_count(self) -> int

Gets the number of jobs currently queued on the printer.

get_location

def get_location(self) -> str

Returns a description of the location of the printer.

get_name

def get_name(self) -> str

Returns the name of the printer.

get_state_message

def get_state_message(self) -> str

Returns the state message describing the current state of the printer.

has_details

def has_details(self) -> bool

Returns whether the printer details are available.

is_accepting_jobs

def is_accepting_jobs(self) -> bool

Returns whether the printer is accepting jobs

is_active

def is_active(self) -> bool

Returns whether the printer is currently active (i.e. accepts new jobs).

is_default

def is_default(self) -> bool

Returns whether the printer is the default printer.

is_paused

def is_paused(self) -> bool

Returns whether the printer is currently paused.

A paused printer still accepts jobs, but it is not printing them.

is_virtual

def is_virtual(self) -> bool

Returns whether the printer is virtual (i.e. does not represent actual printer hardware, but something like a CUPS class).

list_papers

def list_papers(self) -> list[PageSetup]

Lists all the paper sizes printer supports.

This will return and empty list unless the printer’s details are available, see Printer.has_details and Printer.request_details.

request_details

def request_details(self) -> None

Requests the printer details.

When the details are available, the Printer.details-acquired signal will be emitted on printer.

Properties

accepting_jobs

accepting_jobs: bool  # read-only

True if the printer is accepting jobs.

accepts_pdf

accepts_pdf: bool  # read/write

True if this printer can accept PDF.

accepts_ps

accepts_ps: bool  # read/write

True if this printer can accept PostScript.

icon_name

icon_name: str  # read-only

Icon name to use for the printer.

is_virtual

is_virtual: bool  # read/write

False if this represents a real hardware device.

job_count

job_count: int  # read-only

Number of jobs queued in the printer.

location

location: str  # read-only

Information about the location of the printer.

name

name: str  # read/write

The name of the printer.

paused

paused: bool  # read-only

True if this printer is paused.

A paused printer still accepts jobs, but it does not print them.

state_message

state_message: str  # read-only

String giving the current status of the printer.

Signals

details-acquired

def on_details_acquired(self, success: bool) -> None: ...

Emitted in response to a request for detailed information about a printer from the print backend.

The success parameter indicates if the information was actually obtained.