Proposal: Update `vtkPythonCommand::Execute` to support custom event

The current implementation vtkPythonCommand::Execute does not support custom event. See Test Case below.


The issue is that vtkPythonCommand::GetStringFromEventId[1] (used in vtkPythonCommand::Execute[2]) returns the string NoEvent for custom events.


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)

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

  1. ↩︎

  2. ↩︎


Sounds reasonable. Something like this, where the allowed types are int and str.

def callback(caller, event):
1 Like