def emitter(ob): """Returns a QObject surrogate for *ob*, to use in Qt signaling. This function enables you to connect to and emit signals from (almost) any python object with having to subclass QObject. >>> class A(object): ... def notify(self, *args): ... QObject.emit(emitter(self), PYSIGNAL('test'), args) ... >>> ob = A() >>> def myhandler(*args): print 'got', args ... >>> QObject.connect(emitter(ob), PYSIGNAL('test'), myhandler) ... True >>> ob.notify('hello') got ('hello',) >>> QObject.emit(emitter(ob), PYSIGNAL('test'), (42, 'abc',)) got (42, 'abc') """ if ob not in _emitterCache: _emitterCache[ob] = qt.QObject() return _emitterCache[ob]
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): QToolBar.__init__(self) VTKObservationMixin.__init__(self) self.parameterNode = WarpDrive.WarpDriveLogic().getParameterNode() self.addObserver(self.parameterNode, vtk.vtkCommand.ModifiedEvent, self.updateToolbarFromParameterNode) self.setWindowTitle(qt.QObject().tr("LeadDBS")) self.name = 'LeadDBS' # # Modality # self.addWidget(qt.QLabel('Modality:')) self.modalityComboBox = qt.QComboBox() self.modalityComboBox.addItem('T1w') self.modalityComboBox.view().pressed.connect(self.onModalityPressed) self.addWidget(self.modalityComboBox) # # B <-> F slider # self.addSeparator() self.addWidget(qt.QLabel('Template:')) templateSlider = qt.QSlider(1) templateSlider.singleStep = 10 templateSlider.minimum = 0 templateSlider.maximum = 100 templateSlider.value = 0 templateSlider.setFixedWidth(120) templateSlider.connect( 'valueChanged(int)', lambda value: slicer.util. setSliceViewerLayers(foregroundOpacity=value / 100.0)) self.addWidget(templateSlider) # # Space Separator # self.addSeparator() empty = qt.QWidget() empty.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Preferred) self.addWidget(empty) # # Subject # self.subjectNameLabel = qt.QLabel('Subject: ') self.addWidget(self.subjectNameLabel) # # Harden Changes # self.addSeparator() self.hardenChangesCheckBox = qt.QCheckBox("Harden Changes") self.hardenChangesCheckBox.checked = True self.addWidget(self.hardenChangesCheckBox) # # Save # self.nextButton = qt.QPushButton("Exit") self.nextButton.setFixedWidth(75) self.nextButton.setStyleSheet("background-color: green") self.addWidget(self.nextButton) self.nextButton.connect("clicked(bool)", self.onNextButton) # # Update # self.updateModalities(self.parameterNode.GetParameter("subjectPath")) self.initSubject() self.updateToolbarFromParameterNode()
def __init__(self): QToolBar.__init__(self) VTKObservationMixin.__init__(self) self.parameterNode = SmudgeModule.SmudgeModuleLogic().getParameterNode() self.addObserver(self.parameterNode, vtk.vtkCommand.ModifiedEvent, self.updateToolbarFromMRML) self.setWindowTitle(qt.QObject().tr("LeadDBS")) self.name = 'LeadDBS' # # Modality # self.addWidget(qt.QLabel('Modality:')) self.modalityComboBox = qt.QComboBox() self.modalityComboBox.addItem('t1') self.modalityComboBox.view().pressed.connect(self.onModalityPressed) self.addWidget(self.modalityComboBox) # # B <-> F slider # self.addSeparator() self.addWidget(qt.QLabel('Template:')) templateSlider = qt.QSlider(1) templateSlider.singleStep = 10 templateSlider.minimum = 0 templateSlider.maximum = 100 templateSlider.value = 0 templateSlider.setFixedWidth(120) templateSlider.connect('valueChanged(int)', lambda value: slicer.util.setSliceViewerLayers(foregroundOpacity = value / 100.0)) self.addWidget(templateSlider) # # Resolution # self.addSeparator() self.addWidget(qt.QLabel('Warp Resolution: ')) self.resolutionComboBox = qt.QComboBox() avalibaleResolutions = [0.5, 1, 2, 5, 10] self.resolutionComboBox.addItems([str(r)+'mm' for r in avalibaleResolutions]) self.resolutionComboBox.setCurrentIndex(avalibaleResolutions.index(float(self.parameterNode.GetParameter("resolution")))) self.resolutionComboBox.connect('currentIndexChanged(int)', self.onResolutionChanged) self.addWidget(self.resolutionComboBox) # # Space Separator # empty = qt.QWidget() empty.setSizePolicy(qt.QSizePolicy.Expanding,qt.QSizePolicy.Preferred) self.addWidget(empty) # # Subject # self.subjectNameLabel = qt.QLabel('Subject: ') self.addWidget(self.subjectNameLabel) # # Save # self.saveButton = qt.QPushButton("Finish and Exit") self.saveButton.setFixedWidth(200) self.saveButton.setStyleSheet("background-color: green") self.addWidget(self.saveButton) ImportAtlas.ImportAtlasLogic().run(os.path.join(self.parameterNode.GetParameter("MNIAtlasPath"), 'DISTAL Minimal (Ewert 2017)')) self.saveButton.connect("clicked(bool)", self.onSaveButton) # # Update # self.updateModalities(self.parameterNode.GetParameter("subjectPath")) reducedToolbarLogic().loadSubjectTransforms() self.onModalityPressed([],self.modalityComboBox.currentText) self.updateToolbarFromMRML()