Slicer  5.3
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 qt
2 
3 import slicer
4 
5 from AbstractScriptedSubjectHierarchyPlugin import *
6 
7 
9  """ Scripted subject hierarchy plugin for the Annotations module.
10 
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.
15 
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)
21  """
22 
23  # Necessary static member to be able to set python source to scripted subject hierarchy plugin
24  filePath = __file__
25 
26  def __init__(self, scriptedPlugin):
27  scriptedPlugin.name = 'Annotations'
28  AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin)
29 
30  def canAddNodeToSubjectHierarchy(self, node, parentItemID):
31  if node is not None:
32  if node.IsA("vtkMRMLAnnotationROINode") or node.IsA("vtkMRMLAnnotationRulerNode"):
33  return 1.0
34  return 0.0
35 
36  def canOwnSubjectHierarchyItem(self, itemID):
37  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
38  shNode = pluginHandlerSingleton.subjectHierarchyNode()
39  associatedNode = shNode.GetItemDataNode(itemID)
40  # ROI or Ruler
41  if associatedNode is not None:
42  if associatedNode.IsA("vtkMRMLAnnotationROINode") or associatedNode.IsA("vtkMRMLAnnotationRulerNode"):
43  return 1.0
44  return 0.0
45 
46  def roleForPlugin(self):
47  return "Annotation"
48 
49  def helpText(self):
50  # return ("<p style=\" margin-top:4px; margin-bottom:1px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
51  # "<span style=\" font-family:'sans-serif'; font-size:9pt; font-weight:600; color:#000000;\">"
52  # "SegmentEditor module subject hierarchy help text"
53  # "</span>"
54  # "</p>"
55  # "<p style=\" margin-top:0px; margin-bottom:11px; margin-left:26px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
56  # "<span style=\" font-family:'sans-serif'; font-size:9pt; color:#000000;\">"
57  # "This is how you can add help text to the subject hierarchy module help box via a python scripted plugin."
58  # "</span>"
59  # "</p>\n")
60  return ""
61 
62  def icon(self, itemID):
63  import os
64  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
65  shNode = pluginHandlerSingleton.subjectHierarchyNode()
66  associatedNode = shNode.GetItemDataNode(itemID)
67  if associatedNode is not None:
68  # ROI
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)
73  # Ruler
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)
78  # Item unknown by plugin
79  return qt.QIcon()
80 
81  def visibilityIcon(self, visible):
82  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
83  return pluginHandlerSingleton.pluginByName('Default').visibilityIcon(visible)
84 
85  def editProperties(self, itemID):
86  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
87  pluginHandlerSingleton.pluginByName('Default').editProperties(itemID)
88 
90  return []
91 
93  return []
94 
95  def showContextMenuActionsForItem(self, itemID):
96  pass
97 
99  """ Important note:
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.
102 
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)
110  """
111  return []
112 
113  def showViewContextMenuActionsForItem(self, itemID, eventData):
114  pass
115 
116  def tooltip(self, itemID):
117  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
118  tooltip = pluginHandlerSingleton.pluginByName('Default').tooltip(itemID)
119  return str(tooltip)
120 
121  def setDisplayVisibility(self, itemID, visible):
122  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
123  pluginHandlerSingleton.pluginByName('Default').setDisplayVisibility(itemID, visible)
124 
125  def getDisplayVisibility(self, itemID):
126  pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance()
127  return pluginHandlerSingleton.pluginByName('Default').getDisplayVisibility(itemID)