Disconnect signal

I am connected to a figure like below:

    mainwindow = slicer.util.mainWindow()
    figureHandle= slicer.util.findChildren(mainwindow, className="qMRMLPlotView")[0]

Now, I would like to disconnect when File --> Close Scene is selected. Is there a signal emitted when Close Scene is selected? For example, I am looking for something like below:

figureHandle.disconnect(‘when scene is closed’)

The signals associated with the scene are documented here: http://apidocs.slicer.org/v4.10/classvtkMRMLScene.html#a8ccb4e378bdb987a4e95ac6cc1067c94

The relevant signal to observe is vtkMRMLScene::EndCloseEvent

For example:

def onSceneEndCloseEvent(caller, eventId):
  print("Scene close")

slicer.mrmlScene.AddObserver(slicer.vtkMRMLScene.EndCloseEvent, onSceneEndCloseEvent)

To learn more about efficient way for managing VTK object connections, see also:

1 Like