gtk.print_operation
Module for [PrintOperation] class
Types 3
gtk.print_operation.PrintOperation is the high-level, portable printing API.
It looks a bit different than other GTK dialogs such as the gtk.file_chooser.FileChooser, since some platforms don’t expose enough infrastructure to implement a good print dialog. On such platforms, gtk.print_operation.PrintOperation uses the native print dialog. On platforms which do not provide a native print dialog, GTK uses its own, see gtk.print_unix_dialog.PrintUnixDialog.
The typical way to use the high-level printing API is to create a gtk.print_operation.PrintOperation 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 gtk.print_settings.PrintSettings 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 gtk.print_operation.PrintOperation, the main one being gtk.print_operation.PrintOperation.drawPage, which you are supposed to handle and render the page on the provided gtk.print_context.PrintContext 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 gtk.print_operation.PrintOperation 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.void customTabLabel(string propval) @property nothrowSet `customTabLabel` property. Params: propval = Used as the label of the tab containing custom widgets.gtk.page_setup.PageSetup defaultPageSetup() @property nothrowGet `defaultPageSetup` property. Returns: The [gtk.page_setup.PageSetup] used by default.void defaultPageSetup(gtk.page_setup.PageSetup propval) @property nothrowSet `defaultPageSetup` property. Params: propval = The [gtk.page_setup.PageSetup] 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.void exportFilename(string propval) @property nothrowSet `exportFilename` property. Params: propval = The name of a file to generate instead of showing the print dialog.bool hasSelection() @property nothrowGet `hasSelection` property. Returns: Determines whether there is a selection in your application.void hasSelection(bool propval) @property nothrowSet `hasSelection` property. Params: propval = Determines whether there is a selection in your application.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 [gtk.print_settings.PrintSettings] used for initializing the dialog.void printSettings(gtk.print_settings.PrintSettings propval) @property nothrowSet `printSettings` property. Params: propval = The [gtk.print_settings.PrintSettings] 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.bool supportSelection() @property nothrowGet `supportSelection` property. Returns: If true, the print operation will support print of selection.void supportSelection(bool propval) @property nothrowSet `supportSelection` property. Params: propval = If true, the print operation will support print of selection.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.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.gtk.types.Unit unit() @property nothrowGet `unit` property. Returns: The transformation for the cairo context obtained from [gtk.print_context.PrintContext] 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 [gtk.print_context.PrintContext] 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 [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.void useFullPage(bool propval) @property nothrowSet `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.gtk.page_setup.PageSetup getDefaultPageSetup() nothrowReturns the default page setup. Returns: the default page setupbool getEmbedPageSetup() nothrowGets whether page setup selection combos are embedded Returns: whether page setup selection combos are embeddedvoid getError()Call this when the result of a print operation is [gtk.types.PrintOperationResult.Error].bool getHasSelection() nothrowGets whether there is a selection. Returns: whether there is a selectionstring getStatusString() nothrowReturns a string representation of the status of the print operation.bool getSupportSelection() nothrowGets whether the application supports print of selection Returns: whether the application supports print of selectiongtk.types.PrintOperationResult run(gtk.types.PrintOperationAction action, gtk.window.Window parent = null)Runs the print operation.void setAllowAsync(bool allowAsync) nothrowSets whether [gtk.print_operation.PrintOperation.run] may return before the print operation is completed.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 [gtk.print_operation.PrintOperation] to wait for calling of [methodGtk.PrintOperation.draw_page_finish from application.void setEmbedPageSetup(bool embed) nothrowEmbed page size combo box and orientation combo box into page setup page.void setExportFilename(string filename) nothrowSets up the [gtk.print_operation.PrintOperation] to generate a file instead of showing the print dialog.void setPrintSettings(gtk.print_settings.PrintSettings printSettings = null) nothrowSets the print settings for op.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 [gtk.print_operation.PrintOperation].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.void setUnit(gtk.types.Unit unit) nothrowSets up the transformation for the cairo context obtained from [gtk.print_context.PrintContext] 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 [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.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.T defaultPageSetup(gtk.page_setup.PageSetup propval) nothrowSet `defaultPageSetup` property. Params: propval = The [gtk.page_setup.PageSetup] 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.T hasSelection(bool propval) nothrowSet `hasSelection` property. Params: propval = Determines whether there is a selection in your application.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 [gtk.print_settings.PrintSettings] 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.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.T unit(gtk.types.Unit propval) nothrowSet `unit` property. Params: propval = The transformation for the cairo context obtained from [gtk.print_context.PrintContext] is set up in such a way that distances are measured in units of @unit....T useFullPage(bool propval) nothrowSet `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.Fluent builder for gtk.print_operation.PrintOperation