5 from AbstractScriptedSubjectHierarchyPlugin
import *
9 """ Scripted subject hierarchy plugin for the Annotations module. 11 This is also an example for scripted plugins, so includes all possible methods. 12 The methods that are not needed (i.e. the default implementation in 13 qSlicerSubjectHierarchyAbstractPlugin is satisfactory) can simply be 14 omitted in plugins created based on this one. 16 The plugin registers itself on creation, but needs to be initialized from the 17 module or application as follows: 18 from SubjectHierarchyPlugins import AnnotationsSubjectHierarchyPlugin 19 scriptedPlugin = slicer.qSlicerSubjectHierarchyScriptedPlugin(None) 20 scriptedPlugin.setPythonSource(AnnotationsSubjectHierarchyPlugin.filePath) 27 scriptedPlugin.name =
'Annotations' 28 AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin)
32 if node.IsA(
"vtkMRMLAnnotationROINode")
or node.IsA(
"vtkMRMLAnnotationRulerNode"):
37 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
38 shNode = pluginHandlerSingleton.subjectHierarchyNode()
39 associatedNode = shNode.GetItemDataNode(itemID)
41 if associatedNode
is not None:
42 if associatedNode.IsA(
"vtkMRMLAnnotationROINode")
or associatedNode.IsA(
"vtkMRMLAnnotationRulerNode"):
64 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
65 shNode = pluginHandlerSingleton.subjectHierarchyNode()
66 associatedNode = shNode.GetItemDataNode(itemID)
67 if associatedNode
is not None:
69 if associatedNode.IsA(
"vtkMRMLAnnotationROINode"):
70 roiIconPath = os.path.join(os.path.dirname(__file__),
'../Resources/Icons/AnnotationROI.png')
71 if os.path.exists(roiIconPath):
72 return qt.QIcon(roiIconPath)
74 if associatedNode.IsA(
"vtkMRMLAnnotationRulerNode"):
75 rulerIconPath = os.path.join(os.path.dirname(__file__),
'../Resources/Icons/AnnotationDistance.png')
76 if os.path.exists(rulerIconPath):
77 return qt.QIcon(rulerIconPath)
82 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
83 return pluginHandlerSingleton.pluginByName(
'Default').
visibilityIcon(visible)
86 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
87 pluginHandlerSingleton.pluginByName(
'Default').
editProperties(itemID)
100 In order to use view menus in scripted plugins, it needs to be registered differently, 101 so that the Python API can be fully built by the time this function is called. 103 The following changes are necessary: 104 1. Remove or comment out the following line from constructor 105 AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) 106 2. In addition to the initialization where the scripted plugin is instantialized and 107 the source set, the plugin also needs to be registered manually: 108 pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler.instance() 109 pluginHandler.registerPlugin(scriptedPlugin) 117 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
118 tooltip = pluginHandlerSingleton.pluginByName(
'Default').
tooltip(itemID)
122 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
126 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
def sceneContextMenuActions(self)
def viewContextMenuActions(self)
def itemContextMenuActions(self)
def setDisplayVisibility(self, itemID, visible)
def canOwnSubjectHierarchyItem(self, itemID)
def visibilityIcon(self, visible)
def getDisplayVisibility(self, itemID)
def tooltip(self, itemID)
def canAddNodeToSubjectHierarchy(self, node, parentItemID)
def showContextMenuActionsForItem(self, itemID)
def editProperties(self, itemID)
def __init__(self, scriptedPlugin)
def showViewContextMenuActionsForItem(self, itemID, eventData)