Jump to content

How to run an event only when left mouse bottom being held down?(Python


Blacko0ps

Recommended Posts

It should be possible to do using Qt event system if you familiar with it.

What you need to do is to install eventFilter to Houdini's QApplication instance, and catch QMouseEvent there. 

Quick untested code from the top of my head:

app = QApplication.instance()

class Filter(QObject):
    def eventFilter(self, event, **kwargs):
        if isinstance(QMouseEvent, event):
            if event.button() ==  Qt.RightButton:
				# DO stuff
	return super(Filter, self).eventFilter(event, **kwargs)

app.installEventFilter(Filter())

 

Edited by Stalkerx777
  • Like 2
Link to comment
Share on other sites

Thanks Alex! Unfortunately, I am not familiar with QT event system. Is it a separate package or it's built in in Houdini ? 

Update- Ok, after doing some research I think this what you have been refering to : http://doc.qt.io/qt-4.8/qobject.html#installEventFilter

Still trying to figure out how to install it for Houdini 

Edited by Blacko0ps
Link to comment
Share on other sites

  • 2 years later...

Any chance this thread can be revisited? I'd also like to know how, specifically, the code posted by @Stalkerx777 is meant to be added to Houdini.

When I run the code directly within an instance of Houdini (Houdini 17.5), I get this warning:`, this warning is

Qt Warn: QObject::installEventFilter(): Cannot filter events for objects in a different thread.

and the event is not installed. The same warning happens when I try to apply the event to hou.qt.mainWindow(). And suggestions on this?

Edited by Red Scholar
Link to comment
Share on other sites

H17 Introduced a new Python API for the viewport (Python states), this is a way to go if you need viewport interaction. If you want to catch an event in the whole Houdini app, then the trick I posted above should work, however, keep in mind, it must run in the main thread. Pretty much every place from which you can start Python code in Houdini will put it in the main thread, EXCEPT the Python shell - it runs in its own thread.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...