Class: Gtk::PrintOperation

Inherits:
Object
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk4/deprecated.rb

Instance Method Summary collapse

Constructor Details

#initializeGtk::PrintOperation

Creates a new GtkPrintOperation.

Instance Method Details

#allow_async=(allow_async) ⇒ Boolean

Determines whether the print operation may run asynchronously or not.

Some systems don't support asynchronous printing, but those that do will return %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS as the status, and emit the [signalGtk.PrintOperation::done] signal when the operation is actually done.

The Windows port does not support asynchronous operation at all (this is unlikely to change). On other platforms, all actions except for %GTK_PRINT_OPERATION_ACTION_EXPORT support asynchronous operation.

Parameters:

  • allow_async (Boolean)

Returns:

  • (Boolean)

    allow-async

  • (Boolean)

    allow-async

#allow_async?Boolean

Determines whether the print operation may run asynchronously or not.

Some systems don't support asynchronous printing, but those that do will return %GTK_PRINT_OPERATION_RESULT_IN_PROGRESS as the status, and emit the [signalGtk.PrintOperation::done] signal when the operation is actually done.

The Windows port does not support asynchronous operation at all (this is unlikely to change). On other platforms, all actions except for %GTK_PRINT_OPERATION_ACTION_EXPORT support asynchronous operation.

Returns:

  • (Boolean)

    allow-async

#cancelnil

Cancels a running print operation.

This function may be called from a [signalGtk.PrintOperation::begin-print], [signalGtk.PrintOperation::paginate] or [signalGtk.PrintOperation::draw-page] signal handler to stop the currently running print operation.

Returns:

  • (nil)

#current_pageInteger

The current page in the document.

If this is set before [methodGtk.PrintOperation.run], the user will be able to select to print only the current page.

Note that this only makes sense for pre-paginated documents.

Returns:

  • (Integer)

    current-page

#current_page=(current_page) ⇒ Integer

The current page in the document.

If this is set before [methodGtk.PrintOperation.run], the user will be able to select to print only the current page.

Note that this only makes sense for pre-paginated documents.

Parameters:

  • current_page (Integer)

Returns:

  • (Integer)

    current-page

  • (Integer)

    current-page

#custom_tab_labelString

Used as the label of the tab containing custom widgets.

Note that this property may be ignored on some platforms.

If this is nil, GTK uses a default label.

Returns:

  • (String)

    custom-tab-label

#custom_tab_label=(custom_tab_label) ⇒ String

Used as the label of the tab containing custom widgets.

Note that this property may be ignored on some platforms.

If this is nil, GTK uses a default label.

Parameters:

  • custom_tab_label (String)

Returns:

  • (String)

    custom-tab-label

  • (String)

    custom-tab-label

#default_page_setupGtk::PageSetup

The GtkPageSetup used by default.

This page setup will be used by [methodGtk.PrintOperation.run], but it can be overridden on a per-page basis by connecting to the [signalGtk.PrintOperation::request-page-setup] signal.

Returns:

#default_page_setup=(default_page_setup) ⇒ Gtk::PageSetup

The GtkPageSetup used by default.

This page setup will be used by [methodGtk.PrintOperation.run], but it can be overridden on a per-page basis by connecting to the [signalGtk.PrintOperation::request-page-setup] signal.

Parameters:

Returns:

#draw_page_finishnil

Signal that drawing of particular page is complete.

It is called after completion of page drawing (e.g. drawing in another thread). If [methodGtk.PrintOperation.set_defer_drawing] was called before, then this function has to be called by application. Otherwise it is called by GTK itself.

Returns:

  • (nil)

#embed_page_setupBoolean

Gets whether page setup selection combos are embedded

Returns:

  • (Boolean)

    whether page setup selection combos are embedded

#embed_page_setup=(embed_page_setup) ⇒ Boolean

If true, page size combo box and orientation combo box are embedded into page setup page.

Parameters:

  • embed_page_setup (Boolean)

Returns:

  • (Boolean)

    embed-page-setup

  • (Boolean)

    embed-page-setup

#embed_page_setup?Boolean

If true, page size combo box and orientation combo box are embedded into page setup page.

Returns:

  • (Boolean)

    embed-page-setup

#errornil

Call this when the result of a print operation is %GTK_PRINT_OPERATION_RESULT_ERROR.

It can be called either after [methodGtk.PrintOperation.run] returns, or in the [signalGtk.PrintOperation::done] signal handler.

The returned GError will contain more details on what went wrong.

Returns:

  • (nil)

#export_filenameString

The name of a file to generate instead of showing the print dialog.

Currently, PDF is the only supported format.

The intended use of this property is for implementing “Export to PDF” actions.

“Print to PDF” support is independent of this and is done by letting the user pick the “Print to PDF” item from the list of printers in the print dialog.

Returns:

  • (String)

    export-filename

#export_filename=(export_filename) ⇒ String

The name of a file to generate instead of showing the print dialog.

Currently, PDF is the only supported format.

The intended use of this property is for implementing “Export to PDF” actions.

“Print to PDF” support is independent of this and is done by letting the user pick the “Print to PDF” item from the list of printers in the print dialog.

Parameters:

  • export_filename (String)

Returns:

  • (String)

    export-filename

  • (String)

    export-filename

#has_selectionBoolean

Gets whether there is a selection.

Returns:

  • (Boolean)

    whether there is a selection

#has_selection=(has_selection) ⇒ Boolean

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 "Selection" button sensitive.

Parameters:

  • has_selection (Boolean)

Returns:

  • (Boolean)

    has-selection

  • (Boolean)

    has-selection

#has_selection?Boolean

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 "Selection" button sensitive.

Returns:

  • (Boolean)

    has-selection

#is_finishedBoolean

A convenience function to find out if the print operation is finished.

a print operation is finished if its status is either %GTK_PRINT_STATUS_FINISHED or %GTK_PRINT_STATUS_FINISHED_ABORTED.

Note: when you enable print status tracking the print operation can be in a non-finished state even after done has been called, as the operation status then tracks the print job status on the printer.

Returns:

  • (Boolean)

    true, if the print operation is finished.

#job_nameString

A string used to identify the job (e.g. in monitoring applications like eggcups).

If you don't set a job name, GTK picks a default one by numbering successive print jobs.

Returns:

  • (String)

    job-name

#job_name=(job_name) ⇒ String

A string used to identify the job (e.g. in monitoring applications like eggcups).

If you don't set a job name, GTK picks a default one by numbering successive print jobs.

Parameters:

  • job_name (String)

Returns:

  • (String)

    job-name

  • (String)

    job-name

#n_pagesInteger

The number of pages in the document.

This must be set to a positive number before the rendering starts. It may be set in a [signalGtk.PrintOperation::begin-print] signal handler.

Note that the page numbers passed to the [signalGtk.PrintOperation::request-page-setup] and [signalGtk.PrintOperation::draw-page] signals are 0-based, i.e. if the user chooses to print all pages, the last ::draw-page signal will be for page n_pages - 1.

Returns:

  • (Integer)

    n-pages

#n_pages=(n_pages) ⇒ Integer

The number of pages in the document.

This must be set to a positive number before the rendering starts. It may be set in a [signalGtk.PrintOperation::begin-print] signal handler.

Note that the page numbers passed to the [signalGtk.PrintOperation::request-page-setup] and [signalGtk.PrintOperation::draw-page] signals are 0-based, i.e. if the user chooses to print all pages, the last ::draw-page signal will be for page n_pages - 1.

Parameters:

  • n_pages (Integer)

Returns:

  • (Integer)

    n-pages

  • (Integer)

    n-pages

#n_pages_to_printInteger

The number of pages that will be printed.

Note that this value is set during print preparation phase (%GTK_PRINT_STATUS_PREPARING), so this value should never be get before the data generation phase (%GTK_PRINT_STATUS_GENERATING_DATA). You can connect to the [signalGtk.PrintOperation::status-changed] signal and call [methodGtk.PrintOperation.get_n_pages_to_print] when print status is %GTK_PRINT_STATUS_GENERATING_DATA.

This is typically used to track the progress of print operation.

Returns:

  • (Integer)

    n-pages-to-print

#n_pages_to_print=(n_pages_to_print) ⇒ Integer

The number of pages that will be printed.

Note that this value is set during print preparation phase (%GTK_PRINT_STATUS_PREPARING), so this value should never be get before the data generation phase (%GTK_PRINT_STATUS_GENERATING_DATA). You can connect to the [signalGtk.PrintOperation::status-changed] signal and call [methodGtk.PrintOperation.get_n_pages_to_print] when print status is %GTK_PRINT_STATUS_GENERATING_DATA.

This is typically used to track the progress of print operation.

Parameters:

  • n_pages_to_print (Integer)

Returns:

  • (Integer)

    n-pages-to-print

  • (Integer)

    n-pages-to-print

The GtkPrintSettings used for initializing the dialog.

Setting this property is typically used to re-establish print settings from a previous print operation, see [methodGtk.PrintOperation.run].

Returns:

The GtkPrintSettings used for initializing the dialog.

Setting this property is typically used to re-establish print settings from a previous print operation, see [methodGtk.PrintOperation.run].

Parameters:

Returns:

#run(action, parent) ⇒ Gtk::PrintOperationResult

Runs the print operation.

Normally that this function does not return until the rendering of all pages is complete. You can connect to the [signalGtk.PrintOperation::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 set the [Gtk.PrintOperation:allow-async] property, the operation will run asynchronously if this is supported on the platform. The [signalGtk.PrintOperation::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_window_destroy), NULL);
   gtk_window_present (GTK_WINDOW (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.

Parameters:

Returns:

  • (Gtk::PrintOperationResult)

    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 [methodGtk.PrintOperation.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 [signalGtk.PrintOperation::done] signal when done.

#set_defer_drawingnil

Sets up the GtkPrintOperation to wait for calling of [methodGtk.PrintOperation.draw_page_finish from application.

This can be used for drawing page in another thread.

This function must be called in the callback of the [signalGtk.PrintOperation::draw-page] signal.

Returns:

  • (nil)

#show_progress=(show_progress) ⇒ Boolean

Determines whether to show a progress dialog during the print operation.

Parameters:

  • show_progress (Boolean)

Returns:

  • (Boolean)

    show-progress

  • (Boolean)

    show-progress

#show_progress?Boolean

Determines whether to show a progress dialog during the print operation.

Returns:

  • (Boolean)

    show-progress

#statusGtk::PrintStatus

The status of the print operation.

Returns:

#status=(status) ⇒ Gtk::PrintStatus

The status of the print operation.

Parameters:

Returns:

#status_stringString

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.

See the [propertyGtk.PrintOperation:status] property for a status value that is suitable for programmatic use.

Returns:

  • (String)

    status-string

#status_string=(status_string) ⇒ String

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.

See the [propertyGtk.PrintOperation:status] property for a status value that is suitable for programmatic use.

Parameters:

  • status_string (String)

Returns:

  • (String)

    status-string

  • (String)

    status-string

#support_selectionBoolean

Gets whether the application supports print of selection

Returns:

  • (Boolean)

    whether the application supports print of selection

#support_selection=(support_selection) ⇒ Boolean

If true, the print operation will support print of selection.

This allows the print dialog to show a "Selection" button.

Parameters:

  • support_selection (Boolean)

Returns:

  • (Boolean)

    support-selection

  • (Boolean)

    support-selection

#support_selection?Boolean

If true, the print operation will support print of selection.

This allows the print dialog to show a "Selection" button.

Returns:

  • (Boolean)

    support-selection

#track_print_status=(track_print_status) ⇒ Boolean

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 to show things like “out of paper” issues, and when the print job actually reaches the printer. However, this is often implemented using polling, and should not be enabled unless needed.

Parameters:

  • track_print_status (Boolean)

Returns:

  • (Boolean)

    track-print-status

  • (Boolean)

    track-print-status

#track_print_status?Boolean

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 to show things like “out of paper” issues, and when the print job actually reaches the printer. However, this is often implemented using polling, and should not be enabled unless needed.

Returns:

  • (Boolean)

    track-print-status

#unitGtk::Unit

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:

#unit=(unit) ⇒ Gtk::Unit

The transformation for the cairo context obtained from GtkPrintContext is set up in such a way that distances are measured in units of unit.

Parameters:

Returns:

#use_full_page=(use_full_page) ⇒ Boolean

If true, the transformation for the cairo context obtained from GtkPrintContext puts the origin at the top left corner of the page.

This may not be the top left corner of the sheet, depending on page orientation and the number of pages per sheet. Otherwise, the origin is at the top left corner of the imageable area (i.e. inside the margins).

Parameters:

  • use_full_page (Boolean)

Returns:

  • (Boolean)

    use-full-page

  • (Boolean)

    use-full-page

#use_full_page?Boolean

If true, the transformation for the cairo context obtained from GtkPrintContext puts the origin at the top left corner of the page.

This may not be the top left corner of the sheet, depending on page orientation and the number of pages per sheet. Otherwise, the origin is at the top left corner of the imageable area (i.e. inside the margins).

Returns:

  • (Boolean)

    use-full-page