gtk.print_operation
Module for [PrintOperation] class
Types 3
GtkPrintOperation is the high-level, portable printing API. It looks a bit different than other GTK+ dialogs such as the #GtkFileChooser, since some platforms don’t expose enough infrastructure to implement a good print dialog. On such platforms, GtkPrintOperation uses the native print dialog. On platforms which do not provide a native print dialog, GTK+ uses its own, see #GtkPrintUnixDialog.
The typical way to use the high-level printing API is to create a GtkPrintOperation object with [gtk.print_operation.PrintOperation.new_] when the user selects to print. Then you set some properties on it, e.g. the page size, any #GtkPrintSettings from previous print operations, the number of pages, the current page, etc.
Then you start the print operation by calling [gtk.print_operation.PrintOperation.run]. It will then show a dialog, let the user select a printer and options. When the user finished the dialog various signals will be emitted on the #GtkPrintOperation, the main one being #GtkPrintOperation::draw-page, which you are supposed to catch and render the page on the provided #GtkPrintContext using Cairo.
The high-level printing API
static GtkPrintSettings *settings = NULL;
static void
do_print (void)
{
GtkPrintOperation *print;
GtkPrintOperationResult res;
print = gtk_print_operation_new ();
if (settings != NULL)
gtk_print_operation_set_print_settings (print, settings);
g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL);
g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_WINDOW (main_window), NULL);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
{
if (settings != NULL)
g_object_unref (settings);
settings = g_object_ref (gtk_print_operation_get_print_settings (print));
}
g_object_unref (print);
}By default GtkPrintOperation uses an external application to do print preview. To implement a custom print preview, an application must connect to the preview signal. The functions [gtk.print_operation_preview.PrintOperationPreview.renderPage], [gtk.print_operation_preview.PrintOperationPreview.endPreview] and [gtk.print_operation_preview.PrintOperationPreview.isSelected] are useful when implementing a print preview.
PrintOperation self()Returns `this`, for use in `with` statements.PrintOperationGidBuilder builder()Get builder for [gtk.print_operation.PrintOperation] Returns: New builder objectbool allowAsync() @propertyGet `allowAsync` property. Returns: Determines whether the print operation may run asynchronously or not.void allowAsync(bool propval) @propertySet `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.void currentPage(int propval) @propertySet `currentPage` property. Params: propval = The current page in the document.string customTabLabel() @propertyGet `customTabLabel` property. Returns: Used as the label of the tab containing custom widgets. Note that this property may be ignored on some platforms.void customTabLabel(string propval) @propertySet `customTabLabel` property. Params: propval = Used as the label of the tab containing custom widgets. Note that this property may be ignored on some platforms.gtk.page_setup.PageSetup defaultPageSetup() @propertyGet `defaultPageSetup` property. Returns: The #GtkPageSetup used by default.void defaultPageSetup(gtk.page_setup.PageSetup propval) @propertySet `defaultPageSetup` property. Params: propval = The #GtkPageSetup used by default.bool embedPageSetup() @propertyGet `embedPageSetup` property. Returns: If true, page size combo box and orientation combo box are embedded into page setup page.void embedPageSetup(bool propval) @propertySet `embedPageSetup` property. Params: propval = If true, page size combo box and orientation combo box are embedded into page setup page.string exportFilename() @propertyGet `exportFilename` property. Returns: The name of a file to generate instead of showing the print dialog. Currently, PDF is the only supported format.void exportFilename(string propval) @propertySet `exportFilename` property. Params: propval = The name of a file to generate instead of showing the print dialog. Currently, PDF is the only supported format.bool hasSelection() @propertyGet `hasSelection` property. Returns: Determines whether there is a selection in your application. This can allow your application to print the selection. This is typically used to make a "Selectio...void hasSelection(bool propval) @propertySet `hasSelection` property. Params: propval = Determines whether there is a selection in your application. This can allow your application to print the selection. This is typically used to make a ...string jobName() @propertyGet `jobName` property. Returns: A string used to identify the job (e.g. in monitoring applications like eggcups).void jobName(string propval) @propertySet `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).void nPages(int propval) @propertySet `nPages` property. Params: propval = The number of pages in the document.int nPagesToPrint() @propertyGet `nPagesToPrint` property. Returns: The number of pages that will be printed.gtk.print_settings.PrintSettings printSettings() @propertyGet `printSettings` property. Returns: The #GtkPrintSettings used for initializing the dialog.void printSettings(gtk.print_settings.PrintSettings propval) @propertySet `printSettings` property. Params: propval = The #GtkPrintSettings used for initializing the dialog.bool showProgress() @propertyGet `showProgress` property. Returns: Determines whether to show a progress dialog during the print operation.void showProgress(bool propval) @propertySet `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation.gtk.types.PrintStatus status() @propertyGet `status` property. Returns: The status of the print operation.string statusString() @propertyGet `statusString` property. Returns: A string representation of the status of the print operation. The string is translated and suitable for displaying the print status e.g. in a #GtkStatusbar.bool supportSelection() @propertyGet `supportSelection` property. Returns: If true, the print operation will support print of selection. This allows the print dialog to show a "Selection" button.void supportSelection(bool propval) @propertySet `supportSelection` property. Params: propval = If true, the print operation will support print of selection. This allows the print dialog to show a "Selection" button.bool trackPrintStatus() @propertyGet `trackPrintStatus` property. Returns: If true, the print operation will try to continue report on the status of the print job in the printer queues and printer. This can allow your application ...void trackPrintStatus(bool propval) @propertySet `trackPrintStatus` property. Params: propval = If true, the print operation will try to continue report on the status of the print job in the printer queues and printer. This can allow your app...gtk.types.Unit unit() @propertyGet `unit` property. Returns: The transformation for the cairo context obtained from #GtkPrintContext is set up in such a way that distances are measured in units of @unit.void unit(gtk.types.Unit propval) @propertySet `unit` property. Params: propval = The transformation for the cairo context obtained from #GtkPrintContext is set up in such a way that distances are measured in units of @unit.bool useFullPage() @propertyGet `useFullPage` property. Returns: If true, the transformation for the cairo context obtained from #GtkPrintContext puts the origin at the top left corner of the page (which may not be the top le...void useFullPage(bool propval) @propertySet `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from #GtkPrintContext puts the origin at the top left corner of the page (which may not be t...void cancel()Cancels a running print operation. This function may be called from a #GtkPrintOperation::begin-print, #GtkPrintOperation::paginate or #GtkPrintOperation::draw-page signal handler to stop the curre...void drawPageFinish()Signalize that drawing of particular page is complete.gtk.page_setup.PageSetup getDefaultPageSetup()Returns the default page setup, see [gtk.print_operation.PrintOperation.setDefaultPageSetup]. Returns: the default page setupbool getEmbedPageSetup()Gets the value of #GtkPrintOperation:embed-page-setup property. Returns: whether page setup selection combos are embeddedvoid getError()Call this when the result of a print operation is [gtk.types.PrintOperationResult.Error], either as returned by [gtk.print_operation.PrintOperation.run], or in the #GtkPrintOperation::done signal h...bool getHasSelection()Gets the value of #GtkPrintOperation:has-selection property. Returns: whether there is a selectionint getNPagesToPrint()Returns the number of pages that will be printed.gtk.print_settings.PrintSettings getPrintSettings()Returns the current print settings.gtk.types.PrintStatus getStatus()Returns the status of the print operation. Also see [gtk.print_operation.PrintOperation.getStatusString]. Returns: the status of the print operationstring getStatusString()Returns a string representation of the status of the print operation. The string is translated and suitable for displaying the print status e.g. in a #GtkStatusbar.bool getSupportSelection()Gets the value of #GtkPrintOperation:support-selection property. Returns: whether the application supports print of selectionbool isFinished()A convenience function to find out if the print operation is finished, either successfully ([gtk.types.PrintStatus.Finished]) or unsuccessfully ([gtk.types.PrintStatus.FinishedAborted]).gtk.types.PrintOperationResult run(gtk.types.PrintOperationAction action, gtk.window.Window parent = null)Runs the print operation, by first letting the user modify print settings in the print dialog, and then print the document.void setAllowAsync(bool allowAsync)Sets whether the [gtk.print_operation.PrintOperation.run] may return before the print operation is completed. Note that some platforms may not allow asynchronous operation.void setCurrentPage(int currentPage)Sets the current page.void setCustomTabLabel(string label = null)Sets the label for the tab holding custom widgets.void setDefaultPageSetup(gtk.page_setup.PageSetup defaultPageSetup = null)Makes defaultpagesetup the default page setup for op.void setDeferDrawing()Sets up the #GtkPrintOperation to wait for calling of [gtk.print_operation.PrintOperation.drawPageFinish] from application. It can be used for drawing page in another thread.void setEmbedPageSetup(bool embed)Embed page size combo box and orientation combo box into page setup page. Selected page setup is stored as default page setup in #GtkPrintOperation.void setExportFilename(string filename)Sets up the #GtkPrintOperation to generate a file instead of showing the print dialog. The indended use of this function is for implementing “Export to PDF” actions. Currently, PDF is the only ...void setHasSelection(bool hasSelection)Sets whether there is a selection to print.void setJobName(string jobName)Sets the name of the print job. The name is used to identify the job (e.g. in monitoring applications like eggcups).void setNPages(int nPages)Sets the number of pages in the document.void setPrintSettings(gtk.print_settings.PrintSettings printSettings = null)Sets the print settings for op. This is typically used to re-establish print settings from a previous print operation, see [gtk.print_operation.PrintOperation.run].void setShowProgress(bool showProgress)If show_progress is true, the print operation will show a progress dialog during the print operation.void setSupportSelection(bool supportSelection)Sets whether selection is supported by #GtkPrintOperation.void setTrackPrintStatus(bool trackStatus)If track_status is true, the print operation will try to continue report on the status of the print job in the printer queues and printer. This can allow your application to show things like “out...void setUnit(gtk.types.Unit unit)Sets up the transformation for the cairo context obtained from #GtkPrintContext in such a way that distances are measured in units of unit.void setUseFullPage(bool fullPage)If full_page is true, the transformation for the cairo context obtained from #GtkPrintContext puts the origin at the top left corner of the page (which may not be the top left corner of the sheet, ...gulong connectBeginPrint(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 3)Connect to `BeginPrint` signal.gulong connectCreateCustomWidget(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T : gobject.object.ObjectWrap)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 2)Connect to `CreateCustomWidget` signal.gulong connectCustomWidgetApply(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.widget.Widget)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 3)Connect to `CustomWidgetApply` signal.gulong connectDone(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.PrintOperationResult)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 3)Connect to `Done` signal.gulong connectDrawPage(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 4)Connect to `DrawPage` signal.gulong connectEndPrint(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 3)Connect to `EndPrint` signal.gulong connectPaginate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == bool)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 3)Connect to `Paginate` signal.gulong connectPreview(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == bool)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation_preview.PrintOperationPreview)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.window.Window)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 5)Connect to `Preview` signal.gulong connectRequestPageSetup(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.page_setup.PageSetup)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 5)Connect to `RequestPageSetup` signal.gulong connectStatusChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 2)Connect to `StatusChanged` signal.gulong connectUpdateCustomWidget(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.widget.Widget)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.page_setup.PageSetup)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.print_settings.PrintSettings)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation)))
&& Parameters!T.length < 5)Connect to `UpdateCustomWidget` signal.T allowAsync(bool propval)Set `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.T currentPage(int propval)Set `currentPage` property. Params: propval = The current page in the document.T customTabLabel(string propval)Set `customTabLabel` property. Params: propval = Used as the label of the tab containing custom widgets. Note that this property may be ignored on some platforms.T defaultPageSetup(gtk.page_setup.PageSetup propval)Set `defaultPageSetup` property. Params: propval = The #GtkPageSetup used by default.T embedPageSetup(bool propval)Set `embedPageSetup` property. Params: propval = If true, page size combo box and orientation combo box are embedded into page setup page. Returns: Builder instance for fluent chainingT exportFilename(string propval)Set `exportFilename` property. Params: propval = The name of a file to generate instead of showing the print dialog. Currently, PDF is the only supported format.T hasSelection(bool propval)Set `hasSelection` property. Params: propval = Determines whether there is a selection in your application. This can allow your application to print the selection. This is typically used to make a ...T jobName(string propval)Set `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).T nPages(int propval)Set `nPages` property. Params: propval = The number of pages in the document.T printSettings(gtk.print_settings.PrintSettings propval)Set `printSettings` property. Params: propval = The #GtkPrintSettings used for initializing the dialog.T showProgress(bool propval)Set `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation. Returns: Builder instance for fluent chainingT supportSelection(bool propval)Set `supportSelection` property. Params: propval = If true, the print operation will support print of selection. This allows the print dialog to show a "Selection" button. Returns: Builder instance...T trackPrintStatus(bool propval)Set `trackPrintStatus` property. Params: propval = If true, the print operation will try to continue report on the status of the print job in the printer queues and printer. This can allow your app...T unit(gtk.types.Unit propval)Set `unit` property. Params: propval = The transformation for the cairo context obtained from #GtkPrintContext is set up in such a way that distances are measured in units of @unit. Returns: Builde...T useFullPage(bool propval)Set `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from #GtkPrintContext puts the origin at the top left corner of the page (which may not be t...Fluent builder for [gtk.print_operation.PrintOperation]