Hi Marcus, this was just a temp name. The handler is now called as an instance in my main class. And it works really smooth. Thanks again you guys. This group is priceless!
On Monday, November 10, 2014 9:26:03 AM UTC+1, Marcus Ottosson wrote: > > You’re very welcome, but something is not right. > > Handler is the event filter, yet HyperShadeEventFilter is named > “eventfilter”. What is HyperShadeEventFilter doing? You can remove it, > and instead do this. > > eventfilter = Handler() > mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget) > mainWin.installEventFilter(eventfilter) > > When run from Maya, Maya will keep eventfilter alive, as it does with all > local variables. In a standalone application, this would probably have to > be wr > > > On 10 November 2014 08:05, Arvid Schneider <[email protected] > <javascript:>> wrote: > >> SO.. finally. >> Got it to works. Thanks you two for helping me (at 8 am ). >> Works with this code perfectly. Thats the whole code btw. >> >> Arvid >> >> import maya.OpenMayaUI as mui >> import shiboken >> from PySide import QtGui >> from PySide import QtCore >> >> >> class HyperShadeEventFilter(QtCore.QObject): >> def __init__(self): >> super(HyperShadeEventFilter, self).__init__() >> ptr = mui.MQtUtil.mainWindow() >> self.Handler = Handler() >> mainWin = shiboken.wrapInstance(long(ptr), QtGui.QWidget) >> mainWin.installEventFilter(self.Handler) >> >> >> class Handler(QtCore.QObject): >> def eventFilter(self, obj, event): >> if event.type() == event.ChildPolished: >> print event.type() >> child = event.child() >> print child.objectName() >> if 'hyperShadePanel' in child.objectName(): >> print 'OPEN' >> elif event.type() == event.ChildRemoved: >> print event.type() >> child = event.child() >> if 'hyperShadePanel' in child.objectName(): >> print 'CLOSE' >> return super(Handler, self).eventFilter(obj, event) >> x = HyperShadeEventFilter() >> >> >> >> >> >> On Monday, November 10, 2014 8:48:58 AM UTC+1, Marcus Ottosson wrote: >>> >>> Ok, also make sure that you’re keeping the instance of the eventfilter >>> alive at run-time. >>> >>> For example, this: >>> >>> def __init__(self): >>> filter = MyEventFilter() >>> self.installEventFilter(filter) >>> >>> Will cause filter to get picked up by garbage collection before it gets >>> a chance to do anything. One way is to add it as a member to the class. >>> >>> def __init__(self): >>> self.filter = MyEventFilter() >>> self.installEventFilter(self.filter) >>> >>> Do post the entire code if you can, otherwise I can only guess. >>> >>> >>> On 10 November 2014 07:43, Arvid Schneider <[email protected]> wrote: >>> >>>> Hi Justin, >>>> >>>> I ve tried both versions. No errors. >>>> It seems that the eventFilter does not get properly installed. >>>> >>>> Marcus, I am installing the eventFilter in the class's init like you >>>> suggested. >>>> Arvid >>>> >>>> On Monday, November 10, 2014 8:39:30 AM UTC+1, 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/45b59dd >>>>>>> f-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%3DqGnwgffbzTs9MP >>>>>> XX1MO9g1pQAPNodA%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/c53c462e-d967-425c-97a3- >>>> e4fd15a1ce5f%40googlegroups.com >>>> <https://groups.google.com/d/msgid/python_inside_maya/c53c462e-d967-425c-97a3-e4fd15a1ce5f%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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/2ff63179-b3f7-4038-9a06-b7cb2a29c679%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/2ff63179-b3f7-4038-9a06-b7cb2a29c679%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > *Marcus Ottosson* > [email protected] <javascript:> > -- 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/7ecaa5ea-7d7a-43fe-91d1-a7816a7d69ba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
