Basically I have this code for setting a default volume in the views
mainWindow = slicer.util.mainWindow()
if mainWindow is not None:
layoutManager = slicer.app.layoutManager()
if layoutManager is not None:
sliceLogic = layoutManager.sliceWidget('Red').sliceLogic()
CompositeNode = sliceLogic.GetSliceCompositeNode()
CompositeNode.SetLinkedControl(1)
sliceLogic.StartSliceCompositeNodeInteraction(1)
CompositeNode.SetBackgroundVolumeID(minCTID)
CompositeNode.SetForegroundVolumeID(minSPECTID)
sliceLogic.EndSliceCompositeNodeInteraction()
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)
slicer.util.resetSliceViews()
It works like a charm in normal mode, but when testing with --no-main-window
it creates the following error
3: Test checkAttributes_positive passed!
3:
3: **************************************
3:
3: ok
3: runTest (slicer.ScriptedLoadableModule.ScriptedLoadableModuleTest) ... No test is defined in ScriptedLoadableModuleTest
3: ok
3:
3: ----------------------------------------------------------------------
3: Ran 2 tests in 0.732s
3:
3: OK
3: vtkDebugLeaks has detected LEAKS!
3: Class "vtkObserverManager" has 1 instance still around.
3: Class "vtkMRMLSliceCompositeNode" has 1 instance still around.
3: Class "vtkCommand or subclass" has 2 instances still around.
3:
3/4 Test #3: py_Dosimetry4DTest ...............***Failed 10.47 sec
As you can see the test passed, but the VTK leaks breaks the workflow
Without the above code, the VTK leaks are not present. However that code is not intended to run at all in no window mode, that is why I check if there is a main window. However, the check is failing as it creates the composite nodes. How is this possible?? Is there a way to NOT run a piece of code in no window mode??