Ejemplo n.º 1
0
    def create(self):
        # add a search box
        self.searchFrame = qt.QFrame(self.parent)
        self.searchFrame.setLayout(qt.QHBoxLayout())
        self.parent.layout().addWidget(self.searchFrame)
        self.searchLabel = qt.QLabel(self.searchFrame)
        self.searchLabel.setText("Search: ")
        self.searchFrame.layout().addWidget(self.searchLabel)
        self.search = qt.QLineEdit(self.searchFrame)
        self.searchFrame.layout().addWidget(self.search)

        # model and view for color table
        self.view = qt.QTreeView()
        self.parent.layout().addWidget(self.view)
        self.populateColors()
        self.search.connect('textChanged(QString)', self.populateColors)
        self.view.connect('clicked(QModelIndex)', self.selected)
Ejemplo n.º 2
0
    def create(self):
        # add a search box
        self.searchFrame = qt.QFrame(self.parent)
        self.searchFrame.setLayout(qt.QHBoxLayout())
        self.parent.layout().addWidget(self.searchFrame)
        self.searchLabel = qt.QLabel(self.searchFrame)
        self.searchLabel.setText("Search: ")
        self.searchFrame.layout().addWidget(self.searchLabel)
        self.search = qt.QLineEdit(self.searchFrame)
        self.searchFrame.layout().addWidget(self.search)

        # model and view for color table
        self.view = qt.QTreeView()
        self.view.setObjectName('EditColorTreeView')
        self.view.setEditTriggers(qt.QAbstractItemView().NoEditTriggers)
        self.parent.layout().addWidget(self.view)
        self.populateColors()
        self.search.connect('textChanged(QString)', self.populateColors)
        self.view.connect('activated(QModelIndex)', self.selected)
Ejemplo n.º 3
0
    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.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)
        # TODO
        self.masterSelector.nodeTypes = (("vtkMRMLScalarVolumeNode"), "")
        self.masterSelector.addAttribute("vtkMRMLScalarVolumeNode", "LabelMap",
                                         0)
        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 \"-label\" appended to the name will be created if it doesn't already exist."
        )
        self.masterSelectorFrame.layout().addWidget(self.masterSelector)

        #
        # merge label name and set button
        #
        self.mergeFrame = qt.QFrame(self.masterFrame)
        self.mergeFrame.setLayout(qt.QHBoxLayout())
        self.masterFrame.layout().addWidget(self.mergeFrame)

        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.mergeFrame)
        self.mergeNameLabel.setToolTip(mergeNameToolTip)
        self.mergeFrame.layout().addWidget(self.mergeNameLabel)

        self.mergeName = qt.QLabel("", self.mergeFrame)
        self.mergeName.setToolTip(mergeNameToolTip)
        self.mergeFrame.layout().addWidget(self.mergeName)

        self.setMergeButton = qt.QPushButton("Set...", self.mergeFrame)
        self.setMergeButton.setToolTip(
            "Set the merge volume to use with this master.")
        self.mergeFrame.layout().addWidget(self.setMergeButton)

        #
        # Structures Frame
        #

        self.structuresFrame = ctk.ctkCollapsibleGroupBox(self.masterFrame)
        self.structuresFrame.title = "Per-Structure Volumes"
        self.structuresFrame.collapsed = True
        self.structuresFrame.setLayout(qt.QVBoxLayout())
        self.masterFrame.layout().addWidget(self.structuresFrame)

        # buttons frame

        self.structureButtonsFrame = qt.QFrame(self.structuresFrame)
        self.structureButtonsFrame.setLayout(qt.QHBoxLayout())
        self.structuresFrame.layout().addWidget(self.structureButtonsFrame)

        # add button

        self.addStructureButton = qt.QPushButton("Add Structure",
                                                 self.structureButtonsFrame)
        self.addStructureButton.setToolTip(
            "Add a label volume for a structure to edit")
        self.structureButtonsFrame.layout().addWidget(self.addStructureButton)

        # split button

        self.splitButton = qt.QPushButton("Split Merge Volume",
                                          self.structuresFrame)
        self.splitButton.setToolTip(
            "Split distinct labels from merge volume into new volumes")
        self.structureButtonsFrame.layout().addWidget(self.splitButton)

        # structures view

        self.structuresView = qt.QTreeView()
        self.structuresView.sortingEnabled = True
        self.structuresFrame.layout().addWidget(self.structuresView)

        # all buttons frame

        self.allButtonsFrame = qt.QFrame(self.structuresFrame)
        self.allButtonsFrame.setLayout(qt.QHBoxLayout())
        self.structuresFrame.layout().addWidget(self.allButtonsFrame)

        # delete structures button

        self.deleteStructuresButton = qt.QPushButton("Delete Structures",
                                                     self.allButtonsFrame)
        self.deleteStructuresButton.setToolTip(
            "Delete all the structure volumes from the scene.\n\nNote: to delete individual structure volumes, use the Data Module."
        )
        self.allButtonsFrame.layout().addWidget(self.deleteStructuresButton)

        # merge button

        self.mergeButton = qt.QPushButton("Merge All", self.allButtonsFrame)
        self.mergeButton.setToolTip("Merge all structures into Merge Volume")
        self.allButtonsFrame.layout().addWidget(self.mergeButton)

        # merge and build button

        self.mergeAndBuildButton = qt.QPushButton("Merge And Build",
                                                  self.allButtonsFrame)
        self.mergeAndBuildButton.setToolTip(
            "Merge all structures into Merge Volume and build models from all structures"
        )
        self.allButtonsFrame.layout().addWidget(self.mergeAndBuildButton)
        # options frame

        self.optionsFrame = qt.QFrame(self.structuresFrame)
        self.optionsFrame.setLayout(qt.QHBoxLayout())
        self.structuresFrame.layout().addWidget(self.optionsFrame)

        # replace models button

        self.replaceModels = qt.QCheckBox("Replace Models", self.optionsFrame)
        self.replaceModels.setToolTip(
            "Replace any existing models when building")
        self.replaceModels.setChecked(1)
        self.optionsFrame.layout().addWidget(self.replaceModels)

        #
        # 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)
        # buttons pressed
        self.addStructureButton.connect("clicked()", self.addStructure)
        self.deleteStructuresButton.connect("clicked()", self.deleteStructures)
        # selection changed event
        self.structuresView.connect("clicked(QModelIndex)",
                                    self.onStructuresClicked)
        # invoked event
        self.splitButton.connect("clicked()", self.split)
        self.mergeButton.connect("clicked()", self.mergeStructures)
        self.mergeAndBuildButton.connect("clicked()", self.onMergeAndBuild)
        self.setMergeButton.connect("clicked()", self.labelSelectDialog)

        # new scene, node added or removed events
        # TODO: allow observers on speific events: 66000, 66001, 66002
        tag = slicer.mrmlScene.AddObserver("ModifiedEvent",
                                           self.updateStructures)
        self.observerTags.append((slicer.mrmlScene, tag))

        # so buttons will initially be disabled
        self.master = None
        self.updateStructures()
Ejemplo n.º 4
0
    def setup(self):
        # Instantiate and connect widgets ...

        icon = self.parent.style().standardIcon(qt.QStyle.SP_ArrowForward)
        iconSize = qt.QSize(22, 22)

        def createToolButton(text):
            tb = qt.QToolButton()

            tb.text = text
            tb.icon = icon

            font = tb.font
            font.setBold(True)
            font.setPixelSize(14)
            tb.font = font

            tb.iconSize = iconSize
            tb.toolButtonStyle = qt.Qt.ToolButtonTextBesideIcon
            tb.autoRaise = True

            return tb

        def createReadOnlyLineEdit():
            le = qt.QLineEdit()
            le.readOnly = True
            le.frame = False
            le.styleSheet = "QLineEdit { background:transparent; }"
            le.cursor = qt.QCursor(qt.Qt.IBeamCursor)
            return le

        #
        # Tools Area
        #
        self.toolsCollapsibleButton = ctk.ctkCollapsibleButton()
        self.toolsCollapsibleButton.text = "Extension Tools"
        self.layout.addWidget(self.toolsCollapsibleButton)

        self.createExtensionButton = createToolButton("Create Extension")
        self.createExtensionButton.connect('clicked(bool)',
                                           self.createExtension)

        self.selectExtensionButton = createToolButton("Select Extension")
        self.selectExtensionButton.connect('clicked(bool)',
                                           self.selectExtension)

        toolsLayout = qt.QVBoxLayout(self.toolsCollapsibleButton)
        toolsLayout.addWidget(self.createExtensionButton)
        toolsLayout.addWidget(self.selectExtensionButton)

        #
        # Editor Area
        #
        self.editorCollapsibleButton = ctk.ctkCollapsibleButton()
        self.editorCollapsibleButton.text = "Extension Editor"
        self.editorCollapsibleButton.enabled = False
        self.editorCollapsibleButton.collapsed = True
        self.layout.addWidget(self.editorCollapsibleButton)

        self.extensionNameField = createReadOnlyLineEdit()
        self.extensionLocationField = createReadOnlyLineEdit()
        self.extensionRepositoryField = createReadOnlyLineEdit()

        self.extensionContentsModel = qt.QFileSystemModel()
        self.extensionContentsView = qt.QTreeView()
        self.extensionContentsView.setModel(self.extensionContentsModel)
        self.extensionContentsView.sortingEnabled = True
        self.extensionContentsView.hideColumn(3)

        self.createExtensionModuleButton = createToolButton(
            "Add Module to Extension")
        self.createExtensionModuleButton.connect('clicked(bool)',
                                                 self.createExtensionModule)

        self.editExtensionMetadataButton = createToolButton(
            "Edit Extension Metadata")
        self.editExtensionMetadataButton.connect('clicked(bool)',
                                                 self.editExtensionMetadata)

        editorLayout = qt.QFormLayout(self.editorCollapsibleButton)
        editorLayout.addRow("Name:", self.extensionNameField)
        editorLayout.addRow("Location:", self.extensionLocationField)
        editorLayout.addRow("Repository:", self.extensionRepositoryField)
        editorLayout.addRow("Contents:", self.extensionContentsView)
        editorLayout.addRow(self.createExtensionModuleButton)
        editorLayout.addRow(self.editExtensionMetadataButton)

        # Add vertical spacer
        self.layout.addStretch(1)