1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Asynchronous operations</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="chapter-printing.html" title="Chapter 21. Printing">
<link rel="prev" href="sec-printing-rendering-text.html" title="Rendering text">
<link rel="next" href="sec-printing-export-to-pdf.html" title="Export to PDF">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Asynchronous operations</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-printing-rendering-text.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 21. Printing</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-printing-export-to-pdf.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-async-printing-ops"></a>Asynchronous operations</h2></div></div></div>
<p>
By default, <code class="methodname">PrintOperation::run()</code> returns when a print
operation is completed. If you need to run a non-blocking print operation,
call <code class="methodname">PrintOperation::set_allow_async()</code>. Note that <code class="methodname">set_allow_async()</code> is not supported
on all platforms, however the <code class="literal">done</code> signal will still be emitted.
</p>
<p>
<code class="methodname">run()</code> may return
<code class="literal">PrintOperation::Result::IN_PROGRESS</code>. To track status
and handle the result or error you need to implement signal handlers for
the <code class="literal">done</code> and <code class="literal">status_changed</code> signals:
</p>
<p>For instance,</p>
<pre class="programlisting"><code class="code">// in class ExampleWindow's method...
auto op = PrintOperation::create();
// ...set up op...
op->signal_done().connect(sigc::bind(sigc::mem_fun(
*this, &ExampleWindow::on_printoperation_done), op));
// run the op
</code></pre>
<p>Second, check for an error and connect to the <code class="literal">status_changed</code> signal. For instance:
</p>
<pre class="programlisting"><code class="code">void ExampleWindow::on_printoperation_done(Gtk::PrintOperation::Result result,
const Glib::RefPtr<PrintOperation>& op)
{
if (result == Gtk::PrintOperation::Result::ERROR)
//notify user
else if (result == Gtk::PrintOperation::Result::APPLY)
//Update PrintSettings with the ones used in this PrintOperation
if (! op->is_finished())
op->signal_status_changed().connect(sigc::bind(sigc::mem_fun(
*this, &ExampleWindow::on_printoperation_status_changed), op));
}
</code></pre>
<p>Finally, check the status. For instance,</p>
<pre class="programlisting"><code class="code">void ExampleWindow::on_printoperation_status_changed(const Glib::RefPtr<PrintOperation>& op)
{
if (op->is_finished())
//the print job is finished
else
//get the status with get_status() or get_status_string()
//update UI
}
</code></pre>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-printing-rendering-text.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-printing.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-printing-export-to-pdf.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Rendering text </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Export to PDF</td>
</tr>
</table>
</div>
</body>
</html>
|