class ChooseDataDialog(QtGui.QDialog): def __init__(self, parent, ivm, used=[]): super(ChooseDataDialog, self).__init__(parent) self.setWindowTitle("Add VFA data set") vbox = QtGui.QVBoxLayout() grid = QtGui.QGridLayout() grid.addWidget(QtGui.QLabel("Data set"), 0, 0) self.data_combo = OverlayCombo(ivm, static_only=True) # Default to first data which hasn't been used data = [ i for i in range(self.data_combo.count()) if self.data_combo.itemText(i) not in used ] if len(data) > 0: self.data_combo.setCurrentIndex(data[0]) self.data_combo.currentIndexChanged.connect(self._guess_fa) grid.addWidget(self.data_combo, 0, 1) grid.addWidget(QtGui.QLabel("Flip angle (\N{DEGREE SIGN})"), 1, 0) self.fa_edit = QtGui.QLineEdit() self.fa_edit.textChanged.connect(self._validate) grid.addWidget(self.fa_edit, 1, 1) vbox.addLayout(grid) self.buttonBox = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False) vbox.addWidget(self.buttonBox) self.setLayout(vbox) self._guess_fa() self._validate() def _guess_fa(self): name = self.data_combo.currentText() m = re.search(r".*?(\d+).*$", name) if m is not None: guess = m.group(1) else: guess = "" self.fa_edit.setText(guess) def _validate(self): valid = True try: fa = float(self.fa_edit.text()) self.fa_edit.setStyleSheet("") except: self.fa_edit.setStyleSheet("QLineEdit {background-color: red}") valid = False self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(valid)
class OverlayViewWidget(QtGui.QGroupBox): """ Change view options for ROI """ def __init__(self, ivl, view): QtGui.QGroupBox.__init__(self) self.ivl = ivl self.ivm = ivl.ivm self.view = view grid = QtGui.QGridLayout() grid.setVerticalSpacing(2) grid.setContentsMargins(5, 5, 5, 5) self.setLayout(grid) grid.addWidget(QtGui.QLabel("Overlay"), 0, 0) self.overlay_combo = OverlayCombo(self.ivm, none_option=True, set_first=False) grid.addWidget(self.overlay_combo, 0, 1) grid.addWidget(QtGui.QLabel("View"), 1, 0) self.ov_view_combo = QtGui.QComboBox() self.ov_view_combo.addItem("All") self.ov_view_combo.addItem("Only in ROI") self.ov_view_combo.addItem("None") grid.addWidget(self.ov_view_combo, 1, 1) grid.addWidget(QtGui.QLabel("Color map"), 2, 0) hbox = QtGui.QHBoxLayout() self.ov_cmap_combo = QtGui.QComboBox() self.ov_cmap_combo.addItem("jet") self.ov_cmap_combo.addItem("hot") self.ov_cmap_combo.addItem("gist_heat") self.ov_cmap_combo.addItem("flame") self.ov_cmap_combo.addItem("bipolar") self.ov_cmap_combo.addItem("spectrum") hbox.addWidget(self.ov_cmap_combo) self.ov_levels_btn = QtGui.QPushButton() self.ov_levels_btn.setIcon(QtGui.QIcon(get_icon("levels.png"))) self.ov_levels_btn.setFixedSize(16, 16) self.ov_levels_btn.setToolTip("Adjust colour map levels") self.ov_levels_btn.clicked.connect(self._show_ov_levels) self.ov_levels_btn.setEnabled(False) hbox.addWidget(self.ov_levels_btn) grid.addLayout(hbox, 2, 1) grid.addWidget(QtGui.QLabel("Alpha"), 3, 0) self.ov_alpha_sld = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.ov_alpha_sld.setFocusPolicy(QtCore.Qt.NoFocus) self.ov_alpha_sld.setRange(0, 255) self.ov_alpha_sld.setValue(255) grid.addWidget(self.ov_alpha_sld, 3, 1) grid.setRowStretch(4, 1) self.overlay_combo.currentIndexChanged.connect(self._combo_changed) self.ov_view_combo.currentIndexChanged.connect(self._view_changed) self.ov_cmap_combo.currentIndexChanged.connect(self._cmap_changed) self.ov_alpha_sld.valueChanged.connect(self._alpha_changed) self.view.sig_view_changed.connect(self._update) def _update(self, view): widgets = [ self.ov_view_combo, self.ov_cmap_combo, self.ov_alpha_sld, self.overlay_combo ] try: for widget in widgets: widget.blockSignals(True) if not view.get("visible"): self.ov_view_combo.setCurrentIndex(2) elif view.get("roi_only"): self.ov_view_combo.setCurrentIndex(1) else: self.ov_view_combo.setCurrentIndex(0) # 'Custom' only appears as a flag to indicate the user has messed with the # LUT using the histogram widget. Otherwise is is hidden cmap = view.get("cmap") if cmap == "custom": idx = self.ov_cmap_combo.findText("custom") if idx >= 0: self.ov_cmap_combo.setCurrentIndex(idx) else: self.ov_cmap_combo.addItem("custom") idx = self.ov_cmap_combo.findText("custom") self.ov_cmap_combo.setCurrentIndex(idx) else: idx = self.ov_cmap_combo.findText("custom") if idx >= 0: self.ov_cmap_combo.removeItem(idx) idx = self.ov_cmap_combo.findText(view.get("cmap")) self.ov_cmap_combo.setCurrentIndex(idx) self.ov_alpha_sld.setValue(view.get("alpha")) self.ov_levels_btn.setEnabled(view.data is not None) if view.data is not None: idx = self.overlay_combo.findText(view.data.name) self.overlay_combo.setCurrentIndex(idx) else: self.overlay_combo.setCurrentIndex(-1) except: import traceback traceback.print_exc() finally: for widget in widgets: widget.blockSignals(False) def _combo_changed(self, idx): if idx > 0: data_name = self.overlay_combo.itemText(idx) self.ivm.set_current_data(data_name) else: self.ivl.ivm.set_current_data(None) def _cmap_changed(self, idx): cmap = self.ov_cmap_combo.itemText(idx) self.view.set("cmap", cmap) def _view_changed(self, idx): """ Viewing style (all or within ROI only) changed """ self.view.set("visible", idx in (0, 1)) self.view.set("roi_only", (idx == 1)) def _alpha_changed(self, alpha): """ Set the data transparency """ self.view.set("alpha", alpha) def _show_ov_levels(self): dlg = LevelsDialog(self, self.ivl, self.ivm, self.view) dlg.exec_()