Skip to content

Commit

Permalink
STYLE: Editor-editUtil: Change EditUtil class method to be static
Browse files Browse the repository at this point in the history
This simplifies the code avoiding to explicitly instantiate the EditUtil
class.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@24327 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information
jcfr committed Jun 17, 2015
1 parent 801f018 commit aa71a55
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 123 deletions.
23 changes: 9 additions & 14 deletions Modules/Scripted/Editor/Editor.py
Expand Up @@ -2,6 +2,7 @@
from __main__ import slicer
import qt, ctk, vtk
import EditorLib
from EditorLib.EditUtil import EditUtil

#
# Editor
Expand Down Expand Up @@ -50,14 +51,8 @@ def __init__(self, parent=None, showVolumesFrame=True):

# set attributes from ctor parameters
self.showVolumesFrame = showVolumesFrame
# TODO: figure out why module/class hierarchy is different
# between developer builds ans packages
try:
# for developer build...
self.editUtil = EditorLib.EditUtil.EditUtil()
except AttributeError:
# for release package...
self.editUtil = EditorLib.EditUtil()

self.editUtil = EditUtil() # Kept for backward compatibility

if not parent:
self.parent = slicer.qMRMLWidget()
Expand Down Expand Up @@ -94,12 +89,12 @@ def installShortcutKeys(self):
Key_Space = 0x20 # not in PythonQt
self.shortcuts = []
keysAndCallbacks = (
('e', self.editUtil.toggleLabel),
('e', EditUtil.toggleLabel),
('z', self.toolsBox.undoRedo.undo),
('y', self.toolsBox.undoRedo.redo),
('h', self.editUtil.toggleCrosshair),
('o', self.editUtil.toggleLabelOutline),
('t', self.editUtil.toggleForegroundBackground),
('h', EditUtil.toggleCrosshair),
('o', EditUtil.toggleLabelOutline),
('t', EditUtil.toggleForegroundBackground),
(Key_Escape, self.toolsBox.defaultEffect),
('p', lambda : self.toolsBox.selectEffect('PaintEffect')),
('d', lambda : self.toolsBox.selectEffect('DrawEffect')),
Expand Down Expand Up @@ -137,7 +132,7 @@ def enter(self):
# since we are in the editor) to get the current background and label
# - set the foreground layer as the active ID
# in the selection node for later calls to PropagateVolumeSelection
compositeNode = self.editUtil.getCompositeNode()
compositeNode = EditUtil.getCompositeNode()
selectionNode = slicer.app.applicationLogic().GetSelectionNode()
selectionNode.SetReferenceSecondaryVolumeID( compositeNode.GetForegroundVolumeID() )
bgID = lbID = ""
Expand All @@ -154,7 +149,7 @@ def enter(self):

# Observe the parameter node in order to make changes to
# button states as needed
self.parameterNode = self.editUtil.getParameterNode()
self.parameterNode = EditUtil.getParameterNode()
self.parameterNodeTag = self.parameterNode.AddObserver(vtk.vtkCommand.ModifiedEvent, self.updateGUIFromMRML)

if self.helper:
Expand Down
29 changes: 15 additions & 14 deletions Modules/Scripted/EditorLib/EditBox.py
@@ -1,8 +1,10 @@
import os
import slicer
import vtk
from __main__ import qt
from EditOptions import *
import EditUtil
import EditorLib
from EditUtil import EditUtil
from EditUtil import UndoRedo
from slicer.util import VTKObservationMixin

#########################################################
Expand Down Expand Up @@ -33,8 +35,7 @@ def __init__(self, parent=None, optionsFrame=None):
self.effectActionGroup.connect('triggered(QAction*)', self._onEffectActionTriggered)
self.effectActionGroup.exclusive = True
self.currentEffect = None
self.editUtil = EditUtil.EditUtil()
self.undoRedo = EditUtil.UndoRedo()
self.undoRedo = UndoRedo()
self.undoRedo.stateChangedCallback = self.updateUndoRedoButtons
self.toggleShortcut = None

Expand Down Expand Up @@ -82,7 +83,7 @@ def __init__(self, parent=None, optionsFrame=None):
self.addObserver(interactionNode, interactionNode.InteractionModeChangedEvent, self.onInteractionModeChanged)

# Listen for changed on the Parameter node
self.addObserver(self.editUtil.getParameterNode(), vtk.vtkCommand.ModifiedEvent, self._onParameterNodeModified)
self.addObserver(EditUtil.getParameterNode(), vtk.vtkCommand.ModifiedEvent, self._onParameterNodeModified)

if not parent:
self.parent = qt.QFrame()
Expand All @@ -103,9 +104,9 @@ def onInteractionModeChanged(self, caller, event):

def _onParameterNodeModified(self, caller, event=-1):
self._onEffectChanged(caller.GetParameter("effect"))
self.editUtil.setEraseEffectEnabled(self.editUtil.isEraseEffectEnabled())
self.actions["EraseLabel"].checked = self.editUtil.isEraseEffectEnabled()
self.actions[self.editUtil.getCurrentEffect()].checked = True
EditUtil.setEraseEffectEnabled(EditUtil.isEraseEffectEnabled())
self.actions["EraseLabel"].checked = EditUtil.isEraseEffectEnabled()
self.actions[EditUtil.getCurrentEffect()].checked = True

#
# Public lists of the available effects provided by the editor
Expand Down Expand Up @@ -234,7 +235,7 @@ def _onEffectActionTriggered(self, action):
self.selectEffect(action.property('effectName'))

def _onEraseLabelActionTriggered(self, enabled):
self.editUtil.setEraseEffectEnabled(enabled)
EditUtil.setEraseEffectEnabled(enabled)

# create the edit box
def create(self):
Expand Down Expand Up @@ -286,7 +287,7 @@ def create(self):
vbox.addStretch(1)

self.updateUndoRedoButtons()
self._onParameterNodeModified(self.editUtil.getParameterNode())
self._onParameterNodeModified(EditUtil.getParameterNode())

def setActiveToolLabel(self,name):
if EditBox.displayNames.has_key(name):
Expand All @@ -300,7 +301,7 @@ def defaultEffect(self):
self.selectEffect("DefaultTool")

def selectEffect(self, effectName):
self.editUtil.setCurrentEffect(effectName)
EditUtil.setCurrentEffect(effectName)

#
# manage the editor effects
Expand All @@ -313,14 +314,14 @@ def _onEffectChanged(self, effectName):
#
# If there is no background volume or label map, do nothing
#
if not self.editUtil.getBackgroundVolume():
if not EditUtil.getBackgroundVolume():
return
if not self.editUtil.getLabelVolume():
if not EditUtil.getLabelVolume():
return

self.currentEffect = effectName

self.editUtil.restoreLabel()
EditUtil.restoreLabel()

# Update action
self.actions[effectName].checked = True
Expand Down
11 changes: 5 additions & 6 deletions Modules/Scripted/EditorLib/EditColor.py
Expand Up @@ -2,7 +2,7 @@
from __main__ import qt
from __main__ import vtk
import ColorBox
import EditUtil
from EditUtil import EditUtil

#########################################################
#
Expand All @@ -24,7 +24,6 @@ def __init__(self, parent=0, parameter='label',colorNode=None):
self.parameterNode = None
self.parameterNodeTag = None
self.parameter = parameter
self.editUtil = EditUtil.EditUtil()
self.colorBox = None
self.colorNode = colorNode
if parent == 0:
Expand Down Expand Up @@ -63,7 +62,7 @@ def create(self):
self.colorSpin = qt.QSpinBox(self.frame)
self.colorSpin.objectName = 'ColorSpinBox'
self.colorSpin.setMaximum( 64000)
self.colorSpin.setValue( self.editUtil.getLabel() )
self.colorSpin.setValue( EditUtil.getLabel() )
self.colorSpin.setToolTip( "Click colored patch at right to bring up color selection pop up window. Use the 'c' key to bring up color popup menu." )
self.frame.layout().addWidget(self.colorSpin)

Expand All @@ -90,7 +89,7 @@ def updateParameterNode(self, caller, event):
#
# observe the scene to know when to get the parameter node
#
parameterNode = self.editUtil.getParameterNode()
parameterNode = EditUtil.getParameterNode()
if parameterNode != self.parameterNode:
if self.parameterNode:
self.parameterNode.RemoveObserver(self.parameterNodeTag)
Expand All @@ -112,7 +111,7 @@ def updateGUIFromMRML(self,caller,event):
return
label = int(self.parameterNode.GetParameter(self.parameter))

self.colorNode = self.editUtil.getColorNode()
self.colorNode = EditUtil.getColorNode()
if self.colorNode:
self.frame.setDisabled(0)
self.labelName.setText( self.colorNode.GetColorName( label ) )
Expand All @@ -137,7 +136,7 @@ def updateGUIFromMRML(self,caller,event):


def showColorBox(self):
self.colorNode = self.editUtil.getColorNode()
self.colorNode = EditUtil.getColorNode()

if not self.colorBox:
self.colorBox = ColorBox.ColorBox(parameterNode=self.parameterNode, parameter=self.parameter, colorNode=self.colorNode)
Expand Down
6 changes: 3 additions & 3 deletions Modules/Scripted/EditorLib/EditOptions.py
Expand Up @@ -3,7 +3,7 @@
from __main__ import ctk
from __main__ import vtk
from __main__ import getNodes
import EditUtil
from EditUtil import EditUtil

#########################################################
#
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self, parent=None):
self.widgets = []
self.parameterNode = None
self.parameterNodeTag = None
self.editUtil = EditUtil.EditUtil()
self.editUtil = EditUtil() # Kept for backward compatibility
self.tools = []

# connections is a list of widget/signal/slot tripples
Expand Down Expand Up @@ -165,7 +165,7 @@ def getBackgroundScalarRange(self):
success = False
lo = -1
hi = -1
backgroundVolume = self.editUtil.getBackgroundVolume()
backgroundVolume = EditUtil.getBackgroundVolume()
if backgroundVolume:
backgroundImage = backgroundVolume.GetImageData()
if backgroundImage:
Expand Down

0 comments on commit aa71a55

Please sign in to comment.