@Marcus Ottosson: Awesome!!! I was trying to hack a version that remembers if last window was actually the scriptEditor. Using QtCore.QEvent.ApplicationDeactivate you easily get when you leave Maya. But getting the last window seems tricky!
QtGui.qApp.activeWindow() does not get you anything at that point. QtGui.qApp.topLevelWidgets() is not sorted to have topmost window last or something. cmds.getPanel(withFocus=True) is only sometimes giving you the 'scriptEditorPanel1' :( [wtf?] and cmds.getPanel(underPointer=True) is kind of unreliable :/ my playground so far: http://pastebin.com/ibq7ZBVD I'll try If I'm more happy with brute force scriptEditorPanel activation like that already :] thanks a bunch!!! ëRiC On Friday, October 16, 2015 at 1:29:53 PM UTC+2, Marcus Ottosson wrote: > > Intrigued by the possibility eliminating this minor annoyance, I followed > Justin’s suggestion and wrote a solution. > > Run this, or put it in your userSetup.py, and it will restore focus to the > Script Editor, if it is available. > > from PySide import QtCore, QtGui > class RestoreScriptEditorFocus(QtCore.QObject): > def eventFilter(self, obj, event): > if event.type() != QtCore.QEvent.ApplicationActivate: > return super(RestoreScriptEditorFocus, self).eventFilter(obj, > event) > > script_editor = next(w for w in QtGui.qApp.topLevelWidgets() if > w.objectName() == "scriptEditorPanel1Window") > script_editor.activateWindow() > return True > > f = RestoreScriptEditorFocus() > QtGui.qApp.installEventFilter(f) > > It’ll also “restore” focus to it, even if it wasn’t the last thing to have > focus at the time of leaving the Maya window. Whether that’s a problem or > not is too soon to tell, but I’ll leave the implementation for that to the > reader. > > Enjoy! > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ff5b65a7-ef3d-4df8-885b-c150872baa24%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
