If you search the forum you will see previous questions about adding a drag and drop handler to Maya.
https://groups.google.com/d/topic/python_inside_maya/Auiy06xVqLo/discussion This one in particular shows an approach that works in 2015 for sure, but possibly not anymore in 2017 under PySide2. But it may be because of changes to Maya and which widgets are handling events. If in the past, the viewport never directly handled the drops, then it would make sense to be able to catch them on the main window. But if Maya has changed to where the event is handled on the viewport or some child widget of the main window, then you won't be able to catch it from the main window. It would have to be installed on the viewport widget. Events work by first going through the QApplication, and then getting sent directly to the target widget for the event. If the target widget decides not to handle it, then it bubbles up to parents, which is why you can catch things on the main window like a viewport drag and drop I'm Maya 2015 Here is the qt 4.8 reference about how the event system works: http://doc.qt.io/qt-4.8/eventsandfilters.html Justin On Sat, Feb 4, 2017, 6:06 AM johan Borgström <[email protected]> wrote: > Hi, > > I am trying to install an event filter on the main maya window to process > a drop event. In the snippet below I can get the key press event, but the > DragEnter and Drop event never gets called. Instead a function called > "performFileDropAction" gets called. > > How would I do this? > > Thanks, > / J > > from PySide2 import QtGui, QtCore, QtWidgets > from maya import OpenMayaUI as omui > from shiboken2 import wrapInstance > > > class MyEventFilter(QtCore.QObject): > > def eventFilter(self, obj, event): > > if event.type() is event.KeyPress: > print("Ate key press", event.key()) > event.accept() > return True > > elif event.type() is event.DragEnter: > print('DragEnter') > event.accept() > > elif event.type() is event.Drop: > print('Drop') > event.accept() > > else: > # standard event processing > return QtCore.QObject.eventFilter(self, obj, event) > > main_win = wrapInstance(long(omui.MQtUtil.mainWindow()), > QtWidgets.QWidget) > my_filter = MyEventFilter() > main_win.installEventFilter(my_filter) > #main_win.removeEventFilter(my_filter) > > > -- > 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/180b8d68-8f17-4dd2-a96e-068027de2e77%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/180b8d68-8f17-4dd2-a96e-068027de2e77%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/CAPGFgA2SM6qky3LpPsM6VyM%2BPHu4ZmjN972NQfWywKszpYHHgg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
