# Folder display node ModifiedEvent doesn't get triggered from parent

**URL:** <https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812>\
**Category:** Development\
**Created:** [April 8, 2023, 7:20pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812 "2023-04-08T19:20:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![danpak94](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danpak94/32/18310_2.png) [@danpak94](https://discourse.slicer.org/u/danpak94)\
**Post date:** [April 8, 2023, 7:20pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/1 "2023-04-08T19:20:18Z")

</div>

Hello,

I was trying to implement a callback for my folder display node, but it seems like it’s not triggering ModifiedEvent when I change the display of the parent folder.

For example, let’s say I have the following subject hierarchy:

FolderA  
|---- FolderB  
|---- Segmentation

```auto
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
folderDisplayNode = shNode.GetItemDataNode(shNode.GetItemByName("FolderB"))
segmentationNode = shNode.GetItemDataNode(shNode.GetItemByName("Segmentation"))

def test_callback(caller, event):
    print('in here!', caller.GetName())

test = slicer.util.VTKObservationMixin()
test.addObserver(folderDisplayNode, vtk.vtkCommand.ModifiedEvent, test_callback)
test.addObserver(segmentationNode.GetDisplayNode(), vtk.vtkCommand.ModifiedEvent, test_callback)

```

When I change FolderA visibility, it triggers only Segmentation display node’s ModifiedEvent. I would expect it to trigger the FolderB display ModifiedEvent as well. Could you please point me to how I can fix this issue?

Thank you

---

<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:** [April 11, 2023, 5:07am UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/2 "2023-04-11T05:07:42Z")

</div>

A node’s modified event is only invoked if the node is modified. You can observe the node’s `DisplayModified` event if you want to get notified about any display node changes:

```python
test.addObserver(segmentationNode, slicer.vtkMRMLDisplayableNode.DisplayModifiedEvent, test_callback)

```

---

<div class="post-metadata">

**Author:** ![danpak94](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danpak94/32/18310_2.png) [@danpak94](https://discourse.slicer.org/u/danpak94)\
**Post date:** [April 11, 2023, 11:11am UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/3 "2023-04-11T11:11:09Z")

</div>

Hello,

My problem was actually more associated with `folderDisplayNode`, which is a `vtkMRMLDisplayNode`, not a `vtkMRMLDisplayabableNode`. I just added this line (`test.addObserver(segmentationNode.GetDisplayNode(), vtk.vtkCommand.ModifiedEvent, test_callback`) to demonstrate that changing the **parent** folder visibility seems to call `segmentationNode.DisplayNode()`'s `ModifiedEvent`, but not `folderDisplayNode`’s `ModifiedEvent`.

I would appreciate any pointers as to why this might be happening / how I can solve the issue.

Thank you.

---

<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:** [April 11, 2023, 7:21pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/4 "2023-04-11T19:21:45Z")

</div>

> [@danpak94](#):
>
> to demonstrate that changing the **parent** folder visibility seems to call `segmentationNode.DisplayNode()`'s `ModifiedEvent`, but not `folderDisplayNode`’s `ModifiedEvent`.

Toggling visibility of the folder actually calls `folderDisplayNode`’s `ModifiedEvent`. To test, you can create a new folder, click the eye icon so that a display node gets created for it automatically, run the code snippet below, and toggle the eye icon of the folder to see the message printed:

```python
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
folderDisplayNode = shNode.GetItemDataNode(shNode.GetItemByName('NewFolder'))
if not folderDisplayNode or not folderDisplayNode.IsA('vtkMRMLFolderDisplayNode'):
    raise RuntimeError("This folder has no display node")

def test_callback(caller, event):
    print('in here!', caller.GetName())

test = slicer.util.VTKObservationMixin()
test.addObserver(folderDisplayNode, vtk.vtkCommand.ModifiedEvent, test_callback)

```

---

<div class="post-metadata">

**Author:** ![danpak94](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danpak94/32/18310_2.png) [@danpak94](https://discourse.slicer.org/u/danpak94)\
**Post date:** [April 12, 2023, 1:59am UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/5 "2023-04-12T01:59:51Z")

</div>

Yes, that works when I have a single folder, but I’m wondering about when there’s a folder inside another folder.

ParentFolder  
|---- NewFolder

The callback is triggered when I toggle NewFolder, but not when I toggle ParentFolder.

---

<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:** [April 12, 2023, 11:32am UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/6 "2023-04-12T11:32:07Z")

</div>

> [@danpak94](#):
>
> The callback is triggered when I toggle NewFolder, but not when I toggle ParentFolder.

That’s correct. A node invokes Modified event if the node is modified. A node does not invoke Modified event if a different node is modified.

Some nodes invoke custom modified events when certain properties change or some properties in related nodes change.

What is your overall goal?

---

<div class="post-metadata">

**Author:** ![danpak94](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danpak94/32/18310_2.png) [@danpak94](https://discourse.slicer.org/u/danpak94)\
**Post date:** [April 12, 2023, 4:41pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/7 "2023-04-12T16:41:20Z")

</div>

If this behavior is expected, then how come the following happens?

ParentFolder  
|---- SegmentationNode

`test.addObserver(SegmentationNode.GetDisplayNode(), vtk.vtkCommand.ModifiedEvent, test_callback)`

Toggling ParentFolder calls test\_callback.

My overall goal:  
I want to update my visibility checkbox based on the “final” visibility of the NewFolder, since NewFolder is only visible when both ParentFolder and NewFolder are visible.

---

<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:** [April 12, 2023, 10:41pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/8 "2023-04-12T22:41:19Z")

</div>

It looks like the folder display node explicitly invokes a `Modified` event on all display nodes of all its displayable node children:

> <https://github.com/Slicer/Slicer/blob/fd7b4f3cceba976aabeb2e1cdda9ecc685fc0c64/Libs/MRML/Core/vtkMRMLFolderDisplayNode.cxx#L198-L225>

The folder display node is not a displayable node, so it does not get a Modified event invokation. The code could be reorganized so that each folder display node just notifies its immediate children and then let the children folders notify their children. Do you want to give it a try to implement it?

Displaying branches that are under a “closed eye” branch in a different style (e.g., dark gray text, maybe a different icon) would be great. We’ve been thinking about implementing something like this just did not have the time. Do you plan to contribute this feature to Slicer core? Let us know how we can help.

---

<div class="post-metadata">

**Author:** ![danpak94](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danpak94/32/18310_2.png) [@danpak94](https://discourse.slicer.org/u/danpak94)\
**Post date:** [April 13, 2023, 5:42pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/9 "2023-04-13T17:42:02Z")

</div>

This could be interesting for me to try, but I’ve only worked with python scripting for slicer, so I’m not very familiar with compiling it, etc. Is this something that I can get help with?

---

<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:** [April 13, 2023, 7:08pm UTC](https://discourse.slicer.org/t/folder-display-node-modifiedevent-doesnt-get-triggered-from-parent/28812/10 "2023-04-13T19:08:28Z")

</div>

C++/Python is not a big difference, but the key question is how much you are familiar (or ready to learn) about Qt and a little about Slicer core.

If you decide to give it a try then the first step is to [build Slicer from source](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/index.html).
