Blacko0ps Posted March 12, 2017 Share Posted March 12, 2017 Hi Everyone, I was wondering if there is anyway in Python to run a function only when the left mouse bottom being held down? Thanks, Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 12, 2017 Share Posted March 12, 2017 (edited) 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 March 12, 2017 by Stalkerx777 2 Quote Link to comment Share on other sites More sharing options...
Blacko0ps Posted March 12, 2017 Author Share Posted March 12, 2017 (edited) 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 March 13, 2017 by Blacko0ps Quote Link to comment Share on other sites More sharing options...
Red Scholar Posted April 2, 2019 Share Posted April 2, 2019 (edited) 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 April 2, 2019 by Red Scholar Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted April 2, 2019 Share Posted April 2, 2019 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. Quote Link to comment Share on other sites More sharing options...
Red Scholar Posted April 3, 2019 Share Posted April 3, 2019 I see. Python states are definitely the way to go for my purposes. Thanks Alex! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.