class Region(QtCore.QObject):""" Class contains methods to provide information for a specific selected region """def eventFilter(self, obj, event):if event.type() == QtCore.QEvent.MouseButtonPress:print QtGui.QCursor().pos()press = QtGui.QCursor().pos()return Falseif event.type() == QtCore.QEvent.MouseButtonRelease:print QtGui.QCursor().pos()release = QtGui.QCursor().pos()return False# Call Base Class Method to Continue Normal Event Processingreturn super(Region, self).eventFilter(obj, event)def regionDataOnSetup():global filterfilter = Region()view = omui.M3dView.active3dView()viewWidget = wrapinstance(long(view.widget()), QtCore.QObject)viewWidget.installEventFilter(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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f4b50bee-75d5-4359-b6e8-c6c24ab065c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you only want it to capture the mouse click once after you have told it to attach to the widget, then you can try calling removeEventFilter(obj) in the eventFilter() after you have handled the mouse release. That way it will only fire once and not continue processing events.
Some other suggestions though. Use a constructor and set up some attributes like your clicked and released values. Then store them from your eventFilter like:
self.released = value
Don't use QCursor to get the positions. The proper values are already there on the event object that is being delivered. Once you have checked the type, then you know it is a QMouseEvent: http://qt-project.org/doc/qt-4.8/qmouseevent.html
--
REGION_COORDINATES = ['rStart_x', 'rStart_y', 'rEnd_x', 'rEnd_y']
class Region(QtCore.QObject):""" Class contains methods to provide information for a specific selected region """
global REGION_COORDINATESdef stop(self, value):self.stopEvent = valuedef setCoordinateData(self, coordinateValue, place):""" stores the x and y coordinate in our global variable """REGION_COORDINATES[place] = coordinateValuedef eventFilter(self, obj, event):""" setup the event filter for mouse button pressand mouse button release"""if event.type() == QtCore.QEvent.MouseButtonPress:self.setCoordinateData(event.globalX(), int(0))self.setCoordinateData(event.globalY(), int(1))
return Falseif event.type() == QtCore.QEvent.MouseButtonRelease:
self.setCoordinateData(event.globalX(), int(2))self.setCoordinateData(event.globalY(), int(3))self.stop(value = True)return Falsereturn super(Region, self).eventFilter(obj, event)def installRegion():
global filterfilter = Region()
filter.stop(value = False)stopEvent = filter.stopEvent
view = omui.M3dView.active3dView()viewWidget = wrapinstance(long(view.widget()), QtCore.QObject)viewWidget.installEventFilter(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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b265518c-9b5c-4497-ae55-c16124da3511%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.