gi-gtk-3.0.17: Gtk bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.Gtk.Objects.PrintOperation

Contents

Description

GtkPrintOperation is the high-level, portable printing API. It looks a bit different than other GTK+ dialogs such as the FileChooser, 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 printOperationNew when the user selects to print. Then you set some properties on it, e.g. the page size, any PrintSettings from previous print operations, the number of pages, the current page, etc.

Then you start the print operation by calling printOperationRun. 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 PrintOperation, the main one being PrintOperation::draw-page, which you are supposed to catch and render the page on the provided PrintContext using Cairo.

The high-level printing API

C code

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 printOperationPreviewRenderPage, printOperationPreviewEndPreview and printOperationPreviewIsSelected are useful when implementing a print preview.

Synopsis

Exported types

Methods

cancel

printOperationCancel Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m () 

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

Since: 2.10

drawPageFinish

printOperationDrawPageFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m () 

Signalize that drawing of particular page is complete.

It is called after completion of page drawing (e.g. drawing in another thread). If printOperationSetDeferDrawing was called before, then this function has to be called by application. In another case it is called by the library itself.

Since: 2.16

getDefaultPageSetup

printOperationGetDefaultPageSetup Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m PageSetup

Returns: the default page setup

Returns the default page setup, see printOperationSetDefaultPageSetup.

Since: 2.10

getEmbedPageSetup

printOperationGetEmbedPageSetup Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Bool

Returns: whether page setup selection combos are embedded

Gets the value of PrintOperation:embed-page-setup property.

Since: 2.18

getError

printOperationGetError Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m ()

(Can throw GError)

Call this when the result of a print operation is PrintOperationResultError, either as returned by printOperationRun, or in the PrintOperation::done signal handler. The returned GError will contain more details on what went wrong.

Since: 2.10

getHasSelection

printOperationGetHasSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Bool

Returns: whether there is a selection

Gets the value of PrintOperation:has-selection property.

Since: 2.18

getNPagesToPrint

printOperationGetNPagesToPrint Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Int32

Returns: the number of pages that will be printed

Returns the number of pages that will be printed.

Note that this value is set during print preparation phase (PrintStatusPreparing), so this function should never be called before the data generation phase (PrintStatusGeneratingData). You can connect to the PrintOperation::status-changed signal and call printOperationGetNPagesToPrint when print status is PrintStatusGeneratingData. This is typically used to track the progress of print operation.

Since: 2.18

getPrintSettings

printOperationGetPrintSettings Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m PrintSettings

Returns: the current print settings of op.

Returns the current print settings.

Note that the return value is Nothing until either printOperationSetPrintSettings or printOperationRun have been called.

Since: 2.10

getStatus

printOperationGetStatus Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m PrintStatus

Returns: the status of the print operation

Returns the status of the print operation. Also see printOperationGetStatusString.

Since: 2.10

getStatusString

printOperationGetStatusString Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Text

Returns: a string representation of the status of the print operation

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 Statusbar.

Use printOperationGetStatus to obtain a status value that is suitable for programmatic use.

Since: 2.10

getSupportSelection

printOperationGetSupportSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Bool

Returns: whether the application supports print of selection

Gets the value of PrintOperation:support-selection property.

Since: 2.18

isFinished

printOperationIsFinished Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m Bool

Returns: True, if the print operation is finished.

A convenience function to find out if the print operation is finished, either successfully (PrintStatusFinished) or unsuccessfully (PrintStatusFinishedAborted).

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.

Since: 2.10

new

printOperationNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m PrintOperation

Returns: a new PrintOperation

Creates a new PrintOperation.

Since: 2.10

run

printOperationRun Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a, IsWindow b) 
=> a

op: a PrintOperation

-> PrintOperationAction

action: the action to start

-> Maybe b

parent: Transient parent of the dialog

-> m PrintOperationResult

Returns: the result of the print operation. A return value of PrintOperationResultApply indicates that the printing was completed successfully. In this case, it is a good idea to obtain the used print settings with printOperationGetPrintSettings and store them for reuse with the next print operation. A value of PrintOperationResultInProgress means the operation is running asynchronously, and will emit the PrintOperation::done signal when done. (Can throw GError)

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 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 call printOperationSetAllowAsync or set the PrintOperation:allow-async property the operation will run asynchronously if this is supported on the platform. The 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).

C code

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 printOperationRun can only be called once on a given PrintOperation.

Since: 2.10

setAllowAsync

printOperationSetAllowAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

allowAsync: True to allow asynchronous operation

-> m () 

Sets whether the printOperationRun may return before the print operation is completed. Note that some platforms may not allow asynchronous operation.

Since: 2.10

setCurrentPage

printOperationSetCurrentPage Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Int32

currentPage: the current page, 0-based

-> m () 

Sets the current page.

If this is called before printOperationRun, the user will be able to select to print only the current page.

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

Since: 2.10

setCustomTabLabel

printOperationSetCustomTabLabel Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Maybe Text

label: the label to use, or Nothing to use the default label

-> m () 

Sets the label for the tab holding custom widgets.

Since: 2.10

setDefaultPageSetup

printOperationSetDefaultPageSetup Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a, IsPageSetup b) 
=> a

op: a PrintOperation

-> Maybe b

defaultPageSetup: a PageSetup, or Nothing

-> m () 

Makes defaultPageSetup the default page setup for op.

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

Since: 2.10

setDeferDrawing

printOperationSetDeferDrawing Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> m () 

Sets up the PrintOperation to wait for calling of printOperationDrawPageFinish from application. It can be used for drawing page in another thread.

This function must be called in the callback of “draw-page” signal.

Since: 2.16

setEmbedPageSetup

printOperationSetEmbedPageSetup Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

embed: True to embed page setup selection in the GtkPrintUnixDialog

-> m () 

Embed page size combo box and orientation combo box into page setup page. Selected page setup is stored as default page setup in PrintOperation.

Since: 2.18

setExportFilename

printOperationSetExportFilename Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> [Char]

filename: the filename for the exported file

-> m () 

Sets up the PrintOperation 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 supported format.

“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.

Since: 2.10

setHasSelection

printOperationSetHasSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

hasSelection: True indicates that a selection exists

-> m () 

Sets whether there is a selection to print.

Application has to set number of pages to which the selection will draw by printOperationSetNPages in a callback of PrintOperation::begin-print.

Since: 2.18

setJobName

printOperationSetJobName Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Text

jobName: a string that identifies the print job

-> m () 

Sets the name of the print job. The name is 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.

Since: 2.10

setNPages

printOperationSetNPages Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Int32

nPages: the number of pages

-> m () 

Sets 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 PrintOperation::begin-print signal hander.

Note that the page numbers passed to the PrintOperation::request-page-setup and 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 nPages - 1.

Since: 2.10

setPrintSettings

printOperationSetPrintSettings Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a, IsPrintSettings b) 
=> a

op: a PrintOperation

-> Maybe b

printSettings: PrintSettings

-> m () 

Sets the print settings for op. This is typically used to re-establish print settings from a previous print operation, see printOperationRun.

Since: 2.10

setShowProgress

printOperationSetShowProgress Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

showProgress: True to show a progress dialog

-> m () 

If showProgress is True, the print operation will show a progress dialog during the print operation.

Since: 2.10

setSupportSelection

printOperationSetSupportSelection Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

supportSelection: True to support selection

-> m () 

Sets whether selection is supported by PrintOperation.

Since: 2.18

setTrackPrintStatus

printOperationSetTrackPrintStatus Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

trackStatus: True to track status after printing

-> m () 

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 of paper” issues, and when the print job actually reaches the printer.

This function is often implemented using some form of polling, so it should not be enabled unless needed.

Since: 2.10

setUnit

printOperationSetUnit Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Unit

unit: the unit to use

-> m () 

Sets up the transformation for the cairo context obtained from PrintContext in such a way that distances are measured in units of unit.

Since: 2.10

setUseFullPage

printOperationSetUseFullPage Source #

Arguments

:: (HasCallStack, MonadIO m, IsPrintOperation a) 
=> a

op: a PrintOperation

-> Bool

fullPage: True to set up the PrintContext for the full page

-> m () 

If fullPage is True, the transformation for the cairo context obtained from PrintContext puts the origin at the top left corner of the page (which 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).

Since: 2.10

Properties

allowAsync

currentPage

customTabLabel

defaultPageSetup

embedPageSetup

exportFilename

hasSelection

jobName

nPages

nPagesToPrint

printSettings

showProgress

status

statusString

supportSelection

trackPrintStatus

unit

useFullPage

Signals

beginPrint

createCustomWidget

customWidgetApply

done

drawPage

endPrint

paginate

preview

requestPageSetup

statusChanged

updateCustomWidget