# Custom Segment Editor effect - Undo action

**URL:** <https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115>\
**Category:** Development\
**Created:** [February 22, 2022, 3:32pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115 "2022-02-22T15:32:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovform](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/giovform/32/4687_2.png) [@giovform](https://discourse.slicer.org/u/giovform)\
**Post date:** [February 22, 2022, 3:32pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/1 "2022-02-22T15:32:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 22, 2022, 6:25pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/2 "2022-02-22T18:25:45Z")

</div>

Probably like:

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

---

<div class="post-metadata">

**Author:** ![giovform](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/giovform/32/4687_2.png) [@giovform](https://discourse.slicer.org/u/giovform)\
**Post date:** [February 22, 2022, 8:29pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/3 "2022-02-22T20:29:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 22, 2022, 8:49pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/4 "2022-02-22T20:49:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giovform](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/giovform/32/4687_2.png) [@giovform](https://discourse.slicer.org/u/giovform)\
**Post date:** [February 22, 2022, 8:51pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/5 "2022-02-22T20:51:59Z")

</div>

From the SegmentEditorWidget

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 22, 2022, 9:08pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/6 "2022-02-22T21:08:44Z")

</div>

The action is taking place [here](https://github.com/Slicer/Slicer/blob/1178ed47833e8d921b36a17e0763828e56e9029b/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx) line 3148

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 22, 2022, 9:20pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/7 "2022-02-22T21:20:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 22, 2022, 10:02pm UTC](https://discourse.slicer.org/t/custom-segment-editor-effect-undo-action/22115/8 "2022-02-22T22:02:48Z")

</div>

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