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:
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?
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:
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.
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:
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)
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.
It looks like the folder display node explicitly invokes a Modified event on all display nodes of all its displayable node children:
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.
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?