Discussion:
[Maya-Python] capturing mouse clicks?
Ravi Jagannadhan
2018-10-13 23:30:54 UTC
Permalink
Hi all, I'm trying to detect when a mouse button is clicked anywhere in
Maya as part of an event filter. I currently have this as an event filter:

from PySide2 import QtCore, QtWidgets
from shiboken2 import wrapInstance
from maya import OpenMayaUI

win_ptr = OpenMayaUI.MQtUtil.mainWindow()
win = wrapInstance(long(win_ptr), QtWidgets.QMainWindow)

class MyEventFilter(QtCore.QObject):

def eventFilter(self, watched, event):
print event.type(), watched, event


filter = MyEventFilter()
win.installEventFilter(filter)

But it doesn't seem to trap a mouse button press/release event (or at least
I don't see it in the output). What am I missing from this in order to
trap the mouse button events?

Thank you for your time,
Ravi
--
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADHeb2aesfCHOSOzeSXbKC5qvB6GebR3FG5yHN0OkYEnzpPcBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-10-14 00:21:24 UTC
Permalink
Post by Ravi Jagannadhan
Hi all, I'm trying to detect when a mouse button is clicked anywhere in
from PySide2 import QtCore, QtWidgets
from shiboken2 import wrapInstance
from maya import OpenMayaUI
win_ptr = OpenMayaUI.MQtUtil.mainWindow()
win = wrapInstance(long(win_ptr), QtWidgets.QMainWindow)
print event.type(), watched, event
filter = MyEventFilter()
win.installEventFilter(filter)
This is only going to catch events that aren't handled by child widgets and
bubble up to the window. If you want to catch every mouse click in the
whole app, you would have to install it on the QApplication. Note this will
slow Maya down because of a python function being called for every event in
the system.
Post by Ravi Jagannadhan
But it doesn't seem to trap a mouse button press/release event (or at
least I don't see it in the output). What am I missing from this in order
to trap the mouse button events?
Thank you for your time,
Ravi
--
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CADHeb2aesfCHOSOzeSXbKC5qvB6GebR3FG5yHN0OkYEnzpPcBw%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CADHeb2aesfCHOSOzeSXbKC5qvB6GebR3FG5yHN0OkYEnzpPcBw%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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0w1tUhnVgQeMsUToaVACkqvcMLE1fuvqtYB37VPoQ3sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Ravi Jagannadhan
2018-10-14 04:22:27 UTC
Permalink
Thank you for the response. The issue I'm looking into happens also when
clicking menu items in the top level window, so maybe I'll start there.
Thanks again.
Post by Justin Israel
Post by Ravi Jagannadhan
Hi all, I'm trying to detect when a mouse button is clicked anywhere in
from PySide2 import QtCore, QtWidgets
from shiboken2 import wrapInstance
from maya import OpenMayaUI
win_ptr = OpenMayaUI.MQtUtil.mainWindow()
win = wrapInstance(long(win_ptr), QtWidgets.QMainWindow)
print event.type(), watched, event
filter = MyEventFilter()
win.installEventFilter(filter)
This is only going to catch events that aren't handled by child widgets
and bubble up to the window. If you want to catch every mouse click in the
whole app, you would have to install it on the QApplication. Note this will
slow Maya down because of a python function being called for every event in
the system.
Post by Ravi Jagannadhan
But it doesn't seem to trap a mouse button press/release event (or at
least I don't see it in the output). What am I missing from this in order
to trap the mouse button events?
Thank you for your time,
Ravi
--
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CADHeb2aesfCHOSOzeSXbKC5qvB6GebR3FG5yHN0OkYEnzpPcBw%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CADHeb2aesfCHOSOzeSXbKC5qvB6GebR3FG5yHN0OkYEnzpPcBw%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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0w1tUhnVgQeMsUToaVACkqvcMLE1fuvqtYB37VPoQ3sA%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0w1tUhnVgQeMsUToaVACkqvcMLE1fuvqtYB37VPoQ3sA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADHeb2ZfLociZt7DbV6cDG1jnJr_8Z%2BFAdyuV-uhitCxSvezVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...