PrintDialog

Added in version 4.14.

class PrintDialog(**properties: Any)

Superclasses: Object

A GtkPrintDialog object collects the arguments that are needed to present a print dialog to the user, such as a title for the dialog and whether it should be modal.

The dialog is shown with the setup function. The actual printing can be done with print or print_file. These APIs follows the GIO async pattern, and the results can be obtained by calling the corresponding finish methods.

Constructors

class PrintDialog
classmethod new() PrintDialog

Creates a new GtkPrintDialog object.

Added in version 4.14.

Methods

class PrintDialog
get_accept_label() str

Returns the label that will be shown on the accept button of the print dialog.

Added in version 4.14.

get_modal() bool

Returns whether the print dialog blocks interaction with the parent window while it is presented.

Added in version 4.14.

get_page_setup() PageSetup

Returns the page setup.

Added in version 4.14.

get_print_settings() PrintSettings

Returns the print settings for the print dialog.

Added in version 4.14.

get_title() str

Returns the title that will be shown on the print dialog.

Added in version 4.14.

print_(parent: Window | None = None, setup: PrintSetup | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
Parameters:
  • parent

  • setup

  • cancellable

  • callback

  • user_data

print_file(parent: Window | None, setup: PrintSetup | None, file: File, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

This function prints a file.

If you pass NULL as setup, then this method will present a print dialog. Otherwise, it will attempt to print directly, without user interaction.

The callback will be called when the printing is done. It should call print_file_finish to obtain the results.

Added in version 4.14.

Parameters:
  • parent – the parent GtkWindow

  • setup – the GtkPrintSetup to use

  • file – the GFile to print

  • cancellable – a GCancellable to cancel the operation

  • callback – a callback to call when the operation is complete

  • user_data – data to pass to callback

print_file_finish(result: AsyncResult) bool

Finishes the print_file call and returns the results.

Added in version 4.14.

Parameters:

result – a GAsyncResult

print_finish(result: AsyncResult) OutputStream | None

Finishes the print call and returns the results.

If the call was successful, the content to be printed should be written to the returned output stream. Otherwise, NULL is returned.

The overall results of the print operation will be returned in the close call, so if you are interested in the results, you need to explicitly close the output stream (it will be closed automatically if you just unref it). Be aware that the close call may not be instant as it operation will for the printer to finish printing.

Added in version 4.14.

Parameters:

result – a GAsyncResult

set_accept_label(accept_label: str) None

Sets the label that will be shown on the accept button of the print dialog shown for setup.

Added in version 4.14.

Parameters:

accept_label – the new accept label

set_modal(modal: bool) None

Sets whether the print dialog blocks interaction with the parent window while it is presented.

Added in version 4.14.

Parameters:

modal – the new value

set_page_setup(page_setup: PageSetup) None

Set the page setup for the print dialog.

Added in version 4.14.

Parameters:

page_setup – the new page setup

set_print_settings(print_settings: PrintSettings) None

Sets the print settings for the print dialog.

Added in version 4.14.

Parameters:

print_settings – the new print settings

set_title(title: str) None

Sets the title that will be shown on the print dialog.

Added in version 4.14.

Parameters:

title – the new title

setup(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

This function presents a print dialog to let the user select a printer, and set up print settings and page setup.

The callback will be called when the dialog is dismissed. It should call setup_finish to obtain the results in the form of a PrintSetup, that can then be passed to print or print_file.

One possible use for this method is to have the user select a printer, then show a page setup UI in the application (e.g. to arrange images on a page), then call print on self to do the printing without further user interaction.

Added in version 4.14.

Parameters:
  • parent – the parent GtkWindow

  • cancellable – a GCancellable to cancel the operation

  • callback – a callback to call when the operation is complete

  • user_data – data to pass to callback

setup_finish(result: AsyncResult) PrintSetup | None

Finishes the setup call.

If the call was successful, it returns a PrintSetup which contains the print settings and page setup information that will be used to print.

Added in version 4.14.

Parameters:

result – a GAsyncResult

Properties

class PrintDialog
props.accept_label: str

A label that may be shown on the accept button of a print dialog that is presented by setup.

Added in version 4.14.

props.modal: bool

Whether the print dialog is modal.

Added in version 4.14.

props.page_setup: PageSetup

The page setup to use.

Added in version 4.14.

props.print_settings: PrintSettings

The print settings to use.

Added in version 4.14.

props.title: str

A title that may be shown on the print dialog that is presented by setup.

Added in version 4.14.