Method

GtkPrintOperationrun

Declaration [src]

GtkPrintOperationResult
gtk_print_operation_run (
  GtkPrintOperation* op,
  GtkPrintOperationAction action,
  GtkWindow* parent,
  GError** error
)

Description [src]

Runs the print operation, by first letting the user modify print settings in the print dialog, and then print the document.

Normally that this function does not return until the rendering of all pages is complete. You can connect to the GtkPrintOperation::status-changed signal on op to obtain some information about the progress of the print operation. Furthermore, it may use a recursive mainloop to show the print dialog.

If you call gtk_print_operation_set_allow_async() or set the GtkPrintOperation:allow-async property the operation will run asynchronously if this is supported on the platform. The GtkPrintOperation::done signal will be emitted with the result of the operation when the it is done (i.e. when the dialog is canceled, or when the print succeeds or fails).

if (settings != NULL)
  gtk_print_operation_set_print_settings (print, settings);
  
if (page_setup != NULL)
  gtk_print_operation_set_default_page_setup (print, page_setup);
  
g_signal_connect (print, "begin-print",
                  G_CALLBACK (begin_print), &data);
g_signal_connect (print, "draw-page",
                  G_CALLBACK (draw_page), &data);
 
res = gtk_print_operation_run (print,
                               GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                               parent,
                               &error);
 
if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
 {
   error_dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
                                 GTK_DIALOG_DESTROY_WITH_PARENT,
                         GTK_MESSAGE_ERROR,
                         GTK_BUTTONS_CLOSE,
                         "Error printing file:\n%s",
                         error->message);
   g_signal_connect (error_dialog, "response",
                     G_CALLBACK (gtk_widget_destroy), NULL);
   gtk_widget_show (error_dialog);
   g_error_free (error);
 }
else 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));
 }

Note that gtk_print_operation_run() can only be called once on a given GtkPrintOperation.

Available since:2.10

Parameters

action

Type: GtkPrintOperationAction

The action to start.

parent

Type: GtkWindow

Transient parent of the dialog.

The argument can be NULL.
The data is owned by the caller of the function.
error

Type: GError **

The return location for an error.

The argument can be NULL.
The argument will be set to NULL by the function if there are no errors.
In case of error, the argument will be set and the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: GtkPrintOperationResult

The result of the print operation. A return value of GTK_PRINT_OPERATION_RESULT_APPLY indicates that the printing was completed successfully. In this case, it is a good idea to obtain the used print settings with gtk_print_operation_get_print_settings() and store them for reuse with the next print operation. A value of GTK_PRINT_OPERATION_RESULT_IN_PROGRESS means the operation is running asynchronously, and will emit the GtkPrintOperation::done signal when done.