I want to revive this conversation.
I converted the code to PySide2 and its all working fine, but the
event.child() has no object name most of the time.
When I open the Render View for example, the ChildPolished and ChildRemoved
events are triggered but the object name of the child is empty. I tried to
get more information about the child but the child is a QWidget that doesnt
look like the Render View at all.
Is there another way how I can identify which window got opened or close
through the event or event.child?
Here is the code I use. I hooked the eventfilter to a window to remove it
when I close it.
from PySide2 import QtCore, QtWidgets
from shiboken2 import wrapInstance
import maya.OpenMayaUI as mui
def maya_main_window():
main_window_ptr = mui.MQtUtil.mainWindow()
return wrapInstance(int(main_window_ptr),QtWidgets.QWidget)
class RenderViewFilter(QtWidgets.QDialog):
def __init__(self, parent=maya_main_window()):
super(RenderViewFilter, self).__init__(parent)
self.setWindowTitle("Test OnRenderViewOpen")
self.setMinimumSize(200, 100)
self.maya_main_window = parent
self.maya_main_window.installEventFilter(self)
def closeEvent(self, event):
self.maya_main_window.removeEventFilter(self)
def eventFilter(self, obj, event):
if obj == self.maya_main_window:
if event.type() == QtCore.QEvent.Type.ChildPolished:
child = event.child()
print(child)
print("ChildPolished")
print(child.objectName())
if 'renderViewWindow' in child.objectName():
print("OPEN Render View")
if event.type() == QtCore.QEvent.Type.ChildRemoved:
child = event.child()
print(child)
print("ChildRemoved")
print(child.objectName())
if 'renderViewWindow' in child.objectName():
print("CLOSED Render View")
return False
if __name__ == "__main__":
x = RenderViewFilter()
x.show()
I have a script that uses a scriptJob that gives me the hook to the close
and open event on a window, but I also want to make it work with
EventFilters. Here is the code with the scriptJob:
import maya.cmds as cmds
import pymel.core as pm
class WindowWatcher():
def __init__(self):
self.window_name = "renderViewWindow"
self.window_opened = False
def check_for_window_open(self):
if not self.window_opened:
if self.window_name in cmds.lsUI(windows=True):
self.window_opened = True
print("Render Window opened!")
else:
if not self.window_name in cmds.lsUI(windows=True):
self.window_opened = False
print("Render Window Closed!")
if __name__ == "__main__":
render_window_watcher = WindowWatcher()
cmds.scriptJob(event=["idle",
pm.windows.Callback(render_window_watcher.check_for_window_open)])
Sorry if the code is not highlighted I dont really know how to format it :/
[email protected] schrieb am Mittwoch, 12. November 2014 um 09:48:59
UTC+1:
> My mistake in not checking that the constants are also located under that
> Type namespace. Didn't realize that.
> I knew they are all equal, and that I was just using less typing to refer
> to it on the instance. My mistake was trying to suggest that the Type
> namespace was invalid.
>
> On Wed, 12 Nov 2014 12:18 PM Michael Boon <[email protected]> wrote:
>
>> Ugh, sorry, I assumed my response would get threaded. It was a reply to
>> one of Justin's posts.
>>
>> Thanks for everyone's help with this. This group really is priceless.
>>
>>
>> On Wednesday, 12 November 2014 10:15:59 UTC+11, Michael Boon wrote:
>>>
>>> Your code is much more concise but I don't think it will change the
>>> functionality. I think that both forms refer to the same static field of
>>> the class.
>>>
>>> For example:
>>> from PySide import QtCore
>>> event = QtCore.QEvent(QtCore.QEvent.ChildPolished)
>>> QtCore.QEvent.Type.ChildPolished == QtCore.QEvent.ChildPolished #
>>> Result: True #
>>> event.type() == event.ChildPolished # Result: True #
>>> event.ChildPolished == QtCore.QEvent.ChildPolished # Result: True #
>>>
>>>
>>>
>>>
>>> On Monday, 10 November 2014 18:39:30 UTC+11, Justin Israel wrote:
>>>>
>>>> You seem to have only made a partial change from my other suggestion. I
>>>> had suggested using event.ChildRemove, yet you have kept that extra .Type.
>>>> bit in there. Isn't that giving you an error about not existing?
>>>>
>>>>
>>>> On Mon Nov 10 2014 at 8:34:20 PM Marcus Ottosson <[email protected]>
>>>> wrote:
>>>>
>>>>> Is that the full code? I can't see where you're installing the filter.
>>>>> Don't forget to run installEventFilter() on the target object.
>>>>>
>>>>> Have a look at this example.
>>>>> https://gist.github.com/mottosso/ce114dfe4a264b52e235
>>>>>
>>>>> On 10 November 2014 07:29, Arvid Schneider <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Thanks for all the help!
>>>>>> But dont get an error now. But its still not working.
>>>>>>
>>>>>>
>>>>>> class HyperShadeEventFilter(QtCore.QObject):
>>>>>> def __init__(self):
>>>>>> super(HyperShadeEventFilter, self).__init__()
>>>>>> ptr = mui.MQtUtil.mainWindow()
>>>>>> mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget)
>>>>>> mainWin.installEventFilter(self)
>>>>>>
>>>>>> def eventFilter(self, object, event):
>>>>>> print event.type()
>>>>>> if event.type() == event.Type.ChildPolished:
>>>>>> child = event.child()
>>>>>> print child.objectName()
>>>>>> if 'hyperShadePanel' in child.objectName():
>>>>>> print 'OPEN'
>>>>>> elif event.type() == event.Type.ChildRemoved:
>>>>>> child = event.child()
>>>>>> if 'hyperShadePanel' in child.objectName():
>>>>>> print 'CLOSE'
>>>>>> HyperShadeEventFilter()
>>>>>>
>>>>>> --
>>>>>> 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/45b59ddf-16ce-4434-a356-
>>>>>> 0d1179bb6114%40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/45b59ddf-16ce-4434-a356-0d1179bb6114%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/CAFRtmODwawJi0dKjmBa%
>>>>> 3DqGnwgffbzTs9MPXX1MO9g1pQAPNodA%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODwawJi0dKjmBa%3DqGnwgffbzTs9MPXX1MO9g1pQAPNodA%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/bf5fd23f-a645-4d21-8dfa-f51c2b7e8c70%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/python_inside_maya/bf5fd23f-a645-4d21-8dfa-f51c2b7e8c70%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/c415af53-0f4c-49bd-bf84-021f6ddd3cf2n%40googlegroups.com.