Hey all! This forum is great and seems to pop up more often lately on my current google searches so I thought it’s just about time to register and get some questions out, and hopefully give some answers back in time!
I’m currently working on widening my Maya Python API horizon by working on some ideas or replicating things that I see around that feel like a good challenge! The other day I was browsing Chad Vernons website for getting some API infos and I stumbled upon his Maya Move Brush. I was often thinking about implementing my own version of this just for the fun of it so I started my journey but got stuck pretty early in the process. Right now I try to find the best way to query mouse data (position) when moving the mouse in the Maya viewport. Chad gives this peace of information in one of the comments:
The viewport is a QWidget. You can install a mouse move event filter on it to track mouse movement.
I’m not a total noob on pyQt but haven’t worked with event filters so far. I looked into the subject and found some more info:
http://nathanhorne.com/?p=298
http://forums.cgsociety.org/showthread.php?f=89&t=933209
These two links give some nice examples of possible solutions for working with event filters. So I started to write an MPxContext plugin for maya in python where I defined an eventFilter class like described by Nathan Horne:
class MouseMoveFilter(QtCore.QObject):
'''A simple event filter to catch MouseMove events'''
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.MouseMove:
#Hide the old tooltip, so that it can move
QtGui.QToolTip.hideText()
QtGui.QToolTip.showText(event.globalPos(), '%04f, %04f' % (event.globalX(), event.globalY()), obj)
return False
return True
I install the filter on the active3dView in the toolOnSetup() method of my context class
def toolOnSetup(self, event):
self._setHelpString('Test')
#Install the event filter into all the model panels
global filter
filter = MouseMoveFilter()
view = OpenMayaUI.M3dView.active3dView()
self.viewWidget = sip.wrapinstance(long(view.widget()), QtCore.QObject)
self.viewWidget.installEventFilter(filter)
This does all actually work. When I invoke the context, the position data are displayed on my cursor and update as I move the mouse along! Problem seems though that in the Maya viewport all other keyboard actions just get discarded and I can’t do anything else but moving the mouse as long as I’m in the context! I step out of it and stuff gets back to normal! It seems like all other events don’t get caught up from Maya no more! Anyone having any ideas what I’m doing wrong?
Another solution I looked into is Mayas native draggerContext function! This also gives me a lot of valuable information but doesn’t continually give me the mouse position when I move the mouse! I might be thinking wrong here though!
Any help is much appreciated!
Thanks in advance