I know for a fact that this application I’m developing can only be launched
from the Maya/Nuke file menus (or the Maya shelf) by the user.

Until someone would like to extend your tool and try to script it. :) I’d
be careful, this is how tight-coupling is born.
​

On 8 October 2014 09:08, Fredrik Averpil <[email protected]> wrote:

> I second that you should ask the API if you are not 100% certain from
> where you are launching the UI. I know for a fact that this application I’m
> developing can only be launched from the Maya/Nuke file menus (or the Maya
> shelf) by the user. So in this case, it works fine to set the parent of my
> UI to QtGui.QApplication.activeWindow().
> ​
>
> On Tue, Oct 7, 2014 at 10:56 AM, Marcus Ottosson <[email protected]>
> wrote:
>
>> That’s a good point. I suppose the API is less likely to change, than the
>> objectName of the Maya window, which might even have that name set by
>> coincidence as many of Maya’s other widgets don’t have *any* namy, as
>> can be seen by the allWidgets() command.
>> ​
>>
>> On 6 October 2014 20:42, Justin Israel <[email protected]> wrote:
>>
>>> I wouldn't say its a performance thing. It's more just about whether you
>>> want to discover the Maya main window yourself, or be told by the API
>>> exactly where it is. If the objectName will never change, then you will end
>>> up with the same result. If they say in the docs "'MayaWindow' will always
>>> be the name of the main window", then at least you have that guarantee. But
>>> I don't think they do that anywhere.
>>>
>>> On Tue, Oct 7, 2014 at 8:35 AM, Marcus Ottosson <[email protected]>
>>> wrote:
>>>
>>>> QApplication.topLevelWidgets()
>>>>
>>>> Perfect, looks great to me. Why go through a PySide/PyQt-dependent
>>>> extra layer of shiboken/sip wrapping when you could do this? And don’t tell
>>>> me it’s for performance, as this is a one-off. ;)
>>>>
>>>> After all, looping through allWidgets() takes ~0.018 seconds.
>>>>
>>>> start = time.time()
>>>> dict((w.objectName(), w) for w in QtGui.QApplication.allWidgets())print 
>>>> time.time() - start
>>>>
>>>> Whereas topLevelWidgets() takes ~0.002 seconds.
>>>>
>>>> start = time.time()
>>>> dict((w.objectName(), w) for w in 
>>>> QtGui.QApplication.topLevelWidgets())print time.time() - start
>>>>
>>>> ​
>>>>
>>>> On 6 October 2014 21:00, Justin Israel <[email protected]> wrote:
>>>>
>>>>> 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
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3MbMv50%3DWRqjCTX%2BQ96O-MLvG0xaCAE4rjEeb-yQf7cA%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/CAFRtmODQYJfEDQOkAL1K%2BUQQ3eCwaLy4ZsChEsCPEtC%3DYO8%2BXw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODQYJfEDQOkAL1K%2BUQQ3eCwaLy4ZsChEsCPEtC%3DYO8%2BXw%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/CAPGFgA3Xk8kOoHZumsZ%2BRJe7sQzJupMFhWOygBoAJEgNFOH3AA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3Xk8kOoHZumsZ%2BRJe7sQzJupMFhWOygBoAJEgNFOH3AA%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/CAFRtmODW0TQ4D%2B_CvN9gwpKnUQbkwvi27W%2BqSsVMAnbi2d6NeQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODW0TQ4D%2B_CvN9gwpKnUQbkwvi27W%2BqSsVMAnbi2d6NeQ%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/CAD%3DwhWNDR7mgeQN%2BP7%2BR8R9LDdF56oaDRtAvscFQ6yFPdHLa_Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNDR7mgeQN%2BP7%2BR8R9LDdF56oaDRtAvscFQ6yFPdHLa_Q%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/CAFRtmOCTnDUrwLNP6p6N1GhFo6zib97GfMYH8h8HPZTR_bQizw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to