Interface

Gtk-4.0GtkPrintOperationSignalSignatures

interface SignalSignatures {
    "begin-print": (arg0: Gtk.PrintContext) => void;
    "create-custom-widget": () => GObject.Object;
    "custom-widget-apply": (arg0: Gtk.Widget) => void;
    done: (arg0: Gtk.PrintOperationResult) => void;
    "draw-page": (arg0: Gtk.PrintContext, arg1: number) => void;
    "end-print": (arg0: Gtk.PrintContext) => void;
    notify: (arg0: GObject.ParamSpec) => void;
    "notify::allow-async": (pspec: GObject.ParamSpec) => void;
    "notify::current-page": (pspec: GObject.ParamSpec) => void;
    "notify::custom-tab-label": (pspec: GObject.ParamSpec) => void;
    "notify::default-page-setup": (pspec: GObject.ParamSpec) => void;
    "notify::embed-page-setup": (pspec: GObject.ParamSpec) => void;
    "notify::export-filename": (pspec: GObject.ParamSpec) => void;
    "notify::has-selection": (pspec: GObject.ParamSpec) => void;
    "notify::job-name": (pspec: GObject.ParamSpec) => void;
    "notify::n-pages": (pspec: GObject.ParamSpec) => void;
    "notify::n-pages-to-print": (pspec: GObject.ParamSpec) => void;
    "notify::print-settings": (pspec: GObject.ParamSpec) => void;
    "notify::show-progress": (pspec: GObject.ParamSpec) => void;
    "notify::status": (pspec: GObject.ParamSpec) => void;
    "notify::status-string": (pspec: GObject.ParamSpec) => void;
    "notify::support-selection": (pspec: GObject.ParamSpec) => void;
    "notify::track-print-status": (pspec: GObject.ParamSpec) => void;
    "notify::unit": (pspec: GObject.ParamSpec) => void;
    "notify::use-full-page": (pspec: GObject.ParamSpec) => void;
    paginate: (arg0: Gtk.PrintContext) => boolean | void;
    preview: (
        arg0: Gtk.PrintOperationPreview,
        arg1: Gtk.PrintContext,
        arg2: Gtk.Window,
    ) => boolean | void;
    "request-page-setup": (
        arg0: Gtk.PrintContext,
        arg1: number,
        arg2: Gtk.PageSetup,
    ) => void;
    "status-changed": () => void;
    "update-custom-widget": (
        arg0: Gtk.Widget,
        arg1: Gtk.PageSetup,
        arg2: Gtk.PrintSettings,
    ) => void;
}

Hierarchy (View Summary)

Index

Properties

"begin-print": (arg0: Gtk.PrintContext) => void

Emitted after the user has finished changing print settings in the dialog, before the actual rendering starts.

A typical use for ::begin-print is to use the parameters from the Gtk.PrintContext and paginate the document accordingly, and then set the number of pages with Gtk.PrintOperation.set_n_pages.

"create-custom-widget": () => GObject.Object

Emitted when displaying the print dialog.

If you return a widget in a handler for this signal it will be added to a custom tab in the print dialog. You typically return a container widget with multiple widgets in it.

The print dialog owns the returned widget, and its lifetime is not controlled by the application. However, the widget is guaranteed to stay around until the Gtk.PrintOperation::custom-widget-apply signal is emitted on the operation. Then you can read out any information you need from the widgets.

"custom-widget-apply": (arg0: Gtk.Widget) => void

Emitted right before ::begin-print if you added a custom widget in the ::create-custom-widget handler.

When you get this signal you should read the information from the custom widgets, as the widgets are not guaranteed to be around at a later time.

done: (arg0: Gtk.PrintOperationResult) => void

Emitted when the print operation run has finished doing everything required for printing.

result gives you information about what happened during the run. If result is Gtk.PrintOperationResult.ERROR then you can call Gtk.PrintOperation.get_error for more information.

If you enabled print status tracking then Gtk.PrintOperation.is_finished may still return false after the ::done signal was emitted.

"draw-page": (arg0: Gtk.PrintContext, arg1: number) => void

Emitted for every page that is printed.

The signal handler must render the page_nr's page onto the cairo context obtained from context using Gtk.PrintContext.get_cairo_context.

static void
draw_page (GtkPrintOperation *operation,
GtkPrintContext *context,
int page_nr,
gpointer user_data)
{
cairo_t *cr;
PangoLayout *layout;
double width, text_height;
int layout_height;
PangoFontDescription *desc;

cr = gtk_print_context_get_cairo_context (context);
width = gtk_print_context_get_width (context);

cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);

cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
cairo_fill (cr);

layout = gtk_print_context_create_pango_layout (context);

desc = pango_font_description_from_string ("sans 14");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);

pango_layout_set_text (layout, "some text", -1);
pango_layout_set_width (layout, width * PANGO_SCALE);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);

pango_layout_get_size (layout, NULL, &layout_height);
text_height = (double)layout_height / PANGO_SCALE;

cairo_move_to (cr, width / 2, (HEADER_HEIGHT - text_height) / 2);
pango_cairo_show_layout (cr, layout);

g_object_unref (layout);
}

Use Gtk.PrintOperation.set_use_full_page and Gtk.PrintOperation.set_unit before starting the print operation to set up the transformation of the cairo context according to your needs.

"end-print": (arg0: Gtk.PrintContext) => void

Emitted after all pages have been rendered.

A handler for this signal can clean up any resources that have been allocated in the Gtk.PrintOperation::begin-print handler.

"notify::allow-async": (pspec: GObject.ParamSpec) => void
"notify::current-page": (pspec: GObject.ParamSpec) => void
"notify::custom-tab-label": (pspec: GObject.ParamSpec) => void
"notify::default-page-setup": (pspec: GObject.ParamSpec) => void
"notify::embed-page-setup": (pspec: GObject.ParamSpec) => void
"notify::export-filename": (pspec: GObject.ParamSpec) => void
"notify::has-selection": (pspec: GObject.ParamSpec) => void
"notify::job-name": (pspec: GObject.ParamSpec) => void
"notify::n-pages": (pspec: GObject.ParamSpec) => void
"notify::n-pages-to-print": (pspec: GObject.ParamSpec) => void
"notify::print-settings": (pspec: GObject.ParamSpec) => void
"notify::show-progress": (pspec: GObject.ParamSpec) => void
"notify::status": (pspec: GObject.ParamSpec) => void
"notify::status-string": (pspec: GObject.ParamSpec) => void
"notify::support-selection": (pspec: GObject.ParamSpec) => void
"notify::track-print-status": (pspec: GObject.ParamSpec) => void
"notify::unit": (pspec: GObject.ParamSpec) => void
"notify::use-full-page": (pspec: GObject.ParamSpec) => void
paginate: (arg0: Gtk.PrintContext) => boolean | void

Emitted after the ::begin-print signal, but before the actual rendering starts.

It keeps getting emitted until a connected signal handler returns true.

The ::paginate signal is intended to be used for paginating a document in small chunks, to avoid blocking the user interface for a long time. The signal handler should update the number of pages using Gtk.PrintOperation.set_n_pages, and return true if the document has been completely paginated.

If you don't need to do pagination in chunks, you can simply do it all in the ::begin-print handler, and set the number of pages from there.

preview: (
    arg0: Gtk.PrintOperationPreview,
    arg1: Gtk.PrintContext,
    arg2: Gtk.Window,
) => boolean | void

Gets emitted when a preview is requested from the native dialog.

The default handler for this signal uses an external viewer application to preview.

To implement a custom print preview, an application must return true from its handler for this signal. In order to use the provided context for the preview implementation, it must be given a suitable cairo context with Gtk.PrintContext.set_cairo_context.

The custom preview implementation can use Gtk.PrintOperationPreview.is_selected and Gtk.PrintOperationPreview.render_page to find pages which are selected for print and render them. The preview must be finished by calling Gtk.PrintOperationPreview.end_preview (typically in response to the user clicking a close button).

"request-page-setup": (
    arg0: Gtk.PrintContext,
    arg1: number,
    arg2: Gtk.PageSetup,
) => void

Emitted once for every page that is printed.

This gives the application a chance to modify the page setup. Any changes done to setup will be in force only for printing this page.

"status-changed": () => void

Emitted at between the various phases of the print operation.

See Gtk.PrintStatus for the phases that are being discriminated. Use Gtk.PrintOperation.get_status to find out the current status.

"update-custom-widget": (
    arg0: Gtk.Widget,
    arg1: Gtk.PageSetup,
    arg2: Gtk.PrintSettings,
) => void

Emitted after change of selected printer.

The actual page setup and print settings are passed to the custom widget, which can actualize itself according to this change.

Properties - Inherited from GObject

notify: (arg0: GObject.ParamSpec) => void

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with GObject.ParamFlags.EXPLICIT_NOTIFY, then any call to g_object_set_property() results in ::notify being emitted, even if the new value is the same as the old. If they did pass GObject.ParamFlags.EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly call g_object_notify() or g_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.

This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the g_signal_connect() call, like this:

g_signal_connect (text_view->buffer, "notify::paste-target-list",
G_CALLBACK (gtk_text_view_target_list_notify),
text_view)

It is important to note that you must use [canonical parameter names][class@GObject.ParamSpec#parameter-names] as detail strings for the notify signal.