Custom Segment Editor effect - Undo action

I am writing a custom segment editor effect in python. I would like to perform some actions when a user clicks the Undo button under the current effect. How could it be done?

Thanks!

Probably like:

segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
# do stuff ... but it was wrong
segmentEditorWidget.undo()

No, this is not the intent. I want to perform actions when the user clicks the Undo button.

Is it the Undo button of the SegmentEditorWidget or your own Undo button ?

From the SegmentEditorWidget

The action is taking place here line 3148

There is possibly an undo event that one could trap/handle but this is beyond my scope. Maybe @lassoan could comment

I want to perform actions when the user clicks the Undo button.

There is no VTK event invoked or Qt signal emitted if the user clicks Undo/Redo, because Undo/Redo is just one of many reasons a segmentation node can change. Your custom effect should behave correctly regardless of what caused that change.

If you describe your use case in more detail then we can help finding the most appropriate objects and events to observe.