Search - User list
Full Version: access to pdg event handlers added to the node
Root » PDG/TOPs » access to pdg event handlers added to the node
AndriiFroloff
Hi,

Is there a way to get a list of event handlers added to a pdg node (similar to eventCallbacks() method of hou.node) or to store some unique id of pdg event handler object to access it after recook of the node that added this handler to be able to remove it?

I tried getting object address using python id() function, storing it to an integer spare parameter and then reading an object from this parameter using ctypes.cast() however it turned out that object id of the event handler changes each time after node recooks so this trick didn't work.
chrisgreb
No there isn't, but we could expose a method: node.removeAllEventHandlers() , would that be sufficient ?
AndriiFroloff
It would be amazing since I currently use spare parameter flag ‘event handler added’ and if-else fork for adding event handler. And this flag must be unset before first cooking after opening hip.
Thanks for the quick response!
AndriiFroloff
I've tested this new method. It works, however it introduced a new bug. If this method is called within a node, workitems are generated but not displayed in the node interface. In some cases, workitems aren't generated at all on the first run of dirty&cook, only generated on the second run.

Video attached, test cooking of simple processor with and without .removeAllEventHandlers()

houdini 17.5 build 350
Windows 7 SP1
chrisgreb
Ah - well it's doing what it promised but that's not useful in this case since we don't want to touch the TOPs handlers. We will take a look at providing a better solution.
AndriiFroloff
Thanks, looking forward to your success. Also if this task turns out to be hard to implement and is not high-priority, maybe you could suggest some temporary trick that is better than my current solution (at least that wouldn't require a manual reset each time and that would allow updating event handler function without reloading a hip-file)

My current solution:

There is a toggle spare parameter ‘event_handler_added’ that must be set to zero (for each node that use event handler) after hip file load.

#event handler adder code in python processor:
event_handler_added = event_handler_added_parm.evalAsInt()
if not event_handler_added:
—-# if zero, assuming this is the first run therefore no event handlers added yet
—-handler = self.addEventHandler(selected, pdg.EventType.UISelect)
—-event_handler_added_parm.set(1) # set flag to 1 to avoid further adding after recook
Andrew Graham
Being able to list all event handlers for a graph and for nodes would be useful to selectively remove a handler of a certain type / name.

Without being able to list handlers its also not possible to determine if a handler needs to be added for some process.
chrisgreb
AndriiFroloff
Thanks, looking forward to your success. Also if this task turns out to be hard to implement and is not high-priority, maybe you could suggest some temporary trick that is better than my current solution (at least that wouldn't require a manual reset each time and that would allow updating event handler function without reloading a hip-file)

My current solution:

There is a toggle spare parameter ‘event_handler_added’ that must be set to zero (for each node that use event handler) after hip file load.

#event handler adder code in python processor:
event_handler_added = event_handler_added_parm.evalAsInt()
if not event_handler_added:
—-# if zero, assuming this is the first run therefore no event handlers added yet
—-handler = self.addEventHandler(selected, pdg.EventType.UISelect)
—-event_handler_added_parm.set(1) # set flag to 1 to avoid further adding after recook

Sorry for the late reply. Can't you just store the handler on the pdg node? IE:


if not hasattr(self, 'handler'):
    def selected(ev):
        print('HANDLE' +str(ev))
    self.handler = self.addEventHandler(selected, pdg.EventType.UISelect)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB