On Windows systems using Autodesk Maya, the text input field of the Script Editor doesn't regain focus after having restored focus to the main window. This event handler explicitly restores focus, if it turns out to have been the last active panel at the time of leaving the application.
Place the full contents of the script below into your userSetup.py
and never again lose focus.
Tested on Maya 2013-2016+ and is safe to use on other platforms where it simply does nothing.
- 2016-09-01: Updated with a fix for Maya 2017; thanks @martin-chatterjee!
For the sake of completeness: my previous comment was rubbish, sorry about that... :(
For this to work you also need to:
have import statements that try to import PySide2 (--> Maya2017) and fallback to importing PySide.
change QtGui.qApp to QtWidgets.qApp (as in PySide2 qApp now lives inside QtWidgets)
Link to my forked and updated Gist: https://gist.github.com/martin-chatterjee/7759bdc0a877424542afc7bc1db06b07