<div dir="ltr"><div><div><div><div>Hi Piotr,<br><br></div>Arve and I meant to keep the discussion on the list, but I sometimes forgot to reply to the list address and instead replied directly.  The full thread is reproduced below.<br><br></div>FYI, if you just want a resumable slot function and you don't care about futures or anything else in asyncio, it can be done using generator expressions (see attached file for an example, or contents pasted in at the very end of this email).<br><br></div>Cheers,<br></div>Erik<br><div><div><div><div><div><div><div><div style="margin-left:40px"><br>Hi!<br>
<br>
I found your post titled "Integrating asyncio with Qt event loop?" at<br>
<a href="http://www.riverbankcomputing.com/pipermail/pyqt/2014-August/034628.html" target="_blank">http://www.riverbankcomputing.com/pipermail/pyqt/2014-August/034628.html</a><br>
but looking at quotes inside the post it seems to be continuation of<br>
earlier discussion. I would like to know where this discussion took<br>
place. Could you please point me to it?<br>
<br>
Thank you in advance.<br>
<br>
Regards,<br>
Piotr<br></div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Erik Hvatum</b> <span dir="ltr"><<a href="mailto:ice.rikh@gmail.com">ice.rikh@gmail.com</a>></span><br>Date: Thu, Aug 7, 2014 at 5:13 PM<br>Subject: Re: [PyQt] Integrating asyncio with Qt event loop?<br>To: Arve Knudsen <<a href="mailto:arve.knudsen@gmail.com">arve.knudsen@gmail.com</a>>, "<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>" <<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>><br><br><br><div dir="ltr"><div><div>Brilliant!  Works like a charm; <a href="https://github.com/erikhvatum/zplab/blob/68328cb37289bdf94ae0b10d4dc5e9583578934d/acquisition/dm6000b/function_units/objective_turret.py" target="_blank">our code</a> is going to get a lot cleaner.<br>
<br></div>Tusen takk,<br></div>Erik<br></div><div class=""><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 7, 2014 at 4:29 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Erik<div><br></div><div>I think you could use an asyncio.Future for this purpose. You can yield from the Future, and set its result upon arrival of the signal. I've concocted an example program that should show what I mean; it creates a 2-second timer which is waited on asynchronously, once its timeout fires the program exits:<br>

<br></div><div><div>    import quamash</div><div>    import asyncio</div><div>    from PyQt5.QtWidgets import *</div><div>    from PyQt5.QtCore import *</div><div><br></div><div><br></div><div>    @asyncio.coroutine</div>

<div>    def _go():</div><div>        def on_timeout():</div><div>            print('Timeout')</div><div>            fut.set_result(True)</div><div><br></div><div>        fut = asyncio.Future()</div><div>        timer = QTimer()</div>

<div>        timer.setSingleShot(True)</div><div>        timer.setInterval(2000)</div><div>        timer.start()</div><div>        timer.timeout.connect(on_timeout)</div><div>        print('Yielding until signal...')</div>

<div>        yield from fut</div><div>        print('Continuing execution after yield from')</div><div><br></div><div>    with quamash.QEventLoop(app=QApplication([])) as loop:</div><div>        w = QMainWindow()</div>

<div>        w.show()</div><div>        loop.run_until_complete(_go())</div><div>    print('Coroutine has ended')</div></div><div><br></div><div>HTH,</div><div>Arve</div></div><div><div>
<div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Aug 7, 2014 at 12:31 AM, Erik Hvatum <span dir="ltr"><<a href="mailto:ice.rikh@gmail.com" target="_blank">ice.rikh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div dir="ltr"><div><div><div><div>Thank you :)<br><br></div>A quick question to help as I dig into 
this: how might one go about "yield from wait_for_a_qt_signal"?  That 
is, I want my coroutine to resume execution when some certain signal is 
emitted.  Perhaps this desire indicates that I'm going about things the 
wrong way...<br><br></div>-Erik<br><br></div></div>PS: forgot to reply to the list the first time around<br></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 5, 2014 at 12:34 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Quamash, in the unix branch (<a href="https://github.com/aknuds1/quamash/tree/unix" target="_blank">https://github.com/aknuds1/quamash/tree/unix</a>), now works perfectly for thread and subprocess execution on OS X, Linux and Windows, I'm pleased to say. Would love some feedback.<span><font color="#888888"><div>



<br></div><div>Arve</div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 3:12 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Now, even subprocess execution works. At least on Windows/PyQt, haven't tested on other platforms.<span><font color="#888888"><div>



<br></div><div>Arve</div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 30, 2014 at 4:03 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Erik, Tamás, feel free to try my <a href="https://github.com/aknuds1/quamash" target="_blank">Quamash fork</a>, it's currently quite functional, except that subprocess execution is somehow broken.<span><font color="#888888"><div>




<br>
</div><div>Arve</div></font></span><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 27, 2014 at 1:34 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>






<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">My fork is now semi-functional with Python 3.4 and PyQt 5. I can at least perform simple asynchronous tasks within a Qt application, but lots remain to implement.<span><font color="#888888"><div>






<br><div>Arve</div></div></font></span></div><div class="gmail_extra">
<br><br><div class="gmail_quote"><div>On Fri, Jun 27, 2014 at 9:24 AM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br></div>
<div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">I've created a fork on GitHub: <a href="https://github.com/aknuds1/quamash" target="_blank">https://github.com/aknuds1/quamash</a>. Do you know where to locate information on writing an asyncio event loop though? Not sure where to begin.<div>








<br></div><div>Thanks,</div><div>Arve</div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 9:30 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>








<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks. I'm thinking I might try to modify his code, if it isn't too much work.<span><font color="#888888"><div>








<br></div><div>Arve</div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 7:32 PM, Tamás Bajusz <span dir="ltr"><<a href="mailto:gbtami@gmail.com" target="_blank">gbtami@gmail.com</a>></span> wrote:<br>









<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Unfortunately, I know that github project only. (<a href="https://github.com/harvimt/quamash" target="_blank">https://github.com/harvimt/quamash</a>)<br>









</div>Try to contact him at <a href="mailto:mark.harviston%40gmail.com" target="_blank">mark.harviston@gmail.com<br>
</a></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 7:27 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br>










<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Tamás, has Mark Harviston's implementation been updated to work with the latest Python (3.4)? I think I read somewhere that it's based on an outdated API.</div>










<span><font color="#888888"><div><br></div><div>Arve</div></font></span><div><div><div class="gmail_extra">
<br><div class="gmail_quote">On Thu, Jun 26, 2014 at 6:29 PM, Tamás Bajusz <span dir="ltr"><<a href="mailto:gbtami@gmail.com" target="_blank">gbtami@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">











<div dir="ltr"><a href="http://haypo-notes.readthedocs.org/asyncio.html#replacing-the-event-loop" target="_blank">http://haypo-notes.readthedocs.org/asyncio.html#replacing-the-event-loop</a></div><div class="gmail_extra">











<br><br><div class="gmail_quote"><div><div>
On Thu, Jun 26, 2014 at 5:20 PM, Arve Knudsen <span dir="ltr"><<a href="mailto:arve.knudsen@gmail.com" target="_blank">arve.knudsen@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">











<div><div>
<div dir="ltr">Hi guys<div><br></div><div>I am looking to integrate Python 3.4 <a href="https://docs.python.org/3/library/asyncio.html" target="_blank">asyncio</a> with Qt's event loop (via PyQt 5), specifically in order to asynchronously monitor output (stdout/stderr) from a child process. Maybe this is somewhat off-topic for this list, but can someone tell me if such integration exists (and works)?</div>













<div><br></div><div>Thanks,</div><div>Arve</div></div>
<br></div></div>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></div>

<div style="color:rgb(0,0,0);background-color:rgb(245,245,245);font-style:normal;font-weight:normal;text-decoration:none">
<pre><span style="color:rgb(0,128,0)">#!/usr/bin/env python3</span>

<span style="color:rgb(0,128,0)"># By Erik Hvatum, 2014.  Copyright waived; the contents of this file represent a trivial example, are public</span>
<span style="color:rgb(0,128,0)"># domain, and may be used for any purpose and/or relicensed without attribution.</span>


<span style="color:rgb(128,0,128)">from</span><span> </span><span>PyQt5</span><span> </span><span style="color:rgb(128,0,128)">import</span><span> </span><span>Qt</span>

<span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">coroutine</span><span>(</span><span>func</span><span>):</span>
<span>    </span><span style="color:rgb(0,128,128)">'''This is meant to act as a decorator.  Its purpose is to call next once for you upon instantiation of</span>
<span style="color:rgb(0,128,128)">    a generator so that you don't have to.  If you want separate instantiation and execution, for example</span>
<span style="color:rgb(0,128,128)">    because you wish to make a generator and kick it off later, don't use this.'''</span>
<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">start</span><span>(</span><span>*</span><span>args</span><span>,</span><span> </span><span>**</span><span>kwargs</span><span>):</span>
<span>        </span><span>cr</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,0,176)">func</span><span>(</span><span>*</span><span>args</span><span>,</span><span> </span><span>**</span><span>kwargs</span><span>)</span>
<span>        </span><span style="color:rgb(0,0,176)">next</span><span>(</span><span>cr</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">return</span><span> </span><span>cr</span>
<span>    </span><span style="color:rgb(128,0,128)">return</span><span> </span><span>start</span>

<span style="color:rgb(128,0,128)">class</span><span> </span><span style="color:rgb(0,0,176)">Dlg</span><span>(</span><span>Qt</span><span>.</span><span>QDialog</span><span>):</span>
<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,255)">__init__</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span style="color:rgb(0,0,176)">super</span><span>().</span><span style="color:rgb(0,0,255)">__init__</span><span>()</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">setAttribute</span><span>(</span><span>Qt</span><span>.</span><span>Qt</span><span>.</span><span>WA_DeleteOnClose</span><span>)</span>

<span>        </span><span>l</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QHBoxLayout</span><span>()</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">setLayout</span><span>(</span><span>l</span><span>)</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,0,255)">None</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation_step_count</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,78,130)">5</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation_step_time</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,78,130)">2</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QTimer</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer</span><span>.</span><span style="color:rgb(0,0,176)">setSingleShot</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer</span><span>.</span><span>timeout</span><span>.</span><span style="color:rgb(0,0,176)">connect</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer_fired_slot</span><span>)</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QPushButton</span><span>(</span><span style="color:rgb(0,128,128)">'start'</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span>clicked</span><span>.</span><span style="color:rgb(0,0,176)">connect</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button_clicked_slot</span><span>)</span>
<span>        </span><span>l</span><span>.</span><span style="color:rgb(0,0,176)">addWidget</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>)</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QPushButton</span><span>(</span><span style="color:rgb(0,128,128)">'abort'</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span>.</span><span>clicked</span><span>.</span><span style="color:rgb(0,0,176)">connect</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button_clicked_slot</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">False</span><span>)</span>
<span>        </span><span>l</span><span>.</span><span style="color:rgb(0,0,176)">addWidget</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span>)</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>status_label</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QLabel</span><span>(</span><span style="color:rgb(0,128,128)">'ready to start'</span><span>)</span>
<span>        </span><span>l</span><span>.</span><span style="color:rgb(0,0,176)">addWidget</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>status_label</span><span>)</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">show</span><span>()</span>

<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">do_button_clicked_slot</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span style="color:rgb(128,0,128)">is</span><span> </span><span style="color:rgb(0,0,255)">None</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span>=</span><span> </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span style="color:rgb(0,0,176)">resumable_operation_proc</span><span>()</span>
<span>            </span><span style="color:rgb(0,128,0)"># Because resumable_operation_proc has the @coroutine decorator, self.resumable_operation.next() has</span>
<span>            </span><span style="color:rgb(0,128,0)"># been called and resumable_operation_proc is now executing</span>
<span>        </span><span style="color:rgb(128,0,128)">else</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span>.</span><span style="color:rgb(0,0,176)">send</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>

<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">abort_button_clicked_slot</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span style="color:rgb(128,0,128)">try</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span style="color:rgb(128,0,128)">is</span><span> </span><span style="color:rgb(128,0,128)">not</span><span> </span><span style="color:rgb(0,0,255)">None</span><span>:</span>
<span>                </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span>.</span><span style="color:rgb(0,0,176)">send</span><span>(</span><span style="color:rgb(0,0,255)">False</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">except</span><span> </span><span>StopIteration</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">pass</span>

<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">do_timer_fired_slot</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span style="color:rgb(128,0,128)">try</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span style="color:rgb(128,0,128)">is</span><span> </span><span style="color:rgb(128,0,128)">not</span><span> </span><span style="color:rgb(0,0,255)">None</span><span>:</span>
<span>                </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span>.</span><span style="color:rgb(0,0,176)">send</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">except</span><span> </span><span>StopIteration</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">pass</span>

<span>    @</span><span>coroutine</span>
<span>    </span><span style="color:rgb(128,0,128)">def</span><span> </span><span style="color:rgb(0,0,176)">resumable_operation_proc</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>):</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span style="color:rgb(0,0,176)">setText</span><span>(</span><span style="color:rgb(0,128,128)">'next step'</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>

<span>        </span><span>step</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,78,130)">1</span>
<span>        </span><span style="color:rgb(128,0,128)">while</span><span> </span><span style="color:rgb(0,0,255)">True</span><span>:</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">False</span><span>)</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>status_label</span><span>.</span><span style="color:rgb(0,0,176)">setText</span><span>(</span><span style="color:rgb(0,128,128)">'doing step {}'</span><span>.</span><span style="color:rgb(0,0,176)">format</span><span>(</span><span>step</span><span>))</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer</span><span>.</span><span style="color:rgb(0,0,176)">start</span><span>(</span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation_step_time</span><span> </span><span>*</span><span> </span><span style="color:rgb(0,78,130)">1000</span><span>)</span>

<span>            </span><span>keep_going</span><span> </span><span>=</span><span> </span><span style="color:rgb(128,0,128)">yield</span>
<span>            </span><span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(128,0,128)">not</span><span> </span><span>keep_going</span><span> </span><span style="color:rgb(128,0,128)">or</span><span> </span><span>step</span><span> </span><span>==</span><span> </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation_step_count</span><span>:</span>
<span>                </span><span style="color:rgb(128,0,128)">break</span>
<span>            </span><span>step</span><span> </span><span>+</span><span>=</span><span> </span><span style="color:rgb(0,78,130)">1</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>
<span>            </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>status_label</span><span>.</span><span style="color:rgb(0,0,176)">setText</span><span>(</span><span style="color:rgb(0,128,128)">'ready for step {}'</span><span>.</span><span style="color:rgb(0,0,176)">format</span><span>(</span><span>step</span><span>))</span>
<span>            </span><span>keep_going</span><span> </span><span>=</span><span> </span><span style="color:rgb(128,0,128)">yield</span>
<span>            </span><span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(128,0,128)">not</span><span> </span><span>keep_going</span><span>:</span>
<span>                </span><span style="color:rgb(128,0,128)">break</span>

<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_timer</span><span>.</span><span style="color:rgb(0,0,176)">stop</span><span>()</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span style="color:rgb(0,0,176)">setText</span><span>(</span><span style="color:rgb(0,128,128)">'start'</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>do_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">True</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>abort_button</span><span>.</span><span style="color:rgb(0,0,176)">setEnabled</span><span>(</span><span style="color:rgb(0,0,255)">False</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>status_label</span><span>.</span><span style="color:rgb(0,0,176)">setText</span><span>(</span><span style="color:rgb(0,128,128)">'ready to start'</span><span>)</span>
<span>        </span><span style="color:rgb(128,0,128)">self</span><span>.</span><span>resumable_operation</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,0,255)">None</span>

<span style="color:rgb(128,0,128)">if</span><span> </span><span style="color:rgb(0,0,255)">__name__</span><span> </span><span>==</span><span> </span><span style="color:rgb(0,128,128)">'__main__'</span><span>:</span>
<span>    </span><span style="color:rgb(128,0,128)">import</span><span> </span><span style="color:rgb(0,0,255)">sys</span>
<span>    </span><span>app</span><span> </span><span>=</span><span> </span><span>Qt</span><span>.</span><span style="color:rgb(0,0,176)">QApplication</span><span>(</span><span style="color:rgb(0,0,255)">sys</span><span>.</span><span style="color:rgb(0,0,255)">argv</span><span>)</span>
<span>    </span><span>dlg</span><span> </span><span>=</span><span> </span><span style="color:rgb(0,0,176)">Dlg</span><span>()</span>
<span>    </span><span>app</span><span>.</span><span style="color:rgb(0,0,176)">exec_</span><span>()</span></pre></div>


</div></div></div></div></div></div></div></div>