def installShortcutKeys(self): """Turn on editor-wide shortcuts. These are active independent of the currently selected effect.""" Key_Escape = 0x01000000 # not in PythonQt Key_Space = 0x20 # not in PythonQt self.shortcuts = [] keysAndCallbacks = ( ('z', self.toolsBox.undoRedo.undo), ('y', self.toolsBox.undoRedo.redo), ('h', self.editUtil.toggleCrosshair), ('o', self.editUtil.toggleLabelOutline), ('t', self.editUtil.toggleForegroundBackground), (Key_Escape, self.toolsBox.defaultEffect), ('p', lambda: self.toolsBox.selectEffect('PaintEffect')), ('1', self.toolsBox.onDefaultChangeIslandButtonClicked), ('2', self.toolsBox.onLMchangeIslandButtonClicked), ('3', self.toolsBox.onLADchangeIslandButtonClicked), ('4', self.toolsBox.onLCXchangeIslandButtonClicked), ('5', self.toolsBox.onRCAchangeIslandButtonClicked), ) for key, callback in keysAndCallbacks: shortcut = qt.QShortcut(slicer.util.mainWindow()) shortcut.setKey(qt.QKeySequence(key)) shortcut.connect('activated()', callback) self.shortcuts.append(shortcut)
def setupKeyboardShortcuts(self): shortcuts = [ ('Ctrl+3', lambda: slicer.util.mainWindow().pythonConsole().parent().setVisible(not slicer.util.mainWindow().pythonConsole().parent().visible)) ] for (shortcutKey, callback) in shortcuts: shortcut = qt.QShortcut(slicer.util.mainWindow()) shortcut.setKey(qt.QKeySequence(shortcutKey)) shortcut.connect('activated()', callback)
def enterFloatingMode(self): self.mainFrame.setParent(None) cursorPosition = qt.QCursor().pos() w = self.mainFrame.width h = self.mainFrame.height self.mainFrame.pos = qt.QPoint(cursorPosition.x() - w/2, cursorPosition.y() - h/2) self.mainFrame.show() self.mainFrame.raise_() Key_Space = 0x20 # not in PythonQt self.toggleShortcut = qt.QShortcut(self.mainFrame) self.toggleShortcut.setKey( qt.QKeySequence(Key_Space) ) self.toggleShortcut.connect( 'activated()', self.toggleFloatingMode )
def init_fGrowCut(self): self.emergencyStopFunc = None self.dialogBox = qt.QMessageBox( ) #will display messages to draw users attention if he does anything wrong self.dialogBox.setWindowTitle("Fast GrowCut Error") self.dialogBox.setWindowModality( qt.Qt.NonModal ) #will allow user to continue interacting with Slicer # TODO: check this claim- might be causing leaks # set the image, label nodes (this will not change although the user can # alter what is bgrnd/frgrnd in editor) # Confused about how info propagates UIarray to UIVol, not the other way, NEEDS AUTO TESTS self.labelNode = self.editUtil.getLabelVolume( ) #labelLogic.GetVolumeNode() self.backgroundNode = self.editUtil.getBackgroundVolume( ) #backgroundLogic.GetVolumeNode() #perform safety check on right images/labels being selected, #set up images #if red slice doesnt have a label or image, go no further if type(self.backgroundNode) == type(None) or type( self.labelNode) == type(None): self.dialogBox.setText( "Either Image (must be Background Image) or Label not set in slice views." ) self.dialogBox.show() if self.emergencyStopFunc: self.emergencyStopFunc() return volumesLogic = slicer.modules.volumes.logic() self.labelName = self.labelNode.GetName( ) # record name of label so user, cant trick us self.imgName = self.backgroundNode.GetName() if self.sliceViewMatchEditor( self.sliceLogic ) == False: # do nothing, exit function if user has played with images if self.emergencyStopFunc: self.emergencyStopFunc() return # fast growcut shortcuts resetFGC = qt.QKeySequence(qt.Qt.Key_R) # reset initialization flag runFGC = qt.QKeySequence(qt.Qt.Key_G) # run fast growcut editSeed = qt.QKeySequence(qt.Qt.Key_S) # edit seed labels print " keys for reset init, run GC, edit seed are R,G, S" self.qtkeyconnections = [] self.qtkeydefsGrowcut = [[resetFGC, self.resetFastGrowCutFlag], [runFGC, self.runFastGrowCut], [editSeed, self.editGrowCutSeed]] for keydef in self.qtkeydefsGrowcut: s = qt.QShortcut(keydef[0], slicer.util.mainWindow() ) # connect this qt event to mainWindow focus #s.setContext(1) s.connect('activated()', keydef[1]) #s.connect('activatedAmbiguously()', keydef[1]) self.qtkeyconnections.append(s) self.fGCLabelMod_tag = self.sliceLogic.AddObserver( "ModifiedEvent", self.FastGrowCutChangeLabelInput ) # put test listener on the whole window # fast grow cut parameters self.bSegmenterInitialized = "no" self.bEditGrowCutSeed = True self.currentMessage = "" seedArray = slicer.util.array(self.labelName) self.growCutSeedArray = seedArray.copy() self.growCutSegArray = seedArray.copy() self.growCutSeedArray[:] = 0 self.growCutSegArray[:] = 0 import vtkSlicerFastGrowCutModuleLogicPython fastGCMod = vtkSlicerFastGrowCutModuleLogicPython.vtkFastGrowCutSeg() fastGCMod.SetSourceVol(self.backgroundNode.GetImageData()) fastGCMod.SetSeedVol(self.labelNode.GetImageData()) fastGCMod.Initialization() self.fastGCMod = fastGCMod self.fastCrowCutCreated = True #tracks if completed the initializtion (so can do stop correctly) of KSlice
def init_fCleverSeg(self): slicer.util.showStatusMessage("Checking CleverSeg inputs...") if not self.areInputsValid(): logging.warning(self.getInvalidInputsMessage()) background = self.editUtil.getBackgroundVolume() labelInput = self.editUtil.getLabelVolume() if not slicer.util.confirmOkCancelDisplay( "Current image type is '{0}' and labelmap type is '{1}'. CleverSeg only works " "reliably with 'short' type.\n\nIf the segmentation result is not satisfactory" ", then cast the image and labelmap to 'short' type (using Cast Scalar Volume " "module) or install CleverSeg extension and use CleverSegEffect editor " "tool.".format( self.editUtil.getBackgroundVolume().GetImageData( ).GetScalarTypeAsString(), self.editUtil.getLabelVolume().GetImageData(). GetScalarTypeAsString()), windowTitle='Editor'): logging.warning('CleverSeg is cancelled by the user') return self.emergencyStopFunc = None self.dialogBox = qt.QMessageBox( ) # will display messages to draw users attention if he does anything wrong self.dialogBox.setWindowTitle("CleverSeg Error") self.dialogBox.setWindowModality( qt.Qt.NonModal ) # will allow user to continue interacting with Slicer # TODO: check this claim- might be causing leaks # set the image, label nodes (this will not change although the user can # alter what is bgrnd/frgrnd in editor) # Confused about how info propagates UIarray to UIVol, not the other way, NEEDS AUTO TESTS self.labelNode = self.editUtil.getLabelVolume( ) # labelLogic.GetVolumeNode() self.backgroundNode = self.editUtil.getBackgroundVolume( ) # backgroundLogic.GetVolumeNode() # perform safety check on right images/labels being selected, #set up images # if red slice doesnt have a label or image, go no further if type(self.backgroundNode) == type(None) or type( self.labelNode) == type(None): self.dialogBox.setText( "Either Image (must be Background Image) or Label not set in slice views." ) self.dialogBox.show() if self.emergencyStopFunc: self.emergencyStopFunc() return volumesLogic = slicer.modules.volumes.logic() self.labelName = self.labelNode.GetName( ) # record name of label so user, cant trick us self.imgName = self.backgroundNode.GetName() if self.sliceViewMatchEditor( self.sliceLogic ) == False: # do nothing, exit function if user has played with images if self.emergencyStopFunc: self.emergencyStopFunc() return # CleverSeg shortcuts resetCS = qt.QKeySequence(qt.Qt.Key_R) # reset initialization flag runCS = qt.QKeySequence(qt.Qt.Key_C) # run CleverSeg editSeed = qt.QKeySequence(qt.Qt.Key_S) # edit seed labels print " keys for reset init = R, run CS = C, edit seed = S" self.qtkeyconnections = [] self.qtkeydefsCleverSeg = [[resetCS, self.resetCleverSegFlag], [runCS, self.runCleverSeg], [editSeed, self.editCleverSegSeed]] for keydef in self.qtkeydefsCleverSeg: s = qt.QShortcut(keydef[0], slicer.util.mainWindow() ) # connect this qt event to mainWindow focus # s.setContext(1) s.connect('activated()', keydef[1]) # s.connect('activatedAmbiguously()', keydef[1]) self.qtkeyconnections.append(s) self.CSLabelMod_tag = self.sliceLogic.AddObserver( "ModifiedEvent", self.CleverSegChangeLabelInput ) # put test listener on the whole window # fast balanced growth parameters self.bSegmenterInitialized = "no" self.bEditCleverSegSeed = True self.currentMessage = "" seedArray = slicer.util.array(self.labelName) self.CleverSegSeedArray = seedArray.copy() self.CleverSegSegArray = seedArray.copy() self.CleverSegSeedArray[:] = 0 self.CleverSegSegArray[:] = 0 import vtkSlicerCleverSegModuleLogicPython cleverSegMod = vtkSlicerCleverSegModuleLogicPython.vtkCleverSeg() cleverSegMod.SetSourceVol(self.backgroundNode.GetImageData()) cleverSegMod.SetSeedVol(self.labelNode.GetImageData()) cleverSegMod.Initialization() self.cleverSegMod = cleverSegMod self.cleverSegCreated = True # tracks if completed the initializtion (so can do stop correctly) of KSlice