Re: [gedit-list] First pass hack of gedit and gtksourceview port to gtkprintoperation



Hi 

> I'm not sure what is the best way to avoid problems with pagination
> blocking the ui for a long time. Alex opened a bug about allowing
rendering
> to happen in a thread.
> 

What about adding a "paginator" interface that programs must/can
implement? 
A "paginator" emits signals while proceeding, this signal can be used by
gtk+ or by the program itself to show a progress bar or similar UI
element.

The GtkPrintPaginator interface should emit three signals:

- begin_page (GtkPrintPaginator *p): emitted when starting to paginate a
new page
- finished (GtkPrintPaginator *p): emitted when pagination ends
- canceled (GtkPrintPaginator *p): if pagination is canceled

The interface should have at least the following methods:

- setup: to pass the GtkPrintContext, GtkPageSetup and GtkPrintSettings
(may other info are needed for the pagination too)
- paginate: to start pagination
- cancel: to cancel pagination
- get_page: returns the number of the page being paginated
- get_page_count: determines the total number of pages the job will
print; the returned value is only meaningful after pagination has
finished.

We can then add the following operations to GtkPrintOperation:

    void gtk_print_operation_set_paginator (GtkPrintOperation *op, 
                                            GtkPrintPaginator *p);

    void gtk_print_operation_set_show_pagination_progress 
                                 (GtkPrintOperation *op,
                                  gboolean           show_progress);
                                  
If the paginator is set, the GtkPrintPaginator is used to paginate, i.e.
before emitting the "begin-print" signal (or may be instead of emitting
the signal)
GtkPrintOperation first setup the paginator calling the "setup" method
and then start the pagination
calling the "paginate" method.
When pagination finished, the print operation continues like in the
current code.
If pagination is canceled, then the print operation emits a
"print-canceled" signal and terminates.

If "show_pagination_progress" is true then gtk+ show a dialog with the
progress bar showing the
pagination progress.

Using gtk_print_operation_run_async  together with a paginator that
paginates in an async way (for example
inside a idle handler as we do in GtkSourceView), I think it can be
possible to avoid problems with pagination
blocking the ui for a long time without using threads.

Ciao,
Paolo

P.S. While I am at it, I'd like to point out the current print API does
not allow to add custom print ranges to the print dialog. In gedit, for
example, we allow users to print from "line X to line Y".




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]