def setToolButtonMenu(self, toolButton, N): channelsNames = [] for i in range( slicer.mrmlScene.GetNumberOfNodesByClass( 'vtkMRMLAlphaOmegaChannelNode')): channelsNames.append( slicer.mrmlScene.GetNthNodeByClass( i, 'vtkMRMLAlphaOmegaChannelNode').GetChannelName()) if not channelsNames: return # init AOChannelsActionGroup = qt.QActionGroup(toolButton) # add none noneChannelAction = qt.QAction('None', toolButton) noneChannelAction.setCheckable(True) noneChannelAction.setChecked(True) AOChannelsActionGroup.addAction(noneChannelAction) # add for each channel for name in channelsNames: channelAction = qt.QAction(name, toolButton) channelAction.setCheckable(True) AOChannelsActionGroup.addAction(channelAction) # set menu toolButton.actions()[0].menu().clear() toolButton.actions()[0].menu().addActions( AOChannelsActionGroup.actions()) toolButton.actions()[0].menu().triggered.connect( lambda action, trajectoryN=N: self.logic. setNthTrajectoryAOChannelNode(trajectoryN, action.text))
def __init__(self, scriptedPlugin): self.logic = MarkupEditorLogic() self.selectOptions = { "set": "Set selection", "add": "Add to selection", "unset": "Remove from selection" } self.selectViewAction = qt.QAction(f"Pick points with curve...", scriptedPlugin) self.selectViewAction.objectName = 'SelectViewAction' self.selectViewAction.connect("triggered()", self.onSelectViewAction) self.selectMenu = qt.QMenu("Select Menu") self.selectViewAction.setMenu(self.selectMenu) for selectOption in self.selectOptions.keys(): action = self.selectMenu.addAction( self.selectOptions[selectOption]) slot = lambda selectOption=selectOption: self.onSelectViewAction( selectOption) action.connect("triggered()", slot) self.editViewAction = qt.QAction(f"Edit selected points", scriptedPlugin) self.editViewAction.objectName = 'EditViewAction' self.editViewAction.connect("triggered()", self.onEditViewAction) self.deleteViewAction = qt.QAction(f"Delete selected points", scriptedPlugin) self.deleteViewAction.objectName = 'DeleteViewAction' self.deleteViewAction.connect("triggered()", self.onDeleteViewAction) self.reset()
def __init__(self, scriptedPlugin): AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) self.exportAsAction = qt.QAction(f"Export as...", scriptedPlugin) self.exportTransformedAsAction = qt.QAction(f"Export transformed as...", scriptedPlugin) self.menu = qt.QMenu("Plugin Menu") self.transformedMenu = qt.QMenu("Transformed Plugin Menu") self.exportAsAction.setMenu(self.menu) self.exportTransformedAsAction.setMenu(self.transformedMenu)
def _setupActions(self): """ creates some actions needed on some menues and toolbars """ a = self._actions["close_shell"] = qt.QAction( qt.QIconSet(qt.QPixmap(os.path.join(CONF.getIconsPath(),"newshell.png"))), "&Close Shell", qt.Qt.CTRL + qt.Qt.Key_W, self, "New Shell" ) self.connect(a, qt.SIGNAL('activated()'), self.destroyShellTab) a = self._actions["new_shell"] = qt.QAction( qt.QIconSet(qt.QPixmap(os.path.join(CONF.getIconsPath(),"newshell.png"))), "&New Shell", qt.Qt.CTRL + qt.Qt.Key_T, self, "New Shell" ) self.connect(a, qt.SIGNAL('activated()'), self.createShellTab)
def onRightClick(self): menu = qt.QMenu() position = qt.QCursor.pos() action = qt.QAction("Delete highlighted fiducial(s)", menu) menu.addAction(action) connectObject = qt.QObject() connectObject.connect(action, 'triggered()', self.onDeleteOneFiducialButton) action2 = qt.QAction("Cancel", menu) menu.addAction(action2) connectObject.connect(action2, 'triggered()', menu.hide) menu.exec_(position)
def __init__(self, scriptedPlugin): AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance() self.subjectHierarchyNode = pluginHandlerSingleton.subjectHierarchyNode() self.exportAsAction = qt.QAction(f"Export as...", scriptedPlugin) self.exportTransformedAsAction = qt.QAction(f"Export transformed as...", scriptedPlugin) self.menu = qt.QMenu("Plugin Menu") self.transformedMenu = qt.QMenu("Transformed Plugin Menu") self.exportAsAction.setMenu(self.menu) self.exportTransformedAsAction.setMenu(self.transformedMenu)
def __init__(self, scriptedPlugin): scriptedPlugin.name = 'SegmentEditor' AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) self.segmentEditorAction = qt.QAction("Segment this...", scriptedPlugin) self.segmentEditorAction.connect("triggered()", self.onSegment)
def __init__(self, scriptedPlugin): AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) pluginHandlerSingleton = slicer.qSlicerSubjectHierarchyPluginHandler.instance() self.subjectHierarchyNode = pluginHandlerSingleton.subjectHierarchyNode() self.formatMarkupsAction = qt.QAction(f"Apply formatting to siblings", scriptedPlugin) self.menu = qt.QMenu("Plugin Menu") self.formatMarkupsAction.setMenu(self.menu)
def __init__(self, scriptedPlugin): scriptedPlugin.name = 'SegmentStatistics' AbstractScriptedSubjectHierarchyPlugin.__init__(self, scriptedPlugin) self.segmentStatisticsAction = qt.QAction("Calculate statistics...", scriptedPlugin) self.segmentStatisticsAction.connect("triggered()", self.onCalculateStatistics)
def __init__(self): toolTip = '' AbstractToolWidget.__init__(self, 'Draw', toolTip) # set up menu nearestModelAction = qt.QAction('To Nearest Model', self.effectButton) nearestModelAction.setCheckable(True) nearestModelAction.setChecked(True) twoLinesAction = qt.QAction('To Following Line', self.effectButton) twoLinesAction.setCheckable(True) actionsGroup = qt.QActionGroup(self.effectButton) actionsGroup.addAction(nearestModelAction) actionsGroup.addAction(twoLinesAction) menu = qt.QMenu(self.effectButton) menu.addActions(actionsGroup.actions()) self.effectButton.setMenu(menu) self.effectButton.setPopupMode(self.effectButton.DelayedPopup)
def addMenu(self): actionIcon = self.parent.icon a = qt.QAction(actionIcon, 'Download Sample Data', slicer.util.mainWindow()) a.setToolTip('Go to the SampleData module to download data from the network') a.connect('triggered()', self.select) fileMenu = slicer.util.lookupTopLevelWidget('FileMenu') if fileMenu: for action in fileMenu.actions(): if action.text == 'Save': fileMenu.insertAction(action,a)
def _addMenu(self, button): menu = qt.QMenu(button) menu.name = button.name button.setMenu(menu) actionGroup = qt.QActionGroup(menu) actionGroup.setExclusive(False) for name, enabled in [(self.LINEAR_MEASUREMENT, True), (self.VOLUMETRIC_MEASUREMENT, False)]: action = qt.QAction(name, actionGroup) action.setEnabled(enabled) menu.addAction(action) actionGroup.addAction(action) action.triggered.connect(lambda triggered, a=action: self._onActionTriggered(a))
def addMenu(self): actionIcon = self.parent.icon mTranslate = slicer.app.translate("qSlicerWelcomeModuleWidget", "Download Sample Data") a = qt.QAction(actionIcon, mTranslate, slicer.util.mainWindow()) a.setToolTip( 'Go to the SampleData module to download data from the network') a.connect('triggered()', self.select) fileMenu = slicer.util.lookupTopLevelWidget('FileMenu') if fileMenu: for action in fileMenu.actions(): if action.name == 'FileSaveSceneAction': fileMenu.insertAction(action, a)
def _addActions(self, menu, layer, volumeClass): actionGroup = qt.QActionGroup(menu) actionGroup.setExclusive(True) _, cNode = self.getWidgetAndCompositeNodeByName(menu.name) for volume in [None]+self.getAvailableVolumes(volumeClassName=volumeClass): action = qt.QAction(volume.GetName() if volume else "None", actionGroup) menu.addAction(action) actionGroup.addAction(action) action.setCheckable(True) action.triggered.connect(lambda triggered, l=layer, n=menu.name,v=volume: self._onImageSelectedFromMenu(l, n, v)) currentVolumeID = getattr(cNode, self.getCompositeGetterNameForLayer(layer))() imageID = volume.GetID() if volume else volume if currentVolumeID == imageID: action.setChecked(True)
def createButtonRow(self, effects, rowLabel=""): """ create a row of the edit box given a list of effect names (items in _effects(list) """ rowFrame = qt.QFrame(self.mainFrame) self.mainFrame.layout().addWidget(rowFrame) self.rowFrames.append(rowFrame) rowFrame.objectName = "RowFrame%s" % len(self.rowFrames) hbox = qt.QHBoxLayout() rowFrame.setLayout(hbox) if rowLabel: label = qt.QLabel(rowLabel) hbox.addWidget(label) for effect in effects: # check that the effect belongs in our list of effects before including if (effect in self.effects): i = self.icons[effect] = qt.QIcon(self.effectIconFiles[effect]) a = self.actions[effect] = qt.QAction(i, '', rowFrame) a.objectName = effect + 'Action' self.effectButtons[effect] = b = self.buttons[ effect] = qt.QToolButton() b.objectName = effect + 'ToolButton' b.setDefaultAction(a) a.setToolTip(effect) if EditBox.displayNames.has_key(effect): a.setToolTip(EditBox.displayNames[effect]) hbox.addWidget(b) if effect not in ('EraseLabel', 'PreviousCheckPoint', 'NextCheckPoint'): # Mapping between action and its associated effect, is done # in function'_onEffectActionTriggered' by retrieving the 'effectName' # property. a.checkable = True a.setProperty('effectName', effect) self.effectActionGroup.addAction(a) elif effect == 'EraseLabel': a.checkable = True a.connect('triggered(bool)', self._onEraseLabelActionTriggered) elif effect == 'PreviousCheckPoint': a.connect('triggered(bool)', self.undoRedo.undo) elif effect == 'NextCheckPoint': a.connect('triggered(bool)', self.undoRedo.redo) hbox.addStretch(1)
def _makeAction(parent, text, icon=None, shortcut=None, slot=None): action = qt.QAction(text, parent) if icon is not None: action.setIcon(qt.QIcon.fromTheme(icon)) if shortcut is not None: action.shortcut = qt.QKeySequence.fromString(shortcut) action.shortcutContext = qt.Qt.WidgetWithChildrenShortcut if slot is not None: action.connect('triggered(bool)', slot) parent.addAction(action) return action
def _addMenu(self, button): menu = qt.QMenu(button) menu.name = button.name button.setMenu(menu) actionGroup = qt.QActionGroup(menu) actionGroup.setExclusive(False) for name, enabled in [("Linear Measurement", True), ("Volumetric Measurement", False)]: action = qt.QAction(name, actionGroup) action.setEnabled(enabled) menu.addAction(action) actionGroup.addAction(action) action.triggered.connect( lambda triggered, a=action: self._onActionTriggered(a))
def _init_toolbar( self ): self.window.setUsesTextLabel( False ) basedir = matplotlib.rcParams[ 'datapath' ] for text, tooltip_text, image_file, callback in self.toolitems: if text == None: self.addSeparator() continue fname = os.path.join( basedir, image_file ) image = qt.QPixmap() image.load( fname ) a = qt.QAction( qt.QIconSet( image ), text, qt.QKeySequence('M'), self.window ) a.setToolTip( tooltip_text ) qt.QObject.connect( a, qt.SIGNAL( 'activated()' ), getattr( self, callback ) ) a.addTo( self )
def compileActions(group, actions, globals): newactions = {} for action in actions: #if len(action) > 5: # action = list(action) # code = compile(action[5], "<callback>", "exec") # def callback(action, code=code, globals=globals): # globals["action"] = action # exec code in globals # action[5] = callback act = qt.QAction(group, action[0]) act.setText(action[0]) act.setMenuText(action[2].replace("_","&")) if len(action) > 4: act.setToolTip(action[4]) if len(action) > 5 and type(action[5]) is not str: qt.QObject.connect(act, qt.SIGNAL("activated()") , action[5]) if action[0] == "find": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.toggleSearch) if action[0] == "update-selected-channels": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.updateSelected) if action[0] == "update-channels": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.updateChannels) if action[0] == "rebuild-cache": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.rebuildCache) if action[0] == "check-installed-packages": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.checkInstalledPackages) if action[0] == "check-uninstalled-packages": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.checkUninstalledPackages) if action[0] == "check-all-packages": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.checkAllPackages) if action[0] == "upgrade-all": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.upgradeAll) if action[0] == "fix-all-problems": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.fixAllProblems) if action[0] == "exec-changes": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.applyChanges) if action[0] == "undo": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.undo) if action[0] == "redo": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.redo) if action[0] == "clear-changes": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.clearChanges) if action[0] == "expand-all": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.expandPackages) if action[0] == "collapse-all": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.collapsePackages) if action[0] == "edit-channels": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.editChannels) if action[0] == "edit-mirrors": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.editMirrors) if action[0] == "edit-flags": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.editFlags) if action[0] == "edit-priorities": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.editPriorities) if action[0] == "summary-window": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.showChanges) if action[0] == "log-window": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.showLog) if action[0] == "legend-window": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.showLegend) if action[0] == "about": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), self.showAbout) if action[0] == "quit": #HACK self = globals["self"] qt.QObject.connect(act, qt.SIGNAL("activated()"), app, qt.SLOT("quit()")) group.add(act) #newactions[action[0]] = tuple(action) newactions[action[0]] = act return newactions
def setup(self): ScriptedLoadableModuleWidget.setup(self) # tracks the modified event observer on the currently # selected sequence browser node self.sequenceBrowserObserverRecord = None self.animatorActionsGUI = None self.logic = AnimatorLogic() # Instantiate and connect widgets ... # # Parameters Area # parametersCollapsibleButton = ctk.ctkCollapsibleButton() parametersCollapsibleButton.text = "Animation Parameters" self.layout.addWidget(parametersCollapsibleButton) # Layout within the dummy collapsible button parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) self.durationBox = ctk.ctkDoubleSpinBox() self.durationBox.suffix = " seconds" self.durationBox.decimals = 1 self.durationBox.minimum = 1 self.durationBox.value = 5 self.durationBox.toolTip = "Duration cannot be changed after animation created" parametersFormLayout.addRow("New animation duration", self.durationBox) # # animation selector # self.animationSelector = slicer.qMRMLNodeComboBox() self.animationSelector.nodeTypes = ["vtkMRMLScriptedModuleNode"] self.animationSelector.setNodeTypeLabel("Animation", "vtkMRMLScriptedModuleNode") self.animationSelector.selectNodeUponCreation = True self.animationSelector.addEnabled = True self.animationSelector.addAttribute("vtkMRMLScriptedModuleNode", "ModuleName", "Animation") self.animationSelector.baseName = "Animation" self.animationSelector.removeEnabled = True self.animationSelector.noneEnabled = True self.animationSelector.showHidden = True self.animationSelector.showChildNodeTypes = False self.animationSelector.setMRMLScene( slicer.mrmlScene ) self.animationSelector.setToolTip( "Pick the animation description." ) parametersFormLayout.addRow("Animation Node: ", self.animationSelector) self.sequencePlay = slicer.qMRMLSequenceBrowserPlayWidget() self.sequencePlay.setMRMLScene(slicer.mrmlScene) self.sequenceSeek = slicer.qMRMLSequenceBrowserSeekWidget() self.sequenceSeek.setMRMLScene(slicer.mrmlScene) parametersFormLayout.addRow(self.sequencePlay) parametersFormLayout.addRow(self.sequenceSeek) self.actionsMenuButton = qt.QPushButton("Add Action") self.actionsMenuButton.enabled = False self.actionsMenu = qt.QMenu() self.actionsMenuButton.setMenu(self.actionsMenu) for actionName in slicer.modules.animatorActionPlugins.keys(): qAction = qt.QAction(actionName, self.actionsMenu) qAction.connect('triggered()', lambda actionName=actionName: self.onAddAction(actionName)) self.actionsMenu.addAction(qAction) parametersFormLayout.addWidget(self.actionsMenuButton) # # Actions Area # self.actionsCollapsibleButton = ctk.ctkCollapsibleButton() self.actionsCollapsibleButton.text = "Actions" self.layout.addWidget(self.actionsCollapsibleButton) # Layout within the dummy collapsible button self.actionsFormLayout = qt.QFormLayout(self.actionsCollapsibleButton) # # Export Area # self.exportCollapsibleButton = ctk.ctkCollapsibleButton() self.exportCollapsibleButton.text = "Export" self.layout.addWidget(self.exportCollapsibleButton) self.exportCollapsibleButton.enabled = False self.exportFormLayout = qt.QFormLayout(self.exportCollapsibleButton) self.sizeSelector = qt.QComboBox() for size in self.sizes.keys(): self.sizeSelector.addItem(size) self.sizeSelector.currentText = self.defaultSize self.exportFormLayout.addRow("Animation size", self.sizeSelector) self.fileFormatSelector = qt.QComboBox() for format in self.fileFormats.keys(): self.fileFormatSelector.addItem(format) self.fileFormatSelector.currentText = self.defaultFileFormat self.exportFormLayout.addRow("Animation format", self.fileFormatSelector) self.outputFileButton = qt.QPushButton("Select a file...") self.exportFormLayout.addRow("Output file", self.outputFileButton) self.exportButton = qt.QPushButton("Export") self.exportButton.enabled = False self.exportFormLayout.addRow("", self.exportButton) # connections self.animationSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSelect) self.outputFileButton.connect("clicked()", self.selectExportFile) self.exportButton.connect("clicked()", self.onExport) # Add vertical spacer self.layout.addStretch(1)
def create(self): """create the segmentation helper box""" # # Master Frame # self.masterFrame = qt.QFrame(self.parent) self.masterFrame.setLayout(qt.QVBoxLayout()) self.parent.layout().addWidget(self.masterFrame) # # the master volume selector # self.masterSelectorFrame = qt.QFrame(self.parent) self.masterSelectorFrame.objectName = 'MasterVolumeFrame' self.masterSelectorFrame.setLayout(qt.QHBoxLayout()) self.masterFrame.layout().addWidget(self.masterSelectorFrame) self.masterSelectorLabel = qt.QLabel("Master Volume: ", self.masterSelectorFrame) self.masterSelectorLabel.setToolTip( "Select the master volume (background grayscale scalar volume node)" ) self.masterSelectorFrame.layout().addWidget(self.masterSelectorLabel) self.masterSelector = slicer.qMRMLNodeComboBox( self.masterSelectorFrame) self.masterSelector.objectName = 'MasterVolumeNodeSelector' # TODO self.masterSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"] self.masterSelector.selectNodeUponCreation = False self.masterSelector.addEnabled = False self.masterSelector.removeEnabled = False self.masterSelector.noneEnabled = True self.masterSelector.showHidden = False self.masterSelector.showChildNodeTypes = False self.masterSelector.setMRMLScene(slicer.mrmlScene) # TODO: need to add a QLabel # self.masterSelector.SetLabelText( "Master Volume:" ) self.masterSelector.setToolTip( "Pick the master structural volume to define the segmentation. A label volume with the with \"%s\" appended to the name will be created if it doesn't already exist." % self.mergeVolumePostfix) self.masterSelectorFrame.layout().addWidget(self.masterSelector) # # merge label name and set button # self.mergeSelectorFrame = qt.QFrame(self.masterFrame) self.mergeSelectorFrame.objectName = 'MergeVolumeFrame' self.mergeSelectorFrame.setLayout(qt.QHBoxLayout()) self.masterFrame.layout().addWidget(self.mergeSelectorFrame) mergeNameToolTip = "Composite label map containing the merged structures (be aware that merge operations will overwrite any edits applied to this volume)" self.mergeNameLabel = qt.QLabel("Merge Volume: ", self.mergeSelectorFrame) self.mergeNameLabel.setToolTip(mergeNameToolTip) self.mergeSelectorFrame.layout().addWidget(self.mergeNameLabel) self.mergeSelector = slicer.qMRMLNodeComboBox(self.mergeSelectorFrame) self.mergeSelector.objectName = 'MergeVolumeNodeSelector' self.mergeSelector.setToolTip(mergeNameToolTip) self.mergeSelector.nodeTypes = ["vtkMRMLLabelMapVolumeNode"] self.mergeSelector.addEnabled = False self.mergeSelector.removeEnabled = False self.mergeSelector.noneEnabled = False self.mergeSelector.showHidden = False self.mergeSelector.showChildNodeTypes = False self.mergeSelector.setMRMLScene(slicer.mrmlScene) self.mergeSelectorFrame.layout().addWidget(self.mergeSelector) self.newMergeVolumeAction = qt.QAction("Create new LabelMapVolume", self.mergeSelector) self.newMergeVolumeAction.connect("triggered()", self.newMerge) self.mergeSelector.addMenuAction(self.newMergeVolumeAction) # # Structures Frame # self.structuresFrame = ctk.ctkCollapsibleGroupBox(self.masterFrame) self.structuresFrame.objectName = 'PerStructureVolumesFrame' self.structuresFrame.title = "Per-Structure Volumes" self.structuresFrame.collapsed = True self.structuresFrame.setLayout(qt.QVBoxLayout()) self.masterFrame.layout().addWidget(self.structuresFrame) self.structureListWidget = LabelStructureListWidget() self.structureListWidget.mergeVolumePostfix = self.mergeVolumePostfix self.structuresFrame.layout().addWidget(self.structureListWidget) # # signals, slots, and observers # # signals/slots on qt widgets are automatically when # this class destructs, but observers of the scene must be explicitly # removed in the destuctor # node selected self.masterSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSelect) self.mergeSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onMergeSelect) # so buttons will initially be disabled self.master = None self.structureListWidget.updateStructures()
def setup(self): """ Called when the user opens the module the first time and the widget is initialized. """ ScriptedLoadableModuleWidget.setup(self) # Load widget from .ui file (created by Qt Designer). # Additional widgets can be instantiated manually and added to self.layout. uiWidget = slicer.util.loadUI(self.resourcePath('UI/LeadOR.ui')) self.layout.addWidget(uiWidget) self.ui = slicer.util.childWidgetVariables(uiWidget) if hasattr(slicer, 'vtkMRMLFiberBundleNode') and hasattr( slicer.vtkMRMLFiberBundleNode, 'GetExtractFromROI'): self.ui.stimulationCollapsibleButton.enabled = True else: self.ui.stimulationCollapsibleButton.enabled = False self.ui.stimulationCollapsibleButton.collapsed = True self.ui.stimulationCollapsibleButton.setToolTip( 'Updated SlicerDMRI Extension needed for stimulation module') # AO Channels actions to ToolButton stimulationActionGroup = qt.QActionGroup(self.layout) for child in self.ui.microElectrodeLayoutFrame.children(): if isinstance(child, qt.QToolButton): # channel AOChannelsAction = qt.QAction('AO Channels', self.layout) AOChannelsAction.setEnabled(False) AOChannelsAction.setMenu(qt.QMenu(child)) child.addAction(AOChannelsAction) # stim stimulationAction = qt.QAction('Stim Source', self.layout) stimulationAction.setCheckable(True) stimulationAction.setEnabled(True) stimulationAction.toggled.connect( self.updateStimulationTransform) stimulationActionGroup.addAction(stimulationAction) child.addAction(stimulationAction) # Set scene in MRML widgets. Make sure that in Qt designer the top-level qMRMLWidget's # "mrmlSceneChanged(vtkMRMLScene*)" signal in is connected to each MRML widget's. # "setMRMLScene(vtkMRMLScene*)" slot. uiWidget.setMRMLScene(slicer.mrmlScene) # Create logic class. Logic implements all computations that should be possible to run # in batch mode, without a graphical user interface. self.logic = LeadORLogic() # Connections # These connections ensure that we update parameter node when scene is closed self.addObserver(slicer.mrmlScene, slicer.mrmlScene.StartCloseEvent, self.onSceneStartClose) self.addObserver(slicer.mrmlScene, slicer.mrmlScene.EndCloseEvent, self.onSceneEndClose) # These connections ensure that whenever user changes some settings on the GUI, that is saved in the MRML scene # (in the selected parameter node). self.ui.distanceToTargetComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", self.updateParameterNodeFromGUI) self.ui.trajectoryTransformComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", self.updateParameterNodeFromGUI) self.ui.trajectoryTransformComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", self.guessSideFromTransform) # transforms hierarchy self.ui.distanceToTargetComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", self.setTransformsHierarchy) self.ui.trajectoryTransformComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", self.setTransformsHierarchy) # reset ME when distance to target node change self.ui.distanceToTargetComboBox.currentNodeChanged.connect( lambda b, enabledList=[0] * 9: self.setMELayout(enabledList)) # distance to target slider self.ui.distanceToTargetComboBox.connect( "currentNodeChanged(vtkMRMLNode*)", lambda node: self.ui. distanceToTargetSlider.setMRMLTransformNode(node)) self.ui.distanceToTargetSlider.connect( "valueChanged(double)", lambda value: self.ui. distanceToTargetSlider.applyTransformation(value)) # micro electrode layouts self.ui.MECenterLayoutPushButton.clicked.connect( lambda b, enabledList=[0, 0, 0, 0, 1, 0, 0, 0, 0 ]: self.setMELayout(enabledList)) self.ui.MEPlusLayoutPushButton.clicked.connect( lambda b, enabledList=[0, 1, 0, 1, 1, 1, 0, 1, 0 ]: self.setMELayout(enabledList)) self.ui.MEXLayoutPushButton.clicked.connect( lambda b, enabledList=[1, 0, 1, 0, 1, 0, 1, 0, 1 ]: self.setMELayout(enabledList)) # add connection for each micro electro toggle button for child in self.ui.microElectrodeLayoutFrame.children(): if isinstance(child, qt.QToolButton): child.toggled.connect( lambda b, N=int(child.objectName.split('_')[-1] ): self.microElectrodeLayoutToggle(b, N)) # ME visibility self.ui.MEModelVisCheckBox.toggled.connect( lambda b: self.logic.setMEVisibility('microElectrodeModel', b)) self.ui.MELineVisCheckBox.toggled.connect( lambda b: self.logic.setMEVisibility('trajectoryLine', b)) self.ui.METipVisCheckBox.toggled.connect( lambda b: self.logic.setMEVisibility('tipFiducial', b)) self.ui.METraceVisCheckBox.toggled.connect( lambda b: self.logic.setMEVisibility('traceModel', b)) self.ui.MEClustersCheckBox.toggled.connect( lambda b: self.logic.setMEVisibility('clusterFiducials', b)) # Stimulation self.ui.stimulationActiveCheckBox.connect('toggled(bool)', self.onStimulationActivate) self.ui.stimulationAmplitudeSpinBox.valueChanged.connect( self.updateStimulationRadius) # Make sure parameter node is initialized (needed for module reload) self.initializeParameterNode() # AlphaOmega parameter node (Singleton) try: AOParameterNode = slicer.modules.alphaomega.logic( ).getParameterNode() self.addObserver(AOParameterNode, vtk.vtkCommand.ModifiedEvent, self.updateParameterNodeFromAO) self.updateParameterNodeFromAO(AOParameterNode, None) except: pass
def _setupActions(self): """ creates some actions needed on some menues and toolbars Actions are later added to different toolbars, for example in method _setupMainToolbar """ a = self._actions["new_shell"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "newshell.png"))), "&New Shell", qt.Qt.CTRL + qt.Qt.SHIFT + qt.Qt.Key_T, self, "New Shell") self.connect(a, qt.SIGNAL('activated()'), self.createShellTab) a = self._actions["close_shell"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "exit.png"))), "&Close Shell", qt.Qt.CTRL + qt.Qt.SHIFT + qt.Qt.Key_W, self, "New Shell") self.connect(a, qt.SIGNAL('activated()'), self.destroyShellTab) a = self._actions["toggle-hosttree"] = qt.QAction( qt.QIconSet( qt.QPixmap( os.path.join(CONF.getIconsPath(), "HostTreeView.png"))), "Toggle Host Tree", 0, self, "Toggle Log Console") a.setToggleAction(True) a.toggle() self.connect(a, qt.SIGNAL('activated()'), self.togglePerspectives) a = self._actions["toggle-logconsole"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "LogConsole.png"))), "Toggle Log Console", 0, self, "Toggle Log Console") a.setToggleAction(True) a.toggle() self.connect(a, qt.SIGNAL('activated()'), self.toggleLogConsole) a = self._actions["maximize-shell"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "maximize.png"))), "Maximize Shell", 0, self, "Maximize Shell") a.setToggleAction(True) self.connect(a, qt.SIGNAL('activated()'), self.maximizeShell) self._tab_manager.tabBar().addAction("maximize", self.maximizeShell) #a = self._actions["test"] = qt.QAction( qt.QIconSet(qt.QPixmap(os.path.join(CONF.getIconsPath(),"donotpresstheredbutton.png"))), "Test", qt.Qt.CTRL + qt.Qt.Key_H, self, "Test" ) #self.connect(a, qt.SIGNAL('activated()'), self.test) a = self._actions["screenshot"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "Screenshot.png"))), "Take Screenshot", 0, self, "Take Screenshot") self.connect(a, qt.SIGNAL('activated()'), self.takeScreenshot) a = self._actions["clear-hosttree"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "clear.png"))), "Clear Host Tree", qt.Qt.CTRL + qt.Qt.Key_R, self, "Clear Host Tree") self.connect(a, qt.SIGNAL('activated()'), self._hosts_treeview.clearTree) a = self._actions["repo-config"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "connect.png"))), "Server Connection", 0, self, "Server Connection") self.connect(a, qt.SIGNAL('activated()'), self._showRepositoryConfigDialog) a = self._actions["visualization"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "visualize.png"))), "Visualize", 0, self, "Visualize") self.connect(a, qt.SIGNAL('activated()'), self.runVisualization) a = self._actions["plugin"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "config.png"))), "Plugin", 0, self, "Plugin") self.connect(a, qt.SIGNAL('activated()'), self.showPluginSettingsDialog) a = self._actions["documentation"] = qt.QAction( qt.QIconSet( qt.QPixmap( os.path.join(CONF.getIconsPath(), "Documentation.png"))), "Documentation", 0, self, "Documentation") self.connect(a, qt.SIGNAL('activated()'), self.go2Website) a = self._actions["exit-faraday"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "exit.png"))), "Exit Faraday", 0, self, "Exit Faraday") self.connect(a, qt.SIGNAL('activated()'), self.exitFaraday) a = self._actions["create-workspace"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "sync.png"))), "Create", 0, self, "Create") self.connect(a, qt.SIGNAL('activated()'), self.createWorkspace) # a = self._actions["open-workspace"] = qt.QAction( qt.QIconSet(qt.QPixmap(os.path.join(CONF.getIconsPath(),"sync.png"))), "Open", 0, self, "Open" ) # self.connect(a, qt.SIGNAL('activated()'), self.openWorkspace) a = self._actions["bfont"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "fontb.png"))), "Big Font", 0, self, "Big Font") self.connect(a, qt.SIGNAL('activated()'), self.setBfont) a = self._actions["sfont"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "fonts.png"))), "Small Font", 0, self, "Small Font") self.connect(a, qt.SIGNAL('activated()'), self.setSfont) if CONF.getDebugStatus(): a = self._actions["debug"] = qt.QAction( qt.QIconSet( qt.QPixmap(os.path.join(CONF.getIconsPath(), "debug.png"))), "Debug", 0, self, "Debug") self.connect(a, qt.SIGNAL('activated()'), self.doDebug)