The current implementation vtkPythonCommand::Execute
does not support custom event. See Test Case below.
Problem
The issue is that vtkPythonCommand::GetStringFromEventId
[1] (used in vtkPythonCommand::Execute
[2]) returns the string NoEvent
for custom events.
Proposal
Introduce a new decorator allowing to modify the behavior of vtkPythonCommand::Execute
so that it always return the event as an integer.
Test case
For example:
vtk_obj = vtk.vtkObject()
customEvent = vtk.vtkCommand.UserEvent + 42
def callback(caller, event):
print(f" current callback event [{event}]")
print(f"expected callback event [{customEvent}]")
assert str(event) == str(customEvent), f"callback event [{event}] is different from [{customEvent}]"
tag = vtk_obj.AddObserver(customEvent, callback)
vtk_obj.InvokeEvent(customEvent)
reports the following
current callback event [NoEvent]
expected callback event [1042]
Traceback (most recent call last):
File "<string>", line 10, in callback
AssertionError: callback event [NoEvent] is different from [1042]
cc: @dgobbi @banesullivan