
On Thu, 27 Nov 2014 23:30:40 +1100 Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Nov 27, 2014 at 11:09 PM, Stefano Borini <stefano.borini@ferrara.linux.it> wrote:
I have a situation where, no matter how the routine ends, I need to return the focus to a widget. It would be rather clever to do this with a context, but I would expect something like this to be a possible strategy
with contextlib.context(enter=None, exit=lambda *args: my_widget.setFocus()): do what I need to do
as far as I know, at the moment it's not possible. Am I right? I think it would be an easy and practical addition to the contextlib module to quickly register two routines for enter and exit.
You could abuse try/finally for this purpose.
Or just use it, since it's a normal use of try/finally ;-) Regards Antoine.
try: whatever you need to do finally: my_widget.setFocus()
ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/