I'm not sure I would consider activeWindow() the "holy grail" since it has
circumstances where it will not return the Maya main window, depending on
how your tool was launched. If it happens to be launched when the main
window does not have focus, or if any other tools are running in top level
windows with focus, it could return None or another window. Even if going
through the shiboken/sip layer is a pain, you can at least be sure you will
instantly find the main window properly even if they rename the object name
to "foo" in the next release.

But if you do want to loop over the existing widgets looking for the
"MayaWindow" object name, you could reduce the number of widgets a great
deal if you use QApplication.topLevelWidgets() instead of allWidgets()



On Tue, Oct 7, 2014 at 4:46 AM, Marcus Ottosson <[email protected]>
wrote:

> That’s brilliant, Fredrik.
>
> I did some tests and it looks like it’s returning the currently active
> window (duh!), which in the case of running from the Script Editor is the
> Script Editor window. Not sure it has any repercussions and shouldn’t be an
> issue when *not* running from the Script Editor.
>
> However, I also tried this.
>
> from PySide import QtGui
> # Returns the Script Editor, sometimes.
> window = QtGui.QApplication.activeWindow()assert window.objectName() == 
> 'scriptEditorPanel1Window'
> # Returns the Maya Window, for sure
> widgets = dict((w.objectName(), w) for w in QtGui.QApplication.allWidgets())
> window = widgets['MayaWindow']
>
> ​
>
> On 6 October 2014 14:35, Fredrik Averpil <[email protected]>
> wrote:
>
>>
>> Then it looks like you just stumbled upon a holy grail. :) Fetching this
>>> handle has always been a PITA and this looks simple and logical. Will be
>>> trying this out next. Thanks!
>>>
>> Nice, let me know how it works. I have only used this with QMainWindow
>> and QDialog. I don't think it will work with QWidget.
>>
>>
>>
>>>  I may be wrong here but I also think exec_() available for
>>> QtGui.QWidget.
>>>
>>> You can see everything it supports here:
>>> http://qt-project.org/doc/qt-4.8/qwidget-members.htm
>>> <http://qt-project.org/doc/qt-4.8/qwidget-members.html>
>>>
>> Ah... so QWidget did not have exec_().
>>
>>  --
>> 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/CAD%3DwhWNV2JDE%3DDxZ1GjjYmYaKsuuTaJCEjsQfXLwud5QgkNAWg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNV2JDE%3DDxZ1GjjYmYaKsuuTaJCEjsQfXLwud5QgkNAWg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Marcus Ottosson*
> [email protected]
>
> --
> 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/CAFRtmOAw_CeoaX3KCrp%3DufRJ5yh%2B3HzUMLyC0y2T%3Dk%2BgZNF_ag%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAw_CeoaX3KCrp%3DufRJ5yh%2B3HzUMLyC0y2T%3Dk%2BgZNF_ag%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAPGFgA3MbMv50%3DWRqjCTX%2BQ96O-MLvG0xaCAE4rjEeb-yQf7cA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to