Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
guiConnectors.py
Go to the documentation of this file.
1from slicer import qMRMLSubjectHierarchyTreeView
2from slicer.parameterNodeWrapper import (
3 isNodeOrUnionOfNodes,
4 getNodeTypes,
5 GuiConnector,
6 parameterNodeGuiConnector,
7)
8
9
10@parameterNodeGuiConnector
12 @staticmethod
13 def canRepresent(widget, datatype) -> bool:
14 return type(widget) == qMRMLSubjectHierarchyTreeView and isNodeOrUnionOfNodes(datatype)
15
16 @staticmethod
17 def create(widget, datatype):
18 if qMRMLSubjectHierarchyTreeViewToNodeConnector.canRepresent(widget, datatype):
20 return None
21
22 def __init__(self, widget: qMRMLSubjectHierarchyTreeView, datatype):
23 super().__init__()
24 self._widget: qMRMLSubjectHierarchyTreeView = widget
25 self._widget.nodeTypes = getNodeTypes(datatype)
26
27 def _connect(self):
28 self._widget.currentItemsChanged.connect(self.changed)
29
30 def _disconnect(self):
31 self._widget.currentItemsChanged.disconnect(self.changed)
32
33 def widget(self) -> qMRMLSubjectHierarchyTreeView:
34 return self._widget
35
36 def read(self):
37 itemId = self._widget.currentItem()
38 shNode = self._widget.subjectHierarchyNode()
39 if itemId == shNode.GetInvalidItemID():
40 return None
41 else:
42 return shNode.GetItemDataNode(itemId)
43
44 def write(self, value) -> None:
45 if value is not None:
46 self._widget.setCurrentNode(value)
47 else:
48 self._widget.clearSelection()