How to get the widget currently with focus in maya with pyqt?

I want to detect if script editor has focus. But

getPanel -wf

returns a modelPanel when cursor is still blinking in script editor. Unless I click on anywhere on script editor toolbar, even an empty spot works, you can see the white rect goes away around the modelpanel viewport. then the above command returns “scriptEditorPanel1”.

How to reproduce the “bug”:

click on any viewport first so it has focus, then go to script editor,
[ul]
[li] if you run the command with ctrl+enter, it returns modelPanel4 because the focus widget is still that.
[/li][li] if you click the “Execute all” toolbar button on script editor, it returns “scriptEditorPanel1” because now focus is on script editor
[/li][/ul]

Is this a bug?
My system is fedora 13, KDE4, maya 2015

I think this is legitimately a feature, otherwise you could never obtain the name of a widget in interactive mode. Since the editor window is itself a widget, I’m going to guess that they do some extra work to prevent getPanel from always returning scriptEditorPanel1.

EDIT: “extra work” being allowing the panel to be used while not yanking focus.