1 import vtk, qt, ctk, slicer
3 from AbstractScriptedSubjectHierarchyPlugin
import *
6 """ Scripted subject hierarchy plugin for the Annotations module. 8 This is also an example for scripted plugins, so includes all possible methods. 9 The methods that are not needed (i.e. the default implementation in 10 qSlicerSubjectHierarchyAbstractPlugin is satisfactory) can simply be 11 omitted in plugins created based on this one. 13 The plugin registers itself on creation, but needs to be initialized from the 14 module or application as follows: 15 from SubjectHierarchyPlugins import AnnotationsSubjectHierarchyPlugin 16 scriptedPlugin = slicer.qSlicerSubjectHierarchyScriptedPlugin(None) 17 scriptedPlugin.setPythonSource(AnnotationsSubjectHierarchyPlugin.filePath) 24 scriptedPlugin.name =
'Annotations' 25 AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin)
29 if node.IsA(
"vtkMRMLAnnotationROINode")
or node.IsA(
"vtkMRMLAnnotationRulerNode"):
34 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
35 shNode = pluginHandlerSingleton.subjectHierarchyNode()
36 associatedNode = shNode.GetItemDataNode(itemID)
38 if associatedNode
is not None:
39 if associatedNode.IsA(
"vtkMRMLAnnotationROINode")
or associatedNode.IsA(
"vtkMRMLAnnotationRulerNode"):
61 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
62 shNode = pluginHandlerSingleton.subjectHierarchyNode()
63 associatedNode = shNode.GetItemDataNode(itemID);
64 if associatedNode
is not None:
66 if associatedNode.IsA(
"vtkMRMLAnnotationROINode"):
67 roiIconPath = os.path.join(os.path.dirname(__file__),
'../Resources/Icons/AnnotationROI.png')
68 if os.path.exists(roiIconPath):
69 return qt.QIcon(roiIconPath)
71 if associatedNode.IsA(
"vtkMRMLAnnotationRulerNode"):
72 rulerIconPath = os.path.join(os.path.dirname(__file__),
'../Resources/Icons/AnnotationDistance.png')
73 if os.path.exists(rulerIconPath):
74 return qt.QIcon(rulerIconPath)
79 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
80 return pluginHandlerSingleton.pluginByName(
'Default').
visibilityIcon(visible)
83 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
84 pluginHandlerSingleton.pluginByName(
'Default').
editProperties(itemID)
97 In order to use view menus in scripted plugins, it needs to be registered differently, 98 so that the Python API can be fully built by the time this function is called. 100 The following changes are necessary: 101 1. Remove or comment out the following line from constructor 102 AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) 103 2. In addition to the initialization where the scripted plugin is instantialized and 104 the source set, the plugin also needs to be registered manually: 105 pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler.instance() 106 pluginHandler.registerPlugin(scriptedPlugin) 114 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
115 tooltip = pluginHandlerSingleton.pluginByName(
'Default').
tooltip(itemID)
119 pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
123 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)