capturing mouse clicks?

31 views
Skip to first unread message

Ravi Jagannadhan

unread,
Oct 13, 2018, 7:31:12 PM10/13/18
to python_in...@googlegroups.com
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

Justin Israel

unread,
Oct 13, 2018, 8:21:40 PM10/13/18
to python_in...@googlegroups.com


On Sun, Oct 14, 2018, 12:31 PM Ravi Jagannadhan <enr...@gmail.com> wrote:
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) 

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. 


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_m...@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.

Ravi Jagannadhan

unread,
Oct 14, 2018, 12:22:46 AM10/14/18
to python_in...@googlegroups.com
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.


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages