Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
AnnotationsSubjectHierarchyPlugin.py
Go to the documentation of this file.
1 import vtk, qt, ctk, slicer
2 import logging
3 from AbstractScriptedSubjectHierarchyPlugin import *
4 
6  """ Scripted subject hierarchy plugin for the Annotations module.
7 
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.
12  """
13 
14  # Necessary static member to be able to set python source to scripted subject hierarchy plugin
15  filePath = __file__
16 
17  def __init__(self, scriptedPlugin):
18  scriptedPlugin.name = 'Annotations'
19  AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin)
20 
21  def canAddNodeToSubjectHierarchy(self, node, parentItemID):
22  if node is not None:
23  if node.IsA("vtkMRMLAnnotationROINode") or node.IsA("vtkMRMLAnnotationRulerNode"):
24  return 1.0
25  return 0.0
26 
27  def canOwnSubjectHierarchyItem(self, itemID):
28  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
29  shNode = pluginHandlerSingleton.subjectHierarchyNode()
30  associatedNode = shNode.GetItemDataNode(itemID)
31  # ROI or Ruler
32  if associatedNode is not None:
33  if associatedNode.IsA("vtkMRMLAnnotationROINode") or associatedNode.IsA("vtkMRMLAnnotationRulerNode"):
34  return 1.0
35  return 0.0
36 
37  def roleForPlugin(self):
38  return "Annotation"
39 
40  def helpText(self):
41  # return ("<p style=\" margin-top:4px; margin-bottom:1px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
42  # "<span style=\" font-family:'sans-serif'; font-size:9pt; font-weight:600; color:#000000;\">"
43  # "SegmentEditor module subject hierarchy help text"
44  # "</span>"
45  # "</p>"
46  # "<p style=\" margin-top:0px; margin-bottom:11px; margin-left:26px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
47  # "<span style=\" font-family:'sans-serif'; font-size:9pt; color:#000000;\">"
48  # "This is how you can add help text to the subject hierarchy module help box via a python scripted plugin."
49  # "</span>"
50  # "</p>\n")
51  return ""
52 
53  def icon(self, itemID):
54  import os
55  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
56  shNode = pluginHandlerSingleton.subjectHierarchyNode()
57  associatedNode = shNode.GetItemDataNode(itemID);
58  if associatedNode is not None:
59  # ROI
60  if associatedNode.IsA("vtkMRMLAnnotationROINode"):
61  roiIconPath = os.path.join(os.path.dirname(__file__), '../Resources/Icons/AnnotationROI.png')
62  if os.path.exists(roiIconPath):
63  return qt.QIcon(roiIconPath)
64  # Ruler
65  if associatedNode.IsA("vtkMRMLAnnotationRulerNode"):
66  rulerIconPath = os.path.join(os.path.dirname(__file__), '../Resources/Icons/AnnotationDistance.png')
67  if os.path.exists(rulerIconPath):
68  return qt.QIcon(rulerIconPath)
69  # Item unknown by plugin
70  return qt.QIcon()
71 
72  def visibilityIcon(self, visible):
73  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
74  return pluginHandlerSingleton.pluginByName('Default').visibilityIcon(visible)
75 
76  def editProperties(self, itemID):
77  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
78  pluginHandlerSingleton.pluginByName('Default').editProperties(itemID)
79 
81  return []
82 
84  return []
85 
86  def showContextMenuActionsForItem(self, itemID):
87  pass
88 
89  def tooltip(self, itemID):
90  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
91  tooltip = pluginHandlerSingleton.pluginByName('Default').tooltip(itemID)
92  return str(tooltip)
93 
94  def setDisplayVisibility(self, itemID, visible):
95  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
96  pluginHandlerSingleton.pluginByName('Default').setDisplayVisibility(itemID, visible)
97 
98  def getDisplayVisibility(self, itemID):
99  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
100  return pluginHandlerSingleton.pluginByName('Default').getDisplayVisibility(itemID)