def __init__(self, parent): layout = qt.QGridLayout(parent) self.pathList = slicer.qSlicerDirectoryListView() layout.addWidget(self.pathList, 0, 0, 3, 1) self.addPathButton = qt.QToolButton() self.addPathButton.icon = qt.QIcon.fromTheme("list-add") self.addPathButton.text = "Add" layout.addWidget(self.addPathButton, 0, 1) self.removePathButton = qt.QToolButton() self.removePathButton.icon = qt.QIcon.fromTheme("list-remove") self.removePathButton.text = "Remove" layout.addWidget(self.removePathButton, 1, 1)
def setup(self): ScriptedLoadableModuleWidget.setup(self) # Load UI file moduleName = 'Home' scriptedModulesPath = os.path.dirname( slicer.util.modulePath(moduleName)) path = os.path.join(scriptedModulesPath, 'Resources', 'UI', moduleName + '.ui') self.Widget = slicer.util.loadUI(path) self.layout.addWidget(self.Widget) # Setup data buttons numberOfColumns = 2 iconPath = os.path.join( os.path.dirname(__file__).replace('\\', '/'), 'Resources', 'Icons') desktop = qt.QDesktopWidget() mainScreenSize = desktop.availableGeometry(desktop.primaryScreen) iconSize = qt.QSize(mainScreenSize.width() / 15, mainScreenSize.height() / 10) buttonsLayout = self.get('DataCollapsibleGroupBox').layout() columnIndex = 0 rowIndex = 0 files = { 'annotation_25': os.path.join(scriptedModulesPath, 'CellLocatorData', 'annotation_25.nrrd'), 'annotation_50': os.path.join(scriptedModulesPath, 'CellLocatorData', 'annotation_50.nrrd') } for (file, filepath) in files.iteritems(): button = qt.QToolButton() button.setText(file) # Set thumbnail thumbnailFileName = os.path.join(scriptedModulesPath, 'Resources', 'Icons', file + '.png') button.setIcon(qt.QIcon(thumbnailFileName)) button.setIconSize(iconSize) button.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) qSize = qt.QSizePolicy() qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding) button.setSizePolicy(qSize) button.name = '%sPushButton' % file buttonsLayout.addWidget(button, rowIndex, columnIndex) columnIndex += 1 if columnIndex == numberOfColumns: rowIndex += 1 columnIndex = 0 button.connect('clicked()', lambda p=filepath: slicer.util.loadVolume(p))
def __init__(self): super().__init__() effectPixmap = qt.QPixmap( os.path.join( os.path.split(WarpDrive.__file__)[0], 'Resources', 'Icons', 'Add.png')) effectIcon = qt.QIcon(effectPixmap) self.addButton = qt.QToolButton() self.addButton.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) self.addButton.setIcon(effectIcon) self.addButton.setIconSize(effectPixmap.rect().size()) self.addButton.setEnabled(True) self.addButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.addButton.clicked.connect(self.onAddButton) effectPixmap = qt.QPixmap( os.path.join( os.path.split(WarpDrive.__file__)[0], 'Resources', 'Icons', 'Delete.png')) effectIcon = qt.QIcon(effectPixmap) self.removeButton = qt.QToolButton() self.removeButton.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) self.removeButton.setIcon(effectIcon) self.removeButton.setText('Delete') self.removeButton.setIconSize(effectPixmap.rect().size()) self.removeButton.setEnabled(True) self.removeButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.removeButton.clicked.connect(self.onRemoveButton) self.buttonsFrame = qt.QFrame() self.buttonsFrame.setSizePolicy(qt.QSizePolicy.Preferred, qt.QSizePolicy.Minimum) self.buttonsFrame.setLayout(qt.QHBoxLayout()) self.buttonsFrame.layout().addWidget(self.addButton, 1) self.buttonsFrame.layout().addWidget(self.removeButton, 1) layout = qt.QVBoxLayout(self) layout.addWidget(self.buttonsFrame) layout.addWidget(self.view)
def build_icon_button(icon_path, on_click, width=50, tooltip=None): path = slicer.os.path.dirname( slicer.os.path.abspath(inspect.getfile( inspect.currentframe()))) + icon_path icon = qt.QPixmap(path).scaled(qt.QSize(16, 16), qt.Qt.KeepAspectRatio, qt.Qt.SmoothTransformation) b = qt.QToolButton() b.setIcon(qt.QIcon(icon)) b.setFixedSize(width, 24) if tooltip is not None: b.setToolTip(tooltip) b.connect('clicked(bool)', on_click) return b
def __init__(self, *args, **kwargs): qt.QWidget.__init__(self, *args) self.setCaption("Hardware Repository browser") tb = qt.QHBox(self) self.cmdRefresh = qt.QToolButton(tb) self.cmdRefresh.setIconSet(qt.QIconSet(Icons.load("reload"))) qt.QToolTip.add(self.cmdRefresh, "refresh HWR objects tree") self.cmdClose = qt.QToolButton(tb) self.cmdClose.setIconSet(qt.QIconSet(Icons.load("button_cancel"))) qt.QToolTip.add(self.cmdClose, "close HWR browser") HorizontalSpacer(tb) tb.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) qt.QObject.connect(self.cmdRefresh, qt.SIGNAL("clicked()"), self.refresh) qt.QObject.connect(self.cmdClose, qt.SIGNAL("clicked()"), self.close) qt.QVBoxLayout(self) self.layout().addWidget(tb) self.add_hwr_browser()
def __init__(self, parent=None, name="CTB"): """ """ qt.QToolButton.__init__(self, parent, name) self.setAutoRaise(True) self.simpleColor = [qt.Qt.black, qt.Qt.white, qt.Qt.red, qt.Qt.green, qt.Qt.blue, qt.Qt.yellow] self.selectedColor = qt.QColor(qt.Qt.black) self.setIconColor(self.selectedColor) self.popupMenu = qt.QPopupMenu(self) self.setPopup(self.popupMenu) self.setPopupDelay(0) colorBar = qt.QHButtonGroup(self.popupMenu) colorBar.setFlat(True) colorBar.setInsideMargin(5) colorButton = [] for color in self.simpleColor: w = qt.QPushButton(colorBar) w.setPaletteBackgroundColor(color) w.setFixedSize(15, 15) colorBar.insert(w) colorButton.append(w) self.connect(colorBar, qt.SIGNAL("clicked(int )"), self.selectSimpleColor) otherBar = qt.QHButtonGroup(self.popupMenu) otherBar.setFlat(True) otherBar.setInsideMargin(5) moreButton = qt.QToolButton(otherBar) moreButton.setTextLabel("More color ...") moreButton.setUsesTextLabel(True) moreButton.setAutoRaise(True) self.connect(moreButton, qt.SIGNAL("clicked()"), self.selectColor) self.popupMenu.insertItem(colorBar) self.popupMenu.insertItem(otherBar)
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 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 __init__(self, name, toolTip): self.name = name # Tool Button effectPixmap = qt.QPixmap(os.path.join(os.path.split(WarpDrive.__file__)[0], 'Resources', 'Icons', self.name + '.png')) effectIcon = qt.QIcon(effectPixmap) self.effectButton = qt.QToolButton() self.effectButton.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) self.effectButton.setIcon(effectIcon) self.effectButton.setText(self.name) self.effectButton.setToolTip(toolTip) self.effectButton.setIconSize(effectPixmap.rect().size()) self.effectButton.setAutoExclusive(True) self.effectButton.setCheckable(True) self.effectButton.setChecked(False) self.effectButton.setEnabled(True) self.effectButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding,qt.QSizePolicy.Maximum) self.effectButton.connect('toggled(bool)', self.onEffectButtonToggle) self.effectButton.connect('clicked(bool)', self.onEffectButtonClicked)
def __init__(self, *args, **kwargs): qt.QWidget.__init__(self, *args) self.setCaption("Toolbox") self.bricksTab = {} self.bricks = {} topPanel = qt.QFrame(self) self.cmdRefresh = qt.QToolButton(topPanel) self.cmdRefresh.setIconSet(qt.QIconSet(Icons.load("reload"))) qt.QToolTip.add(self.cmdRefresh, "refresh bricks list") qt.QHBoxLayout(topPanel) topPanel.layout().addWidget(qt.QLabel("Available bricks", topPanel), 0, qt.Qt.AlignLeft) topPanel.layout().addWidget(self.cmdRefresh, 0, qt.Qt.AlignRight) qt.QObject.connect(self.cmdRefresh, qt.SIGNAL("clicked()"), self.refresh) self.bricksToolbox = qt.QToolBox(self) qt.QVBoxLayout(self, 5, 5) self.layout().addWidget(topPanel) self.layout().addWidget(self.bricksToolbox)
def __init__(self, name, toolTip): VTKObservationMixin.__init__(self) self.parameterNode = SmudgeModule.SmudgeModuleLogic().getParameterNode( ) self.addObserver(self.parameterNode, vtk.vtkCommand.ModifiedEvent, self.updateGuiFromMRML) self.addObserver(self.parameterNode, vtk.vtkCommand.ModifiedEvent, self.resetEffect) self.name = name # Tool Button effectPixmap = qt.QPixmap( os.path.join( os.path.split(__file__)[0], 'Icons', self.name + '.png')) effectIcon = qt.QIcon(effectPixmap) self.effectButton = qt.QToolButton() self.effectButton.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) self.effectButton.setIcon(effectIcon) self.effectButton.setText(self.name) self.effectButton.setToolTip(toolTip) self.effectButton.setIconSize(effectPixmap.rect().size()) self.effectButton.setAutoExclusive(True) self.effectButton.setCheckable(True) self.effectButton.setChecked(False) self.effectButton.setEnabled(False) self.effectButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.effectButton.connect('toggled(bool)', self.onEffectButtonToggle) self.effectButton.connect('clicked(bool)', self.onEffectButtonClicked) # Parameters Frame self.parametersFrame = qt.QFrame() self.parametersFrame.setLayout(qt.QFormLayout()) self.parametersFrame.setVisible(False) # aux prev warp id self.prevWarpID = ""
def setup(self): ScriptedLoadableModuleWidget.setup(self) # This module is often used in developer mode, therefore # collapse reload & test section by default. if hasattr(self, "reloadCollapsibleButton"): self.reloadCollapsibleButton.collapsed = True self.observerTags = [] self.logic = SampleDataLogic(self.logMessage) numberOfColumns = 3 iconPath = os.path.join( os.path.dirname(__file__).replace('\\', '/'), 'Resources', 'Icons') desktop = qt.QDesktopWidget() mainScreenSize = desktop.availableGeometry(desktop.primaryScreen) iconSize = qt.QSize(mainScreenSize.width() / 15, mainScreenSize.height() / 10) categories = slicer.modules.sampleDataSources.keys() categories.sort() if 'BuiltIn' in categories: categories.remove('BuiltIn') categories.insert(0, 'BuiltIn') for category in categories: frame = ctk.ctkCollapsibleGroupBox(self.parent) self.layout.addWidget(frame) frame.title = category frame.name = '%sCollapsibleGroupBox' % category layout = qt.QGridLayout(frame) columnIndex = 0 rowIndex = 0 for source in slicer.modules.sampleDataSources[category]: name = source.sampleName if not name: name = source.nodeNames[0] b = qt.QToolButton() b.setText(name) # Set thumbnail if source.thumbnailFileName: # Thumbnail provided thumbnailImage = source.thumbnailFileName else: # Look for thumbnail image with the name of any node name with .png extension thumbnailImage = None for nodeName in source.nodeNames: if not nodeName: continue thumbnailImageAttempt = os.path.join( iconPath, nodeName + '.png') if os.path.exists(thumbnailImageAttempt): thumbnailImage = thumbnailImageAttempt break if thumbnailImage and os.path.exists(thumbnailImage): b.setIcon(qt.QIcon(thumbnailImage)) b.setIconSize(iconSize) b.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon) qSize = qt.QSizePolicy() qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding) b.setSizePolicy(qSize) b.name = '%sPushButton' % name layout.addWidget(b, rowIndex, columnIndex) columnIndex += 1 if columnIndex == numberOfColumns: rowIndex += 1 columnIndex = 0 if source.customDownloader: b.connect('clicked()', source.customDownloader) else: b.connect( 'clicked()', lambda s=source: self.logic.downloadFromSource(s)) self.log = qt.QTextEdit() self.log.readOnly = True self.layout.addWidget(self.log) self.logMessage('<p>Status: <i>Idle</i>\n') # Add spacer to layout self.layout.addStretch(1)
def setupOptionsFrame(self): self.operationRadioButtons = [] # Fill operation buttons self.fillInsideButton = qt.QRadioButton("Fill inside") self.operationRadioButtons.append(self.fillInsideButton) self.buttonToOperationNameMap[self.fillInsideButton] = 'FILL_INSIDE' self.fillOutsideButton = qt.QRadioButton("Fill outside") self.operationRadioButtons.append(self.fillOutsideButton) self.buttonToOperationNameMap[self.fillOutsideButton] = 'FILL_OUTSIDE' self.binaryMaskFillButton = qt.QRadioButton("Fill inside and outside") self.binaryMaskFillButton.setToolTip("Create a labelmap volume with specified inside and outside fill values.") self.operationRadioButtons.append(self.binaryMaskFillButton) self.buttonToOperationNameMap[self.binaryMaskFillButton] = 'FILL_INSIDE_AND_OUTSIDE' # Operation buttons layout operationLayout = qt.QGridLayout() operationLayout.addWidget(self.fillInsideButton, 0, 0) operationLayout.addWidget(self.fillOutsideButton, 1, 0) operationLayout.addWidget(self.binaryMaskFillButton, 0, 1) self.scriptedEffect.addLabeledOptionsWidget("Operation:", operationLayout) # fill value self.fillValueEdit = qt.QSpinBox() self.fillValueEdit.setToolTip("Choose the voxel intensity that will be used to fill the masked region.") self.fillValueEdit.minimum = -32768 self.fillValueEdit.maximum = 65535 self.fillValueEdit.connect("valueChanged(int)", self.fillValueChanged) self.fillValueLabel = qt.QLabel("Fill value: ") # Binary mask fill outside value self.binaryMaskFillOutsideEdit = qt.QSpinBox() self.binaryMaskFillOutsideEdit.setToolTip("Choose the voxel intensity that will be used to fill outside the mask.") self.binaryMaskFillOutsideEdit.minimum = -32768 self.binaryMaskFillOutsideEdit.maximum = 65535 self.binaryMaskFillOutsideEdit.connect("valueChanged(int)", self.fillValueChanged) self.fillOutsideLabel = qt.QLabel("Outside fill value: ") # Binary mask fill outside value self.binaryMaskFillInsideEdit = qt.QSpinBox() self.binaryMaskFillInsideEdit.setToolTip("Choose the voxel intensity that will be used to fill inside the mask.") self.binaryMaskFillInsideEdit.minimum = -32768 self.binaryMaskFillInsideEdit.maximum = 65535 self.binaryMaskFillInsideEdit.connect("valueChanged(int)", self.fillValueChanged) self.fillInsideLabel = qt.QLabel(" Inside fill value: ") # Fill value layouts fillValueLayout = qt.QFormLayout() fillValueLayout.addRow(self.fillValueLabel, self.fillValueEdit) fillOutsideLayout = qt.QFormLayout() fillOutsideLayout.addRow(self.fillOutsideLabel, self.binaryMaskFillOutsideEdit) fillInsideLayout = qt.QFormLayout() fillInsideLayout.addRow(self.fillInsideLabel, self.binaryMaskFillInsideEdit) binaryMaskFillLayout = qt.QHBoxLayout() binaryMaskFillLayout.addLayout(fillOutsideLayout) binaryMaskFillLayout.addLayout(fillInsideLayout) fillValuesSpinBoxLayout = qt.QFormLayout() fillValuesSpinBoxLayout.addRow(binaryMaskFillLayout) fillValuesSpinBoxLayout.addRow(fillValueLayout) self.scriptedEffect.addOptionsWidget(fillValuesSpinBoxLayout) # input volume selector self.inputVolumeSelector = slicer.qMRMLNodeComboBox() self.inputVolumeSelector.nodeTypes = ["vtkMRMLScalarVolumeNode"] self.inputVolumeSelector.selectNodeUponCreation = True self.inputVolumeSelector.addEnabled = True self.inputVolumeSelector.removeEnabled = True self.inputVolumeSelector.noneEnabled = True self.inputVolumeSelector.noneDisplay = "(Master volume)" self.inputVolumeSelector.showHidden = False self.inputVolumeSelector.setMRMLScene(slicer.mrmlScene) self.inputVolumeSelector.setToolTip("Volume to mask. Default is current master volume node.") self.inputVolumeSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onInputVolumeChanged) self.inputVisibilityButton = qt.QToolButton() self.inputVisibilityButton.setIcon(qt.QIcon(":/Icons/Small/SlicerInvisible.png")) self.inputVisibilityButton.setAutoRaise(True) self.inputVisibilityButton.setCheckable(True) self.inputVisibilityButton.connect('clicked()', self.onInputVisibilityButtonClicked) inputLayout = qt.QHBoxLayout() inputLayout.addWidget(self.inputVisibilityButton) inputLayout.addWidget(self.inputVolumeSelector) self.scriptedEffect.addLabeledOptionsWidget("Input Volume: ", inputLayout) # output volume selector self.outputVolumeSelector = slicer.qMRMLNodeComboBox() self.outputVolumeSelector.nodeTypes = ["vtkMRMLScalarVolumeNode", "vtkMRMLLabelMapVolumeNode"] self.outputVolumeSelector.selectNodeUponCreation = True self.outputVolumeSelector.addEnabled = True self.outputVolumeSelector.removeEnabled = True self.outputVolumeSelector.renameEnabled = True self.outputVolumeSelector.noneEnabled = True self.outputVolumeSelector.noneDisplay = "(Create new Volume)" self.outputVolumeSelector.showHidden = False self.outputVolumeSelector.setMRMLScene( slicer.mrmlScene ) self.outputVolumeSelector.setToolTip("Masked output volume. It may be the same as the input volume for cumulative masking.") self.outputVolumeSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onOutputVolumeChanged) self.outputVisibilityButton = qt.QToolButton() self.outputVisibilityButton.setIcon(qt.QIcon(":/Icons/Small/SlicerInvisible.png")) self.outputVisibilityButton.setAutoRaise(True) self.outputVisibilityButton.setCheckable(True) self.outputVisibilityButton.connect('clicked()', self.onOutputVisibilityButtonClicked) outputLayout = qt.QHBoxLayout() outputLayout.addWidget(self.outputVisibilityButton) outputLayout.addWidget(self.outputVolumeSelector) self.scriptedEffect.addLabeledOptionsWidget("Output Volume: ", outputLayout) # Apply button self.applyButton = qt.QPushButton("Apply") self.applyButton.objectName = self.__class__.__name__ + 'Apply' self.applyButton.setToolTip("Apply segment as volume mask. No undo operation available once applied.") self.scriptedEffect.addOptionsWidget(self.applyButton) self.applyButton.connect('clicked()', self.onApply) for button in self.operationRadioButtons: button.connect('toggled(bool)', lambda toggle, widget=self.buttonToOperationNameMap[button]: self.onOperationSelectionChanged(widget, toggle))
def __init__(self, *args): Qt.QMainWindow.__init__(self, *args) self.plot = BodePlot(self) self.plot.setMargin(5) self.zoomers = [] zoomer = Qwt.QwtPlotZoomer( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.zoomers.append(zoomer) zoomer = Qwt.QwtPlotZoomer( Qwt.QwtPlot.xTop, Qwt.QwtPlot.yRight, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) zoomer.setRubberBand(Qwt.QwtPicker.NoRubberBand) self.zoomers.append(zoomer) self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.plot.canvas()) self.picker.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan)) self.setCentralWidget(self.plot) toolBar = Qt.QToolBar(self) btnZoom = Qt.QToolButton(toolBar) btnZoom.setTextLabel("Zoom") btnZoom.setPixmap(Qt.QPixmap(zoom_xpm)) btnZoom.setToggleButton(True) btnZoom.setUsesTextLabel(True) btnPrint = Qt.QToolButton(toolBar) btnPrint.setTextLabel("Print") btnPrint.setPixmap(Qt.QPixmap(print_xpm)) btnPrint.setUsesTextLabel(True) toolBar.addSeparator() dampBox = Qt.QWidget(toolBar) dampLayout = Qt.QHBoxLayout(dampBox) dampLayout.setSpacing(0) dampLayout.addWidget(Qt.QWidget(dampBox), 10) # spacer dampLayout.addWidget(Qt.QLabel("Damping Factor", dampBox), 0) dampLayout.addSpacing(10) self.cntDamp = Qwt.QwtCounter(dampBox) self.cntDamp.setRange(0.01, 5.0, 0.01) self.cntDamp.setValue(0.01) dampLayout.addWidget(self.cntDamp, 10) toolBar.setStretchableWidget(dampBox) self.statusBar() self.zoom(False) self.showInfo() self.connect( self.cntDamp, Qt.SIGNAL('valueChanged(double)'), self.plot.setDamp) self.connect( btnPrint, Qt.SIGNAL('clicked()'), self.print_) self.connect( btnZoom, Qt.SIGNAL('toggled(bool)'), self.zoom) self.connect( self.picker, Qt.SIGNAL('moved(const QPoint &)'), self.moved) self.connect( self.picker, Qt.SIGNAL('selected(const QwtPolygon &)'), self.selected)
def __init__(self): super().__init__() layout = qt.QGridLayout(self) # set up tree view self.treeView = slicer.qMRMLSubjectHierarchyTreeView( slicer.util.mainWindow()) self.treeView.setMRMLScene(slicer.mrmlScene) self.treeView.contextMenuEnabled = False self.treeView.setEditTriggers(0) # disable double click to edit # add addPixmap = qt.QPixmap( os.path.join(os.path.split(__file__)[0], 'Icons', 'Add.png')) addIcon = qt.QIcon(addPixmap) self.addButton = qt.QToolButton() self.addButton.setToolButtonStyle(qt.Qt.ToolButtonTextBesideIcon) self.addButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.addButton.setIcon(addIcon) self.addButton.setIconSize(addPixmap.rect().size()) self.addButton.setToolTip('Add') # delete deletePixmap = qt.QPixmap( os.path.join(os.path.split(__file__)[0], 'Icons', 'Delete.png')) deleteIcon = qt.QIcon(deletePixmap) self.deleteButton = qt.QPushButton() self.deleteButton.setIcon(deleteIcon) self.deleteButton.setIconSize(deletePixmap.rect().size()) self.deleteButton.setToolTip('Delete') # rename renamePixmap = qt.QPixmap( os.path.join(os.path.split(__file__)[0], 'Icons', 'Rename.png')) renameIcon = qt.QIcon(renamePixmap) self.renameButton = qt.QPushButton() self.renameButton.setIcon(renameIcon) self.renameButton.setIconSize(renamePixmap.rect().size()) self.renameButton.setToolTip('Rename') # set up filters filters = [ treeViewSavedWarpFilter(), treeViewAtlasFilter(), treeViewDrawingsFilter(), treeViewSceneFilter() ] self.radioButtons = [] for filt, pos in zip(filters, [[0, 0], [0, 2], [1, 0], [1, 2]]): filterRadioButton = qt.QRadioButton(filt.name) filterRadioButton.setToolTip(filt.toolTip) filterRadioButton.clicked.connect( lambda b, f=filt: self.onFilterRadioButtonClicked(f)) layout.addWidget(filterRadioButton, pos[0], pos[1], 1, 2) self.radioButtons.append(filterRadioButton) layout.addWidget(self.addButton, 0, 4, 1, 2) layout.addWidget(self.deleteButton, 1, 4, 1, 1) layout.addWidget(self.renameButton, 1, 5, 1, 1) layout.addWidget(self.treeView, 2, 0, 1, 6) # when adding fixed points while one of them is selected the new one is not set in the correct parent folder # this is overdoing, but fixes the problem self.treeView.model().rowsAboutToBeInserted.connect( lambda: self.treeView.setCurrentItem(0)) # init self.radioButtons[3].animateClick()
def __init__(self, *args): """Constructor. Usage: plot = Plot(*args) Plot takes any number of optional arguments. The interpretation of each optional argument depend on its data type: (1) Axis -- enables the axis. (2) Curve -- plots a curve. (3) string or QString -- sets the title. (4) tuples of 2 integer -- sets the size. """ qt.QMainWindow.__init__(self) self.__plot = Plot(self, *args) self.setCentralWidget(self.__plot) self.toolBar = qt.QToolBar(self) printButton = qt.QToolButton(self.toolBar) printButton.setTextLabel("Print") printButton.setPixmap(qt.QPixmap(print_xpm)) self.toolBar.addSeparator() graceButton = qt.QToolButton(self.toolBar) graceButton.setTextLabel("Grace") graceButton.setPixmap(qt.QPixmap(grace_xpm)) self.toolBar.addSeparator() mouseComboBox = qt.QComboBox(self.toolBar) for name in ('3 buttons (PyQwt)', '1 button', '2 buttons', '3 buttons (Qwt)'): mouseComboBox.insertItem(name) mouseComboBox.setCurrentItem(self.getZoomerMouseEventSet()) self.toolBar.addSeparator() qt.QWhatsThis.whatsThisButton(self.toolBar) self.connect(printButton, qt.SIGNAL('clicked()'), self.print_) self.connect(graceButton, qt.SIGNAL('clicked()'), self.gracePlot) self.connect(mouseComboBox, qt.SIGNAL('activated(int)'), self.setZoomerMouseEventSet) self.statusBar().message("Move the mouse within the plot canvas" " to show the cursor position.") self.__plot.canvas().setMouseTracking(1) self.connect(self.__plot, qt.SIGNAL('plotMouseMoved(const QMouseEvent&)'), self.onMouseMoved) qt.QWhatsThis.add(printButton, 'Print to a printer or an (E)PS file.') qt.QWhatsThis.add( graceButton, 'Clone the plot into Grace.\n\n' 'The hardcopy output of Grace is better for\n' 'scientific journals and LaTeX documents.') qt.QWhatsThis.add( mouseComboBox, 'Configure the mouse events for the QwtPlotZoomer.\n\n' '3 buttons (PyQwt style):\n' '- left-click & drag to zoom\n' '- middle-click to unzoom all\n' '- right-click to walk down the stack\n' '- shift-right-click to walk up the stack.\n' '1 button:\n' '- click & drag to zoom\n' '- control-click to unzoom all\n' '- alt-click to walk down the stack\n' '- shift-alt-click to walk up the stack.\n' '2 buttons:\n' '- left-click & drag to zoom\n' '- right-click to unzoom all\n' '- alt-left-click to walk down the stack\n' '- alt-shift-left-click to walk up the stack.\n' '3 buttons (Qwt style):\n' '- left-click & drag to zoom\n' '- right-click to unzoom all\n' '- middle-click to walk down the stack\n' '- shift-middle-click to walk up the stack.\n\n' 'If some of those key combinations interfere with\n' 'your Window manager, press the:\n' '- escape-key to unzoom all\n' '- minus-key to walk down the stack\n' '- plus-key to walk up the stack.') qt.QWhatsThis.add( self.__plot.legend(), 'Clicking on a legend button toggles\n' 'a curve between hidden and shown.') qt.QWhatsThis.add( self.__plot.canvas(), 'Clicking on a legend button toggles a curve\n' 'between hidden and shown.\n\n' 'A QwtPlotZoomer lets you zoom infinitely deep\n' 'by saving the zoom states on a stack. You can:\n' '- select a zoom region\n' '- unzoom all\n' '- walk down the stack\n' '- walk up the stack.\n\n' 'The combo box in the toolbar lets you attach\n' 'different sets of mouse events to those actions.') self.resize(700, 500) self.show()
def setup(self): #->> TODO could also specify with Qt Designer instead in future (QtUiTools) # IO COLLAPSIBLE BUTTON ioCollapsibleButton = ctk.ctkCollapsibleButton() ioCollapsibleButton.text = "IO" self.layout.addWidget(ioCollapsibleButton) # Layout within the io collapsible button ioFormLayout = qt.QFormLayout(ioCollapsibleButton) # inputVolume node selector 1 inputNodeSelector1 = slicer.qMRMLNodeComboBox() inputNodeSelector1.objectName = 'inputNodeSelector1' inputNodeSelector1.toolTip = "Select the 1st input volume to be segmented." inputNodeSelector1.nodeTypes = ['vtkMRMLScalarVolumeNode'] inputNodeSelector1.noneEnabled = False inputNodeSelector1.addEnabled = False inputNodeSelector1.removeEnabled = False inputNodeSelector1.editEnabled = True inputNodeSelector1.connect('currentNodeChanged(vtkMRMLNode*)', self.setInputNode1) ioFormLayout.addRow("Input Volume 1:", inputNodeSelector1) self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', inputNodeSelector1, 'setMRMLScene(vtkMRMLScene*)') self.inputNodeSelector1 = inputNodeSelector1 #->> TODO for all parameters, provide slots to set them, and use internal values to eventually pass them into the PDF segmenter - for using the interactive PDF segmenter somewhere else, ex in editor module # inputVolume node selector 2 inputNodeSelector2 = slicer.qMRMLNodeComboBox() inputNodeSelector2.objectName = 'inputNodeSelector2' inputNodeSelector2.toolTip = "Select the 2nd input volume to be segmented." inputNodeSelector2.nodeTypes = ['vtkMRMLScalarVolumeNode'] inputNodeSelector2.noneEnabled = True inputNodeSelector2.addEnabled = False inputNodeSelector2.removeEnabled = False inputNodeSelector2.editEnabled = True inputNodeSelector2.connect('currentNodeChanged(vtkMRMLNode*)', self.setInputNode2) ioFormLayout.addRow("Input Volume 2 (optional):", inputNodeSelector2) self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', inputNodeSelector2, 'setMRMLScene(vtkMRMLScene*)') self.inputNodeSelector2 = inputNodeSelector2 # inputVolume node selector 3 inputNodeSelector3 = slicer.qMRMLNodeComboBox() inputNodeSelector3.objectName = 'inputNodeSelector3' inputNodeSelector3.toolTip = "Select the 3rd input volume to be segmented." inputNodeSelector3.nodeTypes = ['vtkMRMLScalarVolumeNode'] inputNodeSelector3.noneEnabled = True inputNodeSelector3.addEnabled = False inputNodeSelector3.removeEnabled = False inputNodeSelector3.editEnabled = True inputNodeSelector3.connect('currentNodeChanged(vtkMRMLNode*)', self.setInputNode3) ioFormLayout.addRow("Input Volume 3 (optional):", inputNodeSelector3) self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', inputNodeSelector3, 'setMRMLScene(vtkMRMLScene*)') self.inputNodeSelector3 = inputNodeSelector3 # outputVolume node selector outputNodeSelector = slicer.qMRMLNodeComboBox() outputNodeSelector.objectName = 'outputNodeSelector' outputNodeSelector.toolTip = "Select the output volume to be segmented." outputNodeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] outputNodeSelector.noneEnabled = False outputNodeSelector.addEnabled = True outputNodeSelector.removeEnabled = False outputNodeSelector.editEnabled = True outputNodeSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.setOutputNode) ioFormLayout.addRow("Output Volume:", outputNodeSelector) self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', outputNodeSelector, 'setMRMLScene(vtkMRMLScene*)') self.outputNodeSelector = outputNodeSelector # LABEL MAP COLLAPSIBLE BUTTON labelMapCollapsibleButton = ctk.ctkCollapsibleButton() labelMapCollapsibleButton.text = "Label Maps" self.layout.addWidget(labelMapCollapsibleButton) # Layout within the labelMap collapsible button labelMapFormLayout = qt.QFormLayout(labelMapCollapsibleButton) # labelMap node selector labelMapNodeSelector = slicer.qMRMLNodeComboBox() labelMapNodeSelector.objectName = 'labelMapNodeSelector' labelMapNodeSelector.toolTip = "Select the label map roughly outlining the structure to be segmented and its background." labelMapNodeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] labelMapNodeSelector.addAttribute("vtkMRMLScalarVolumeNode", "LabelMap", True) labelMapNodeSelector.noneEnabled = False labelMapNodeSelector.addEnabled = True labelMapNodeSelector.removeEnabled = False labelMapNodeSelector.editEnabled = True labelMapNodeSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.setLabelMapNode) labelMapFormLayout.addRow("Label Map:", labelMapNodeSelector) self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', labelMapNodeSelector, 'setMRMLScene(vtkMRMLScene*)') self.labelMapNodeSelector = labelMapNodeSelector # Create frame editor widget editorFrame = qt.QFrame() editorFrame.setLayout(qt.QVBoxLayout()) palette = editorFrame.palette bgColor = 240 palette.setColor(qt.QPalette.Background, qt.QColor(bgColor, bgColor, bgColor)) editorFrame.setPalette(palette) editorFrame.setAutoFillBackground(True) labelMapFormLayout.addRow(editorFrame) self.editorFrame = editorFrame # initialize editor widget: using parent frame, embedded is true and list of effects self.editorWidget = __main__.EditorWidget( parent=self.editorFrame, embedded=True, suppliedEffects=self.editorEffects, showVolumesFrame=False) # voidLabel selector # The voidLabel selector selects which label corresponds to the void label # All other labels in the label map will be extracted and set to object labels voidLabelSpinBox = qt.QSpinBox() voidLabelSpinBox.objectName = 'voidLabelSpinBox' voidLabelSpinBox.toolTip = "Value that represents nothing in the label map. All other labels represent objects." voidLabelSpinBox.setMinimum(0) voidLabelSpinBox.setMaximum(255) # temporary value to start voidLabelSpinBox.enabled = False labelMapFormLayout.addRow("Void Id:", voidLabelSpinBox) self.voidLabelSpinBox = voidLabelSpinBox #->> TODO: later on, would like a label combo box that shows only those labels # that are included in the label map # The following code starts in that direction, but does not work # BEGIN hacking ## voidLabelSelector = slicer.qMRMLLabelComboBox() ## voidLabelSelector.maximumColorCount = 256 #->> TODO ## labelMapFormLayout.addRow("Void Label:", voidLabelSelector) ## self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', ## voidLabelSelector, 'setMRMLScene(vtkMRMLScene*)') ## # create a new vtkMRMLColorTableNode to hold the labels in the label map ## colorLogic = slicer.vtkSlicerColorLogic() ## defaultID = colorLogic.GetDefaultEditorColorNodeID() ## defaultNode = slicer.mrmlScene.GetNodeByID(defaultID) ## if defaultNode: ## # create the node based on the default editor color node ## self.labelsColorNode = slicer.vtkMRMLColorTableNode() ## self.labelsColorNode.Copy(defaultNode) ## # substitute in a new lookup table that we will manipulate ## lookupTable = vtk.vtkLookupTable() ## lookupTable.DeepCopy(defaultNode.GetLookupTable()) ## defaultLookupTable = defaultNode.GetLookupTable() ## list = [3,5,7,9] ## lookupTable.SetNumberOfTableValues(len(list)) ## for i in range(0, len(list)): ## orig = [] ## defaultLookupTable.GetTableValue(list[i], orig) ## lookupTable.SetTableValue(i, defaultNode.GetLookupTable(). ## self.labelsColorNode.SetLookupTable(lookupTable) ## # set the new color node to the selector ## # voidLabelSelector.setMRMLColorNode(self.labelsColorNode) ## print "lut:", self.labelsColorNode.GetLookupTable() ## self.voidLabelSelector = voidLabelSelector # END hacking #->> TODO: another alternative is to use an EditColor - but it is heavily coupled # to the editor logic, using an editor parameter node that ties it with the editor # widget's EditColor # Create a frame to give the EditColor a suitable parent ## voidLabelFrame = qt.QFrame() ## voidLabelFrame.setLayout(qt.QHBoxLayout()) ## voidLabelFrame.toolTip = "Value that represents nothing in the label map. All labels not equal to the void id represent objects." ## voidLabelSelector = EditorLib.EditColor(parent=voidLabelFrame) ## labelMapFormLayout.addRow("Void Id", voidLabelFrame) ## self.voidLabelSelector = voidLabelSelector # SEGMENTATION PARAMETERS COLLAPSIBLE BUTTON segmentationCollapsibleButton = ctk.ctkCollapsibleButton() segmentationCollapsibleButton.text = "Segmentation Parameters" self.layout.addWidget(segmentationCollapsibleButton) # Layout within the parameters collapsible button segmentationFormLayout = qt.QFormLayout(segmentationCollapsibleButton) # segmentation "goal" buttons self.goalButtonList = [] goalButtonGroup = qt.QButtonGroup() goalGroupBox = qt.QGroupBox() goalGroupBox.objectName = 'goalGroupBox' goalGroupBox.toolTip = "Select what the goal segmentation looks like" goalGroupBoxLayout = qt.QHBoxLayout() for i in range(0, len(self.goalButtonTexts)): button = qt.QToolButton() button.setText(self.goalButtonTexts[i]) button.setCheckable(True) goalButtonGroup.addButton(button, i) goalGroupBoxLayout.addWidget(button) self.goalButtonList.append(button) self.goalButtonList[self.goalButtonDefault].setChecked(True) goalButtonGroup.setExclusive(True) goalButtonGroup.connect('buttonClicked(int)', self.setGoalSegmentationType) goalGroupBox.setLayout(goalGroupBoxLayout) goalGroupBox.setFlat(True) segmentationFormLayout.addRow("Goal Segmentation:", goalGroupBox) self.goalButtonGroup = goalButtonGroup # ADVANCED PARAMETERS COLLAPSIBLE BUTTON advancedCollapsibleButton = ctk.ctkCollapsibleButton() advancedCollapsibleButton.text = "Advanced Parameters" self.layout.addWidget(advancedCollapsibleButton) # Layout within the parameters collapsible button advancedFormLayout = qt.QFormLayout(advancedCollapsibleButton) # Erosion radius spin box erosionSpinBox = qt.QSpinBox() erosionSpinBox.objectName = 'erosionSpinBox' erosionSpinBox.toolTip = "Set the erosion radius." erosionSpinBox.setMinimum(0) erosionSpinBox.connect('valueChanged(int)', self.setErosionRadius) advancedFormLayout.addRow("Erosion Radius:", erosionSpinBox) self.erosionSpinBox = erosionSpinBox # Hole fill iterations spin box holeFillSpinBox = qt.QSpinBox() holeFillSpinBox.objectName = 'holeFillSpinBox' holeFillSpinBox.toolTip = "Set the number of hole filling iterations." holeFillSpinBox.setMinimum(0) holeFillSpinBox.connect('valueChanged(int)', self.setHoleFillIterations) advancedFormLayout.addRow("Hole Fill Iterations:", holeFillSpinBox) self.holeFillSpinBox = holeFillSpinBox # falsePositiveRatio spin box falsePositiveRatioSpinBox = qt.QDoubleSpinBox() falsePositiveRatioSpinBox.objectName = 'falsePositiveRatioSpinBox' falsePositiveRatioSpinBox.toolTip = "Relative Cost of False Positive vs. false negative." falsePositiveRatioSpinBox.setMinimum(0.0) falsePositiveRatioSpinBox.setValue(1.0) # Default falsePositiveRatioSpinBox.setSingleStep(0.1) advancedFormLayout.addRow("False Positive Ratio:", falsePositiveRatioSpinBox) self.falsePositiveRatioSpinBox = falsePositiveRatioSpinBox # probabilitySmoothingStandardDeviation spin box probabilitySmoothingStdDevSpinBox = qt.QDoubleSpinBox() probabilitySmoothingStdDevSpinBox.objectName = 'probabilitySmoothingStdDevSpinBox' probabilitySmoothingStdDevSpinBox.toolTip = "Standard deviation of blur applied to probability images prior to computing maximum likelihood of each class at each pixel." probabilitySmoothingStdDevSpinBox.setMinimum(0.0) probabilitySmoothingStdDevSpinBox.setValue(3.0) # Default probabilitySmoothingStdDevSpinBox.setSingleStep(0.1) advancedFormLayout.addRow("Probability Smoothing Standard Deviation:", probabilitySmoothingStdDevSpinBox) self.probabilitySmoothingStdDevSpinBox = probabilitySmoothingStdDevSpinBox # draft check box draftCheckBox = qt.QCheckBox() draftCheckBox.objectName = 'draftCheckBox' draftCheckBox.toolTip = "Generate draft results?" advancedFormLayout.addRow("Draft Mode:", draftCheckBox) self.draftCheckBox = draftCheckBox # reclassifyObjectMask check box reclassifyObjectMaskCheckBox = qt.QCheckBox() reclassifyObjectMaskCheckBox.objectName = 'reclassifyObjectMaskCheckBox' reclassifyObjectMaskCheckBox.toolTip = "Perform classification on voxels within the object mask?" reclassifyObjectMaskCheckBox.setChecked(True) advancedFormLayout.addRow("Reclassify Object Mask:", reclassifyObjectMaskCheckBox) self.reclassifyObjectMaskCheckBox = reclassifyObjectMaskCheckBox # reclassifyNotObjectMask check box reclassifyNotObjectMaskCheckBox = qt.QCheckBox() reclassifyNotObjectMaskCheckBox.objectName = 'reclassifyNotObjectMaskCheckBox' reclassifyNotObjectMaskCheckBox.toolTip = "Perform classification on all non-void voxels?" reclassifyNotObjectMaskCheckBox.setChecked(True) advancedFormLayout.addRow("Reclassify Not Object Mask:", reclassifyNotObjectMaskCheckBox) self.reclassifyNotObjectMaskCheckBox = reclassifyNotObjectMaskCheckBox # SEGMENTATION BUTTON segmentCollapsibleButton = ctk.ctkCollapsibleButton() segmentCollapsibleButton.text = "Run Segmentation" self.layout.addWidget(segmentCollapsibleButton) # Layout within the parameters collapsible button segmentFormLayout = qt.QFormLayout(segmentCollapsibleButton) # segmentation button segmentationButton = qt.QPushButton("Segment") segmentationButton.toolTip = "Perform PDF Segmentation." segmentFormLayout.addRow(segmentationButton) segmentationButton.connect('clicked()', self.onSegmentationButtonClicked) # Now that we've created all UI elements, apply the default goal segmentation type self.setGoalSegmentationType(self.goalButtonDefault)
def __init__(self): columnNames = ["Include", "Name", "Radius"] self.model = firstColumnCheckableModel(1, len(columnNames)) self.model.updateSelectedFuntion = self.updateSelected for i, columnName in enumerate(columnNames): self.model.setHeaderData(i, qt.Qt.Horizontal, columnName) self.view = qt.QTableView() self.view.setEditTriggers(self.view.DoubleClicked) self.view.setSelectionMode(self.view.SingleSelection) self.view.setSelectionBehavior(self.view.SelectRows) self.view.horizontalHeader().setStretchLastSection(True) self.view.verticalHeader().setDefaultSectionSize( self.view.verticalHeader().defaultSectionSize * 3 / 4) self.view.setHorizontalScrollMode(self.view.ScrollPerPixel) self.view.setModel(self.model) self.view.clicked.connect(self.onSelectionChanged) self.view.setItemDelegateForColumn( 1, TextEditDelegate(self.model, self.renameControlPoints)) self.view.setItemDelegateForColumn( 2, SpinBoxDelegate(self.model, self.updateRadius)) super().__init__() effectPixmap = qt.QPixmap( os.path.join( os.path.split(WarpDrive.__file__)[0], 'Resources', 'Icons', 'SlicerVisible.png')) effectIcon = qt.QIcon(effectPixmap) self.sourceVisibleButton = qt.QToolButton() self.sourceVisibleButton.setToolButtonStyle( qt.Qt.ToolButtonTextUnderIcon) self.sourceVisibleButton.setIcon(effectIcon) self.sourceVisibleButton.setIconSize(effectPixmap.rect().size()) self.sourceVisibleButton.setText('Source') self.sourceVisibleButton.setToolTip( 'Toggle source fiducials visibility') self.sourceVisibleButton.setCheckable(True) self.sourceVisibleButton.setChecked(False) self.sourceVisibleButton.setEnabled(True) self.sourceVisibleButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.sourceVisibleButton.toggled.connect(self.onSourceVisibleToggled) effectPixmap = qt.QPixmap( os.path.join( os.path.split(WarpDrive.__file__)[0], 'Resources', 'Icons', 'SlicerVisible.png')) effectIcon = qt.QIcon(effectPixmap) self.targetVisibleButton = qt.QToolButton() self.targetVisibleButton.setToolButtonStyle( qt.Qt.ToolButtonTextUnderIcon) self.targetVisibleButton.setIcon(effectIcon) self.targetVisibleButton.setIconSize(effectPixmap.rect().size()) self.targetVisibleButton.setText('Target') self.targetVisibleButton.setToolTip( 'Toggle target fiducials visibility') self.targetVisibleButton.setCheckable(True) self.targetVisibleButton.setChecked(False) self.targetVisibleButton.setEnabled(True) self.targetVisibleButton.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.Maximum) self.targetVisibleButton.toggled.connect(self.onTargetVisibleToggled) self.buttonsFrame.layout().addWidget(self.sourceVisibleButton, 1) self.buttonsFrame.layout().addWidget(self.targetVisibleButton, 1) self.addButton.setText('Fixed point') self.addButton.setToolTip('Add fixed point')
def setupOptionsFrame(self): self.thresholdSliderLabel = qt.QLabel("Threshold Range:") self.thresholdSliderLabel.setToolTip( "Set the range of the background values that should be labeled.") self.scriptedEffect.addOptionsWidget(self.thresholdSliderLabel) self.thresholdSlider = ctk.ctkRangeWidget() self.thresholdSlider.spinBoxAlignment = qt.Qt.AlignTop self.thresholdSlider.singleStep = 0.01 self.scriptedEffect.addOptionsWidget(self.thresholdSlider) self.autoThresholdModeSelectorComboBox = qt.QComboBox() self.autoThresholdModeSelectorComboBox.addItem("auto->maximum", MODE_SET_LOWER_MAX) self.autoThresholdModeSelectorComboBox.addItem("minimum->auto", MODE_SET_MIN_UPPER) self.autoThresholdModeSelectorComboBox.addItem("as lower", MODE_SET_LOWER) self.autoThresholdModeSelectorComboBox.addItem("as upper", MODE_SET_UPPER) self.autoThresholdModeSelectorComboBox.setToolTip( "How to set lower and upper threshold values. Current refers to keeping the current value." ) self.autoThresholdMethodSelectorComboBox = qt.QComboBox() self.autoThresholdMethodSelectorComboBox.addItem("Otsu", METHOD_OTSU) self.autoThresholdMethodSelectorComboBox.addItem("Huang", METHOD_HUANG) self.autoThresholdMethodSelectorComboBox.addItem( "IsoData", METHOD_ISO_DATA) # Kittler-Illingworth sometimes fails with an exception, but it does not cause any major issue, # it just logs an error message and does not compute a new threshold value self.autoThresholdMethodSelectorComboBox.addItem( "Kittler-Illingworth", METHOD_KITTLER_ILLINGWORTH) # Li sometimes crashes (index out of range error in # ITK/Modules/Filtering/Thresholding/include/itkLiThresholdCalculator.hxx#L94) # We can add this method back when issue is fixed in ITK. #self.autoThresholdMethodSelectorComboBox.addItem("Li", METHOD_LI) self.autoThresholdMethodSelectorComboBox.addItem( "Maximum entropy", METHOD_MAXIMUM_ENTROPY) self.autoThresholdMethodSelectorComboBox.addItem( "Moments", METHOD_MOMENTS) self.autoThresholdMethodSelectorComboBox.addItem( "Renyi entropy", METHOD_RENYI_ENTROPY) self.autoThresholdMethodSelectorComboBox.addItem( "Shanbhag", METHOD_SHANBHAG) self.autoThresholdMethodSelectorComboBox.addItem( "Triangle", METHOD_TRIANGLE) self.autoThresholdMethodSelectorComboBox.addItem("Yen", METHOD_YEN) self.autoThresholdMethodSelectorComboBox.setToolTip( "Select method to compute threshold value automatically.") self.selectPreviousAutoThresholdButton = qt.QToolButton() self.selectPreviousAutoThresholdButton.text = "<" self.selectPreviousAutoThresholdButton.setToolTip( "Select previous thresholding method and set thresholds." + " Useful for iterating through all available methods.") self.selectNextAutoThresholdButton = qt.QToolButton() self.selectNextAutoThresholdButton.text = ">" self.selectNextAutoThresholdButton.setToolTip( "Select next thresholding method and set thresholds." + " Useful for iterating through all available methods.") self.setAutoThresholdButton = qt.QPushButton("Set") self.setAutoThresholdButton.setToolTip( "Set threshold using selected method.") # qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) # fails on some systems, therefore set the policies using separate method calls qSize = qt.QSizePolicy() qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding) self.setAutoThresholdButton.setSizePolicy(qSize) autoThresholdFrame = qt.QHBoxLayout() autoThresholdFrame.addWidget(self.autoThresholdModeSelectorComboBox) autoThresholdFrame.addWidget(self.autoThresholdMethodSelectorComboBox) autoThresholdFrame.addWidget(self.selectPreviousAutoThresholdButton) autoThresholdFrame.addWidget(self.selectNextAutoThresholdButton) autoThresholdFrame.addWidget(self.setAutoThresholdButton) self.scriptedEffect.addLabeledOptionsWidget("Automatic threshold:", autoThresholdFrame) self.useForPaintButton = qt.QPushButton("Use for masking") self.useForPaintButton.setToolTip( "Use specified intensity range for masking and switch to Paint effect." ) self.scriptedEffect.addOptionsWidget(self.useForPaintButton) self.applyButton = qt.QPushButton("Apply") self.applyButton.objectName = self.__class__.__name__ + 'Apply' self.applyButton.setToolTip( "Fill selected segment in regions that are in the specified intensity range." ) self.scriptedEffect.addOptionsWidget(self.applyButton) self.useForPaintButton.connect('clicked()', self.onUseForPaint) self.thresholdSlider.connect('valuesChanged(double,double)', self.onThresholdValuesChanged) self.autoThresholdMethodSelectorComboBox.connect( "activated(int)", self.onSelectedAutoThresholdMethod) self.autoThresholdModeSelectorComboBox.connect( "activated(int)", self.onSelectedAutoThresholdMethod) self.selectPreviousAutoThresholdButton.connect( 'clicked()', self.onSelectPreviousAutoThresholdMethod) self.selectNextAutoThresholdButton.connect( 'clicked()', self.onSelectNextAutoThresholdMethod) self.setAutoThresholdButton.connect('clicked()', self.onAutoThreshold) self.applyButton.connect('clicked()', self.onApply)
def addItem(self, item_cfg, parent): type = item_cfg["type"] item_name = item_cfg["name"] newItem = None try: klass = WindowDisplayWidget.items[type] except KeyError: # item is a brick newItem = item_cfg["brick"] newItem.reparent(parent, 0, qt.QPoint(0, 0), True) else: #print 'adding %s, executionMode=%s' % (item_cfg["name"], self.executionMode) newItem = klass(parent, item_cfg["name"], executionMode=self.executionMode) if type in ("vbox", "hbox", "vgroupbox", "hgroupbox"): if item_cfg["properties"]["color"] is not None: try: qtcolor = qt.QColor(item_cfg["properties"]["color"]) newItem.setPaletteBackgroundColor( qt.QColor(qtcolor.red(), qtcolor.green(), qtcolor.blue())) except: logging.getLogger().exception( "Could not set color on item %s", item_cfg["name"]) if type.endswith("groupbox"): newItem.setTitle(item_cfg["properties"]["label"]) newItem.layout().setSpacing(item_cfg["properties"]["spacing"]) newItem.layout().setMargin(item_cfg["properties"]["margin"]) frame_style = qt.QFrame.NoFrame if item_cfg["properties"]["frameshape"] != "default": print "frameshape... ", item_cfg["properties"][ "frameshape"] frame_style = getattr( qt.QFrame, item_cfg["properties"]["frameshape"].capitalize()) if item_cfg["properties"]["shadowstyle"] != "default": frame_style = frame_style | getattr( qt.QFrame, item_cfg["properties"]["shadowstyle"].capitalize()) if frame_style != qt.QFrame.NoFrame: try: newItem.setFrameStyle(frame_style) except: logging.getLogger().exception( "Could not set frame style on item %s", item_cfg["name"]) elif type == "icon": img = qt.QPixmap() if img.load(item_cfg["properties"]["filename"]): newItem.setPixmap(img) elif type == "label": newItem.setText(item_cfg["properties"]["text"]) elif type == "tab": item_cfg.widget = newItem newItem.cmdCloseTab = qt.QToolButton(newItem) newItem.cmdCloseTab.setIconSet( qt.QIconSet(Icons.load('delete_small'))) newItem.setCornerWidget(newItem.cmdCloseTab) newItem.cmdCloseTab.hide() def close_current_page(tab=newItem): slotName = "hidePage_%s" % str( tab.tabLabel(tab.currentPage())) slotName = slotName.replace(" ", "_") getattr(tab, slotName)() qt.qApp.emit(qt.PYSIGNAL('tab_closed'), (tab, slotName)) newItem._close_current_page_cb = close_current_page qt.QObject.connect(newItem, qt.SIGNAL('currentChanged( QWidget * )'), item_cfg.notebookPageChanged) qt.QObject.connect(newItem.cmdCloseTab, qt.SIGNAL("clicked()"), close_current_page) elif type == "vsplitter" or type == "hsplitter": pass newItem.show() return newItem