system: Windows 10
Slicer-version: 4.10.0
Hello,
I am trying to add a observer to monitor the number of slice views changes. But the right way was not found. Which node and event should be used ?
Slice views changes like this:
– to →
I want to trigger my own method after the event has occurred.
Here is the method of slice views changes:
layoutManager = slicer.app.layoutManager()
customLayout = """
<layout type="vertical">
<item>
<layout type="horizontal">
<item splitSize="300">
<view class="vtkMRMLSliceNode" singletontag="Red">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
<item splitSize="300">
<view class="vtkMRMLSliceNode" singletontag="Red1">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
</layout>
</item>
<item>
<layout type="horizontal">
<item splitSize="300">
<view class="vtkMRMLSliceNode" singletontag="Red2">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
<item splitSize="300">
<view class="vtkMRMLSliceNode" singletontag="Red3">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
</layout>
</item>
</layout>
"""
# Built-in layout IDs are all below 100, so you can choose any large random number
# for your custom layout ID.
customLayoutId = 503
layoutManager.layoutLogic().GetLayoutNode().AddLayoutDescription(customLayoutId, customLayout)
# Switch to the new custom layout
layoutManager.setLayout(customLayoutId)
customLayout = """
<layout type="horizontal">
<item splitSize="500">
<view class="vtkMRMLSliceNode" singletontag="Red">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
<item splitSize="500">
<view class="vtkMRMLSliceNode" singletontag="Red1">
<property name="orientation" action="default">Axial</property>
<property name="viewlabel" action="default">R</property>
<property name="viewcolor" action="default">#F34A33</property>
</view>
</item>
</layout>
"""
# Built-in layout IDs are all below 100, so you can choose any large random number
# for your custom layout ID.
customLayoutId = 502
layoutManager.layoutLogic().GetLayoutNode().AddLayoutDescription(customLayoutId, customLayout)
# Switch to the new custom layout
layoutManager.setLayout(customLayoutId)
Thank you for your help!