Skip to content

Gtk.PrintUnixDialog

class — extends Dialog, Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager

A print dialog for platforms which don’t provide a native print dialog, like Unix.

<picture> <source srcset="printdialog-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkPrintUnixDialog" src="printdialog.png"> </picture>

It can be used very much like any other GTK dialog, at the cost of the portability offered by the high-level printing API with PrintOperation.

In order to print something with GtkPrintUnixDialog, you need to use PrintUnixDialog.get_selected_printer to obtain a Printer object and use it to construct a PrintJob using PrintJob.new.

GtkPrintUnixDialog uses the following response values:

GtkPrintUnixDialog as GtkBuildable

The GtkPrintUnixDialog implementation of the GtkBuildable interface exposes its notebook internal children with the name “notebook”.

An example of a GtkPrintUnixDialog UI definition fragment:

<object class="GtkPrintUnixDialog" id="dialog1">
  <child internal-child="notebook">
    <object class="GtkNotebook" id="notebook">
      <child>
        <object type="GtkNotebookPage">
          <property name="tab_expand">False</property>
          <property name="tab_fill">False</property>
          <property name="tab">
            <object class="GtkLabel" id="tablabel">
              <property name="label">Tab label</property>
            </object>
          </property>
          <property name="child">
            <object class="GtkLabel" id="tabcontent">
              <property name="label">Content on notebook tab</property>
            </object>
          </property>
        </object>
      </child>
    </object>
  </child>
</object>

CSS nodes

GtkPrintUnixDialog has a single CSS node with name window. The style classes dialog and print are added.

Constructors

new

@classmethod
def new(cls, title: str | None = ..., parent: Window | None = ...) -> Widget

Creates a new GtkPrintUnixDialog.

Parameters:

  • title — Title of the dialog
  • parent — Transient parent of the dialog

Methods

add_custom_tab

def add_custom_tab(self, child: Widget, tab_label: Widget) -> None

Adds a custom tab to the print dialog.

Parameters:

  • child — the widget to put in the custom tab
  • tab_label — the widget to use as tab label

get_current_page

def get_current_page(self) -> int

Gets the current page of the GtkPrintUnixDialog.

get_embed_page_setup

def get_embed_page_setup(self) -> bool

Gets whether to embed the page setup.

get_has_selection

def get_has_selection(self) -> bool

Gets whether there is a selection.

get_manual_capabilities

def get_manual_capabilities(self) -> PrintCapabilities

Gets the capabilities that have been set on this GtkPrintUnixDialog.

get_page_setup

def get_page_setup(self) -> PageSetup

Gets the page setup that is used by the GtkPrintUnixDialog.

get_page_setup_set

def get_page_setup_set(self) -> bool

Gets whether a page setup was set by the user.

get_selected_printer

def get_selected_printer(self) -> Printer | None

Gets the currently selected printer.

get_settings

def get_settings(self) -> PrintSettings

Gets a new GtkPrintSettings object that represents the current values in the print dialog.

Note that this creates a new object, and you need to unref it if don’t want to keep it.

get_support_selection

def get_support_selection(self) -> bool

Gets whether the print dialog allows user to print a selection.

set_current_page

def set_current_page(self, current_page: int) -> None

Sets the current page number.

If current_page is not -1, this enables the current page choice for the range of pages to print.

Parameters:

  • current_page — the current page number.

set_embed_page_setup

def set_embed_page_setup(self, embed: bool) -> None

Embed page size combo box and orientation combo box into page setup page.

Parameters:

  • embed — embed page setup selection

set_has_selection

def set_has_selection(self, has_selection: bool) -> None

Sets whether a selection exists.

Parameters:

  • has_selectionTrue indicates that a selection exists

set_manual_capabilities

def set_manual_capabilities(self, capabilities: PrintCapabilities | int) -> None

This lets you specify the printing capabilities your application supports.

For instance, if you can handle scaling the output then you pass PrintCapabilities.SCALE. If you don’t pass that, then the dialog will only let you select the scale if the printing system automatically handles scaling.

Parameters:

  • capabilities — the printing capabilities of your application

set_page_setup

def set_page_setup(self, page_setup: PageSetup) -> None

Sets the page setup of the GtkPrintUnixDialog.

Parameters:

  • page_setup — a GtkPageSetup

set_settings

def set_settings(self, settings: PrintSettings | None = ...) -> None

Sets the GtkPrintSettings for the GtkPrintUnixDialog.

Typically, this is used to restore saved print settings from a previous print operation before the print dialog is shown.

Parameters:

  • settings — a GtkPrintSettings

set_support_selection

def set_support_selection(self, support_selection: bool) -> None

Sets whether the print dialog allows user to print a selection.

Parameters:

  • support_selectionTrue to allow print selection

Properties

current_page

current_page: int  # read/write

The current page in the document.

embed_page_setup

embed_page_setup: bool  # read/write

True if the page setup controls are embedded.

has_selection

has_selection: bool  # read/write

Whether the application has a selection.

manual_capabilities

manual_capabilities: PrintCapabilities | int  # read/write

Capabilities the application can handle.

page_setup

page_setup: PageSetup  # read/write

The GtkPageSetup object to use.

print_settings

print_settings: PrintSettings  # read/write

The GtkPrintSettings object used for this dialog.

selected_printer

selected_printer: Printer  # read-only

The GtkPrinter which is selected.

support_selection

support_selection: bool  # read/write

Whether the dialog supports selection.