<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 27, 2014 at 7:39 AM, Stefano Borini <span dir="ltr"><<a href="mailto:stefano.borini@ferrara.linux.it" target="_blank">stefano.borini@ferrara.linux.it</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"><br>
with contextlib.context(enter=None, exit=lambda *args: my_widget.setFocus()):<br>
do what I need to do<br>
</blockquote></div><br></div><div class="gmail_extra">You can easily define your own context manager to do what you want:<br><br> @contextmanager<br> def finally_focus(widget):<br> try:<br> yield<br> finally:<br> widget.setFocus()<br><br></div><div class="gmail_extra"> with finally_focus(my_widget):<br>
# do what I need to do<br>
<br clear="all"><br>-- <br><div class="gmail_signature"><span style="color:rgb(0,102,0)">Juancarlo </span><b style="color:rgb(0,102,0)">Añez</b></div>
</div></div>