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.
PrintOperationGidBuilder builder() static nothrowGet builder for [gtk.print_operation.PrintOperation] Returns: New builder objectbool allowAsync() @property nothrowGet `allowAsync` property. Returns: Determines whether the print operation may run asynchronously or not.void allowAsync(bool propval) @property nothrowSet `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.int currentPage() @property nothrowGet `currentPage` property. Returns: The current page in the document.void currentPage(int propval) @property nothrowSet `currentPage` property. Params: propval = The current page in the document.string customTabLabel() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `defaultPageSetup` property. Returns: The #GtkPageSetup used by default.void defaultPageSetup(gtk.page_setup.PageSetup propval) @property nothrowSet `defaultPageSetup` property. Params: propval = The #GtkPageSetup used by default.bool embedPageSetup() @property nothrowGet `embedPageSetup` property. Returns: If true, page size combo box and orientation combo box are embedded into page setup page.void embedPageSetup(bool propval) @property nothrowSet `embedPageSetup` property. Params: propval = If true, page size combo box and orientation combo box are embedded into page setup page.string exportFilename() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `jobName` property. Returns: A string used to identify the job (e.g. in monitoring applications like eggcups).void jobName(string propval) @property nothrowSet `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).void nPages(int propval) @property nothrowSet `nPages` property. Params: propval = The number of pages in the document.int nPagesToPrint() @property nothrowGet `nPagesToPrint` property. Returns: The number of pages that will be printed.gtk.print_settings.PrintSettings printSettings() @property nothrowGet `printSettings` property. Returns: The #GtkPrintSettings used for initializing the dialog.void printSettings(gtk.print_settings.PrintSettings propval) @property nothrowSet `printSettings` property. Params: propval = The #GtkPrintSettings used for initializing the dialog.bool showProgress() @property nothrowGet `showProgress` property. Returns: Determines whether to show a progress dialog during the print operation.void showProgress(bool propval) @property nothrowSet `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation.gtk.types.PrintStatus status() @property nothrowGet `status` property. Returns: The status of the print operation.string statusString() @property nothrowGet `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() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `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) @property nothrowSet `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() @property nothrowGet `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) @property nothrowSet `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() nothrowCancels 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...gtk.page_setup.PageSetup getDefaultPageSetup() nothrowReturns the default page setup, see [gtk.print_operation.PrintOperation.setDefaultPageSetup]. Returns: the default page setupbool getEmbedPageSetup() nothrowGets 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() nothrowGets the value of #GtkPrintOperation:has-selection property. Returns: whether there is a selectiongtk.types.PrintStatus getStatus() nothrowReturns the status of the print operation. Also see [gtk.print_operation.PrintOperation.getStatusString]. Returns: the status of the print operationstring getStatusString() nothrowReturns 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() nothrowGets the value of #GtkPrintOperation:support-selection property. Returns: whether the application supports print of selectionbool isFinished() nothrowA 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) nothrowSets 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 setCustomTabLabel(string label = null) nothrowSets the label for the tab holding custom widgets.void setDefaultPageSetup(gtk.page_setup.PageSetup defaultPageSetup = null) nothrowMakes default_page_setup the default page setup for op.void setDeferDrawing() nothrowSets 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) nothrowEmbed 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) nothrowSets 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 setJobName(string jobName) nothrowSets the name of the print job. The name is used to identify the job (e.g. in monitoring applications like eggcups).void setPrintSettings(gtk.print_settings.PrintSettings printSettings = null) nothrowSets 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) nothrowIf show_progress is true, the print operation will show a progress dialog during the print operation.void setSupportSelection(bool supportSelection) nothrowSets whether selection is supported by #GtkPrintOperation.void setTrackPrintStatus(bool trackStatus) nothrowIf 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) nothrowSets 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) nothrowIf 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect 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) nothrowConnect to `UpdateCustomWidget` signal.Fluent builder implementation template for gtk.print_operation.PrintOperation
T allowAsync(bool propval) nothrowSet `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.T currentPage(int propval) nothrowSet `currentPage` property. Params: propval = The current page in the document.T customTabLabel(string propval) nothrowSet `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) nothrowSet `defaultPageSetup` property. Params: propval = The #GtkPageSetup used by default.T embedPageSetup(bool propval) nothrowSet `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) nothrowSet `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) nothrowSet `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) nothrowSet `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).T nPages(int propval) nothrowSet `nPages` property. Params: propval = The number of pages in the document.T printSettings(gtk.print_settings.PrintSettings propval) nothrowSet `printSettings` property. Params: propval = The #GtkPrintSettings used for initializing the dialog.T showProgress(bool propval) nothrowSet `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation. Returns: Builder instance for fluent chainingT supportSelection(bool propval) nothrowSet `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) nothrowSet `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) nothrowSet `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) nothrowSet `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