Jump to content
Shalinar

PySide Emit Node Selected Signal

Recommended Posts

In the current tool I'm building for H16, I have a UI in which I would like to have different options available to the user depending on their selection. It would be ideal if these options can change without the user having to close and relaunch the UI every time. In short, I need a way to capture a signal emitted when the user selects node(s). I looked around the HOM and didn't see anything that looks like it gets called whenever a node is selected, just queries for currently selected nodes. Does anyone know how I could trigger something in my UI whenever the user selects different nodes?

Thanks!

Chris

Share this post


Link to post
Share on other sites

You have many options here, none of them are ideal though since not everything in Houdini is Qt yet:

1. To all your nodes in a scene add hou.Node.addEventCallback ( AppearanceChanged event type may work, or may not, I don't know). Pass your function or QWidget there, and hope this will work. A better approach would be to post a custom QEvent from there with QApplication::postEvent() and catch this event in your QWidget. Not that trivial, but definitely possible to do (at least in normal Qt app)

2. QApplication::installEventFilter. Put your filter there and see if you can catch something from Houdini.

3. hou.ui.addEventLoopCallback() poll your hou.selectedNodes() and see if selection changed.

4. Should be other ways...

 

  • Like 1

Share this post


Link to post
Share on other sites

This has been working great for me Alex! The only modification I've made is in the remove_selection_event static method, I ended up having to add the following lines at the end:

if hasattr(hou.session, '_selection'):
	del hou.session._selection

Otherwise, I was getting a continuous hou.ObjectWasDeleted error when event_callback was trying to getattr(hou.session, '_selection', None) if I had deleted the node (this also happened when I tried it first on a locked then unlocked SESI HDA -- weird). So I just made sure to clean up the _selection attribute on hou.session and it's working like a charm!

Thanks again for your very detailed example, it was clear, concise, and easy to follow/replicate for my own needs.

Share this post


Link to post
Share on other sites
22 hours ago, Shalinar said:

This has been working great for me Alex! The only modification I've made is in the remove_selection_event static method, I ended up having to add the following lines at the end:


if hasattr(hou.session, '_selection'):
	del hou.session._selection

Otherwise, I was getting a continuous hou.ObjectWasDeleted error when event_callback was trying to getattr(hou.session, '_selection', None) if I had deleted the node (this also happened when I tried it first on a locked then unlocked SESI HDA -- weird). So I just made sure to clean up the _selection attribute on hou.session and it's working like a charm!

Thanks again for your very detailed example, it was clear, concise, and easy to follow/replicate for my own needs.

Glad i could help :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×