Hi,
This is my first post here,
I'm trying to make a generalized pickobjects tool and I want it to stop the script evaluation until
the user exit the picking cession.
I've seen this asked here and there and there might just not be a solution for it, but I'm giving it a shot.
I'm actually quite close and I'm just using a while loop with processEvents() to still have access to the UI,
unfortunately I'm having an odd behavior on mouse release, it seems it's re-running the whole code, queuing it
and finally execute the queued code.
import maya.OpenMayaUI as om
from PySide import QtGui, QtCore
from PySide.QtCore import *
from PySide.QtGui import *
from shiboken import wrapInstance
import shiboken
class MouseEventFilter(QtCore.QObject):
def __init__(self, label=None):
self.__label = label
QtCore.QObject.__init__(self)
self.x = 0
self.y = 0
def eventFilter(self, obj, event):
typ = event.type()
if event.type() == event.MouseMove:
print event.x(), event.y()
self.x = event.x()
self.y = event.y()
if event.type() == event.MouseButtonPress:
print "pressed"
if event.type() == event.MouseButtonRelease:
print "release"
return False
class KeyEventFilter(QtGui.QWidget):
def __init__(self, label=None):
self.__label = label
QtGui.QWidget.__init__(self)
self.exit = False
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.KeyPress:
typ = event.type()
print typ
self.exit = True
return True
return False
mayaMainWindowPtr = om.MQtUtil.mainWindow()
mayaMainWindow = wrapInstance(long(mayaMainWindowPtr), QWidget)
kEventFilter = KeyEventFilter(mayaMainWindow)
mayaMainWindow.installEventFilter(kEventFilter)
view = om.M3dView.active3dView()
widget_ptr = view.widget()
widget = wrapInstance(long(widget_ptr), QWidget)
mEventFilter = MouseEventFilter(widget)
widget.installEventFilter(mEventFilter)
while True:
QtGui.qApp.processEvents()
#cmds.evalDeferred(flop, low=True)
#print eventFilter.x, eventFilter.y
if kEventFilter.exit == True:
widget.removeEventFilter(mEventFilter)
kEventFilter.deleteLater()
mayaMainWindow.removeEventFilter(kEventFilter)
kEventFilter.deleteLater()
break
print "should run after"
If someone have an idea about it!
Thanks
-A