On Mon Nov 10 2014 at 8:24:20 PM Marcus Ottosson <[email protected]>
wrote:

> You’ll need to call the __init__ method of the object’s baseclass.
>
Jinx. Buy me a coke.

>     def __init__(self):
>         super(HyperShadeEventFilter, self).__init__()
>         ptr = mui.MQtUtil.mainWindow()
>         mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget)
>         mainWin.installEventFilter(self)
>
> ​
>
> On 10 November 2014 07:10, Arvid Schneider <[email protected]>
> wrote:
>
>> Still getting the same error-.
>>
>> // Error: '__init__' method of object's base class
>> (HyperShadeEventFilter) not called.
>> # Traceback (most recent call last):
>> # File "<maya console>", line 22, in <module>
>> # File "<maya console>", line 10, in __init__
>> # RuntimeError: '__init__' method of object's base class
>> (HyperShadeEventFilter) not called. //
>>
>>
>>
>> On Monday, November 10, 2014 5:16:16 AM UTC+1, Justin Israel wrote:
>>>
>>> Replace: QtCore.QEvent.Type.ChildPolished
>>> with : event.ChildPolished
>>>
>>> Replace: QtCore.QEvent.Type.ChildRemoved
>>> with: event.ChildRemoved
>>>
>>> On Mon, 10 Nov 2014 1:11 PM Arvid Schneider <[email protected]>
>>> wrote:
>>>
>>>> Could you please help me out further. I cant even install the event
>>>> filter with the hypershade.
>>>>
>>>> import maya.OpenMayaUI as mui
>>>> import shiboken
>>>> from PySide import QtGui
>>>> from PySide import QtCore
>>>>
>>>> class HyperShadeEventFilter(QtCore.QObject):
>>>>     def __init__(self):
>>>>
>>>>         ptr = mui.MQtUtil.mainWindow()
>>>>         mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget)
>>>>         mainWin.installEventFilter(self)
>>>>
>>>>
>>>>     def eventFilter(self, object, event):
>>>>
>>>>         if event.type() == QtCore.QEvent.Type.ChildPolished:
>>>>             child = event.child()
>>>>
>>>>             if 'renderViewWindow' in child.objectName():
>>>>                 print 'OPEN'
>>>>
>>>>         elif event.type() == QtCore.QEvent.Type.ChildRemoved:
>>>>             child = event.child()
>>>>
>>>>             if 'renderViewWindow' in child.objectName():
>>>>                 print 'CLOSE'
>>>> HyperShadeEventFilter()
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Thursday, November 6, 2014 11:45:51 AM UTC+1, Arvid Schneider wrote:
>>>>>
>>>>> Weird, thats what I did. I ll check into that later.
>>>>> Thanks though :)
>>>>>
>>>>> On Thursday, November 6, 2014 2:25:13 AM UTC+1, Michael Boon wrote:
>>>>>>
>>>>>> In the __init__ of that class, something like this:
>>>>>>     ptr = mui.MQtUtil.mainWindow()
>>>>>>     mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget)
>>>>>>     mainWin.installEventFilter(self)
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thursday, 6 November 2014 11:44:56 UTC+11, Arvid Schneider wrote:
>>>>>>>
>>>>>>> Hey Michael,
>>>>>>>
>>>>>>> how did you install the eventFilter on the MayaMainWindow?
>>>>>>>
>>>>>>>
>>>>>>> On Tuesday, November 4, 2014 4:43:41 AM UTC+1, Michael Boon wrote:
>>>>>>>>
>>>>>>>> Thanks very much.
>>>>>>>>
>>>>>>>> I think I have the basic concept working now.
>>>>>>>>
>>>>>>>> To get a callback when the Hypershade is opened and closed, I've
>>>>>>>> installed an eventFilter on the Maya main window, something like this:
>>>>>>>>     class HyperShadeEventFilter(QtCore.QObject):
>>>>>>>>         def eventFilter(self, object, event):
>>>>>>>>             if event.type() == QtCore.QEvent.Type.ChildPolished:
>>>>>>>>                 child = event.child()
>>>>>>>>                 if 'hyperShadePanel' in child.objectName():
>>>>>>>>                     doStuff()
>>>>>>>>             elif event.type() == QtCore.QEvent.Type.ChildRemoved:
>>>>>>>>                 child = event.child()
>>>>>>>>                 if 'hyperShadePanel' in child.objectName():
>>>>>>>>                     doStuff()
>>>>>>>>
>>>>>>>> (I didn't see any events occurring on the QApplication.)
>>>>>>>>
>>>>>>>>
>>>>>>>> On Monday, 3 November 2014 12:12:08 UTC+11, Justin Israel wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, Nov 3, 2014 at 1:29 PM, Michael Boon <[email protected]>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> four questions below...
>>>>>>>>>>
>>>>>>>>>> I'm looking to add some buttons and menus to the Hypershade. I'm
>>>>>>>>>> new to working with the existing Maya UI so maybe I'm doing this all 
>>>>>>>>>> wrong.
>>>>>>>>>>
>>>>>>>>>> This is the best way I've found to get the Hypershade window:
>>>>>>>>>>     p = pm.getPanel(scriptType='hyperShadePanel')
>>>>>>>>>>     assert len(p) == 1
>>>>>>>>>>     hypershade = p[0].getControl()
>>>>>>>>>>
>>>>>>>>>> I'd read that the Maya UI was all Qt now, but this method gets me
>>>>>>>>>> a pymel.core.uitypes.Panel. *Is Hypershade built in Qt?*
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Correct. The whole UI is a bit Qt application.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> To get individual layouts, the only way I've found is to know the
>>>>>>>>>> structure in advance. For example:
>>>>>>>>>>     mainForm = pm.layout(hypershade, query=True,
>>>>>>>>>> childArray=True)[0]
>>>>>>>>>>     assert mainForm.lower() == 'mainform'
>>>>>>>>>>
>>>>>>>>>> That all seems pretty delicate. *Is there a more robust way to
>>>>>>>>>> get (for example) the toolbar at the top of Hypershade?*
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Either way, this whole thing will be delicate, since playing with
>>>>>>>>> and manipulating Maya's own application structure can be unstable. 
>>>>>>>>> Some of
>>>>>>>>> the safer things you can do are docking your own widgets, or adding 
>>>>>>>>> to the
>>>>>>>>> main menu. But if you modify temporary windows or try to rely on 
>>>>>>>>> finding
>>>>>>>>> child widgets, you are at the mercy of whatever changes Autodesk 
>>>>>>>>> makes in
>>>>>>>>> the future, or for any undocumented behaviour to occur and undo or 
>>>>>>>>> mix up
>>>>>>>>> what you do.
>>>>>>>>>
>>>>>>>>> That being said, you can get the Qt reference to components within
>>>>>>>>> the application. What you are getting so far is just the Maya native 
>>>>>>>>> UI
>>>>>>>>> stuff, that aligns with the commands/mel api. So even though the UI 
>>>>>>>>> is in
>>>>>>>>> Qt, they have an abstraction over it and maintains the compatibility 
>>>>>>>>> of the
>>>>>>>>> native UI interface, which has a more limited exposure.
>>>>>>>>>
>>>>>>>>> Something like this would allow you to get the reference to the
>>>>>>>>> hypershade dialog, and to inspect its children:
>>>>>>>>>
>>>>>>>>> import maya.OpenMayaUI as muifrom PySide import QtGui, QtCoreimport 
>>>>>>>>> shiboken
>>>>>>>>>
>>>>>>>>> p = cmds.getPanel(scriptType='hyperShadePanel')
>>>>>>>>> ptr = mui.MQtUtil.findControl(p[0])
>>>>>>>>> dlg = shiboken.wrapInstance(ptr, QtGui.QDialog)
>>>>>>>>> dlg.findChildren(QtGui.QMenuBar)
>>>>>>>>>
>>>>>>>>> ​
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> To make all that actually work, I would need to do it each time
>>>>>>>>>> the Hypershade opens. *Can I get a callback when the Hypershade
>>>>>>>>>> window is opened? *I can't see any MMessage or callback that
>>>>>>>>>> would tell me.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I think a similar question was asked in the last week or two?
>>>>>>>>> Someone was asking for a way to know when some other window was 
>>>>>>>>> opened, to
>>>>>>>>> be able to hook into it. As far as I know, there isn't an official API
>>>>>>>>> approach to knowing when a specific window is opened or closed, and it
>>>>>>>>> might require an event filter on the QApplication itself, to watch for
>>>>>>>>> QShowEvents, and then checking the objectName()
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> And finally, *is there any good help on MMessage anywhere?* The
>>>>>>>>>> Autodesk help is a decent reference, if you already know what you 
>>>>>>>>>> can do.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>> Boon
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 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/460c6e3
>>>>>>>>>> 4-1e31-45d2-913f-31d1dde1f880%40googlegroups.com
>>>>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/460c6e34-1e31-45d2-913f-31d1dde1f880%40googlegroups.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/78a82075-e02f-48a4-8c3c-
>>>> 547c27ba4a77%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/python_inside_maya/78a82075-e02f-48a4-8c3c-547c27ba4a77%40googlegroups.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/92306db8-5990-4b51-979c-bdf5c50f5af8%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/92306db8-5990-4b51-979c-bdf5c50f5af8%40googlegroups.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/CAFRtmOCCV3SSdC-fK_U%2BOUZm%2ByogFuV40bd6Y-HkxyTbBm6GqQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCCV3SSdC-fK_U%2BOUZm%2ByogFuV40bd6Y-HkxyTbBm6GqQ%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/CAPGFgA2UCEz9EFbTQSZ8a3M2muoiR_Mz%3DR1Vo84B7n9ZwUSeCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to