Jump to content

PySide Emit Node Selected Signal


Shalinar

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

Link to comment
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
Link to comment
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.

Link to comment
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 :) 

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...