Exemple #1
0
 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))
Exemple #2
0
  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 _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)
Exemple #4
0
    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))
Exemple #5
0
    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)
Exemple #6
0
    def __init__(self, parent=None, optionsFrame=None):
        VTKObservationMixin.__init__(self)
        self.effects = []
        self.effectButtons = {}
        self.effectCursors = {}
        self.effectActionGroup = qt.QActionGroup(parent)
        self.effectActionGroup.connect('triggered(QAction*)',
                                       self._onEffectActionTriggered)
        self.effectActionGroup.exclusive = True
        self.currentEffect = None
        self.undoRedo = UndoRedo()
        self.undoRedo.stateChangedCallback = self.updateUndoRedoButtons
        self.toggleShortcut = None

        # check for extensions - if none have been registered, just create the empty dictionary
        try:
            slicer.modules.editorExtensions
        except AttributeError:
            slicer.modules.editorExtensions = {}

        # register the builtin extensions
        self.editorBuiltins = {}
        self.editorBuiltins["PaintEffect"] = EditorLib.PaintEffect
        self.editorBuiltins["DrawEffect"] = EditorLib.DrawEffect
        self.editorBuiltins["ThresholdEffect"] = EditorLib.ThresholdEffect
        self.editorBuiltins["RectangleEffect"] = EditorLib.RectangleEffect
        self.editorBuiltins[
            "LevelTracingEffect"] = EditorLib.LevelTracingEffect
        self.editorBuiltins["MakeModelEffect"] = EditorLib.MakeModelEffect
        self.editorBuiltins["ErodeEffect"] = EditorLib.ErodeEffect
        self.editorBuiltins["DilateEffect"] = EditorLib.DilateEffect
        self.editorBuiltins["ChangeLabelEffect"] = EditorLib.ChangeLabelEffect
        self.editorBuiltins[
            "RemoveIslandsEffect"] = EditorLib.RemoveIslandsEffect
        self.editorBuiltins[
            "IdentifyIslandsEffect"] = EditorLib.IdentifyIslandsEffect
        self.editorBuiltins["SaveIslandEffect"] = EditorLib.SaveIslandEffect
        self.editorBuiltins[
            "ChangeIslandEffect"] = EditorLib.ChangeIslandEffect
        self.editorBuiltins["GrowCutEffect"] = EditorLib.GrowCutEffect
        self.editorBuiltins[
            "WatershedFromMarkerEffect"] = EditorLib.WatershedFromMarkerEffect
        self.editorBuiltins[
            "FastMarchingEffect"] = EditorLib.FastMarchingEffect
        self.editorBuiltins["WandEffect"] = EditorLib.WandEffect

        # frame that holds widgets specific for each effect
        if not optionsFrame:
            self.optionsFrame = qt.QFrame(self.parent)
            self.optionsFrame.objectName = 'OptionsFrame'
        else:
            self.optionsFrame = optionsFrame

        # state variables for selected effect in the box
        # - currentOption is an instance of an option GUI
        # - currentTools is a list of EffectTool instances
        self.currentOption = None
        self.currentTools = []

        # listen for changes in the Interaction Mode
        interactionNode = slicer.app.applicationLogic().GetInteractionNode()
        self.addObserver(interactionNode,
                         interactionNode.InteractionModeChangedEvent,
                         self.onInteractionModeChanged)

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

        if not parent:
            self.parent = qt.QFrame()
            self.parent.setLayout(qt.QVBoxLayout())
            self.create()
            self.parent.show()
        else:
            self.parent = parent
            self.create()
Exemple #7
0
    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
Exemple #8
0
    def __init__(self, ctrl, argv=None):
        QtInterface.__init__(self, ctrl, argv)

        self._changeset = None

        self._window = qt.QMainWindow()
        self._window.setCaption("Smart Package Manager %s" % VERSION)
        centerWindow(self._window)
        self._window.setMinimumSize(640, 480)
        app.connect(app, qt.SIGNAL('lastWindowClosed()'), app, qt.SLOT('quit()'))

        self._undo = []
        self._redo = []

        globals = {"self": self, "qt": qt}
        group = qt.QActionGroup(self._window, "Actions")
        self._actions = compileActions(group, ACTIONS, globals)

        class ToggleAction(qt.QAction):
        
            def __init__(self, group, name, label):
                qt.QAction.__init__(self, group, name)
                self.setToggleAction(True)
                self.setMenuText(label.replace("&","&&"))
                self._name = name
            
            def connect(self, signal, callback, userdata):
                self._callback = callback
                self._userdata = userdata
                qt.QObject.connect(self, qt.SIGNAL(signal), self.slot)
            
            def slot(self):
                self._callback(self._userdata)
         
        self._filters = {}
        for name, label in [("hide-non-upgrades", _("Hide Non-upgrades")),
                            ("hide-installed", _("Hide Installed")),
                            ("hide-uninstalled", _("Hide Uninstalled")),
                            ("hide-unmarked", _("Hide Unmarked")),
                            ("hide-unlocked", _("Hide Unlocked")),
                            ("hide-requested", _("Hide Requested")),
                            ("hide-old", _("Hide Old"))]:
            act = ToggleAction(None, name, label)
            act.connect("activated()", self.toggleFilter, name)
            self._actions[name] = act

        treestyle = sysconf.get("package-tree")
        for name, label in [("groups", _("Groups")),
                            ("channels", _("Channels")),
                            ("channels-groups", _("Channels & Groups")),
                            ("none", _("None"))]:
            act = ToggleAction(group, "tree-style-"+name, label)
            if name == treestyle:
                act.setOn(True)
            act.connect("activated()", self.setTreeStyle, name)
            self._actions["tree-style-"+name] = act

        self._menubar = self._window.menuBar()
        for MENU in MENUBAR:
             def insertmenu(menubar, menu):
                item = menu[0]
                action = self._actions[item]
                m = qt.QPopupMenu(menubar)
                text = action.menuText()
                menubar.insertItem(text, m)
                for item in menu[1]:
                    if isinstance(item, tuple):
                        insertmenu(m, item)
                    elif item:
                        action = self._actions[item]
                        #i = qt.QPopupMenu(m)
                        #text = action.menuText()
                        #m.insertItem(text, i)
                        action.addTo(m)
                    else:
                        m.insertSeparator()
             insertmenu(self._menubar, MENU)

        self._toolbar = qt.QToolBar(self._window)
        for TOOL in TOOLBAR:
            def inserttool(toolbar, tool):
                if tool:
                    action = self._actions[tool]
                    #b = qt.QToolButton(toolbar, TOOL)
                    #b.setTextLabel(action.toolTip())
                    pixmap = getPixmap(TOOLBARICONS[tool])
                    #b.setIconSet(qt.QIconSet(pixmap))
                    action.setIconSet(qt.QIconSet(pixmap))
                    action.addTo(toolbar)
                else:
                    toolbar.addSeparator()
            inserttool(self._toolbar, TOOL)

        #self._window.add_accel_group(self._ui.get_accel_group())

        self._actions["exec-changes"].setAccel(qt.QKeySequence("Ctrl+C"))
        self._actions["find"].setAccel(qt.QKeySequence("Ctrl+F"))
        self._actions["expand-all"].setAccel(qt.QKeySequence("Ctrl+O"))
        self._actions["collapse-all"].setAccel(qt.QKeySequence("Ctrl+W"))
        self._actions["summary-window"].setAccel(qt.QKeySequence("Ctrl+S"))

        self._actions["exec-changes"].setEnabled(False)
        self._actions["clear-changes"].setEnabled(False)
        self._actions["undo"].setEnabled(False)
        self._actions["redo"].setEnabled(False)

        # Search bar

        self._searchbar = qt.QToolBar(self._window)
        self._searchbar.hide()
       
        label = qt.QLabel(_("Search:"), self._searchbar)
        label.show()

        self._searchentry = qt.QLineEdit(self._searchbar)
        qt.QObject.connect(self._searchentry, qt.SIGNAL("returnPressed()"), self.refreshPackages)
        self._searchentry.show()

        button = qt.QPushButton(self._searchbar)
        qt.QObject.connect(button, qt.SIGNAL("clicked()"), self.refreshPackages)
        pixmap = getPixmap("crystal-search")
        button.setIconSet(qt.QIconSet(pixmap))
        button.show()

        buttongroup = qt.QButtonGroup(self._searchbar)
        buttongroup.hide()
        
        self._searchname = qt.QRadioButton(_("Automatic"), self._searchbar)
        self._searchname.setChecked(True)
        qt.QObject.connect(self._searchname, qt.SIGNAL("clicked()"), self.refreshPackages)
        buttongroup.insert(self._searchname)
        self._searchname.show()
        self._searchdesc = qt.QRadioButton(_("Description"), self._searchbar)
        self._searchdesc.setChecked(False)
        qt.QObject.connect(self._searchdesc, qt.SIGNAL("clicked()"), self.refreshPackages)
        self._searchdesc.show()
        buttongroup.insert(self._searchdesc)

        # Packages and information

        self._splitter = qt.QSplitter(qt.Qt.Vertical, self._window)
        self._window.setCentralWidget(self._splitter)
        
        self._pv = QtPackageView(self._splitter)
        self._pv.show()

        self._pi = QtPackageInfo(self._splitter)
        self._pi.show()
        qt.QObject.connect(self._pv, qt.PYSIGNAL("packageSelected"), self._pi.setPackage)
        qt.QObject.connect(self._pv, qt.PYSIGNAL("packageActivated"), self.actOnPackages)
        qt.QObject.connect(self._pv, qt.PYSIGNAL("packagePopup"), self.packagePopup)

        self._status = self._window.statusBar()
        self._status.show()
        
        self._legend = QtLegend(self._window)