class ColorbarWidget(QWidget): colorbarChanged = Signal() # The parent should simply redraw their canvas def __init__(self, parent=None): super(ColorbarWidget, self).__init__(parent) self.setWindowTitle("Colorbar") self.setMaximumWidth(200) self.cmap = QComboBox() self.cmap.addItems(sorted(cm.cmap_d.keys())) self.cmap.currentIndexChanged.connect(self.cmap_index_changed) self.cmin = QLineEdit() self.cmin_value = 0 self.cmin.setMaximumWidth(100) self.cmin.editingFinished.connect(self.clim_changed) self.cmin_layout = QHBoxLayout() self.cmin_layout.addStretch() self.cmin_layout.addWidget(self.cmin) self.cmin_layout.addStretch() self.cmax = QLineEdit() self.cmax_value = 1 self.cmax.setMaximumWidth(100) self.cmax.editingFinished.connect(self.clim_changed) self.cmin.setValidator(QDoubleValidator()) self.cmax.setValidator(QDoubleValidator()) self.cmax_layout = QHBoxLayout() self.cmax_layout.addStretch() self.cmax_layout.addWidget(self.cmax) self.cmax_layout.addStretch() self.norm_layout = QHBoxLayout() self.norm = QComboBox() self.norm.addItems(NORM_OPTS) self.norm.currentIndexChanged.connect(self.norm_changed) self.powerscale = QLineEdit() self.powerscale_value = 2 self.powerscale.setText("2") self.powerscale.setValidator(QDoubleValidator(0.001,100,3)) self.powerscale.setMaximumWidth(50) self.powerscale.editingFinished.connect(self.norm_changed) self.powerscale.hide() self.powerscale_label = QLabel("n=") self.powerscale_label.hide() self.norm_layout.addStretch() self.norm_layout.addWidget(self.norm) self.norm_layout.addStretch() self.norm_layout.addWidget(self.powerscale_label) self.norm_layout.addWidget(self.powerscale) self.autoscale = QCheckBox("Autoscaling") self.autoscale.setChecked(True) self.autoscale.stateChanged.connect(self.update_clim) self.canvas = FigureCanvas(Figure()) if parent: # Set facecolor to match parent self.canvas.figure.set_facecolor(parent.palette().window().color().getRgbF()) self.ax = self.canvas.figure.add_axes([0.4,0.05,0.2,0.9]) # layout self.layout = QVBoxLayout(self) self.layout.addWidget(self.cmap) self.layout.addLayout(self.cmax_layout) self.layout.addWidget(self.canvas, stretch=1) self.layout.addLayout(self.cmin_layout) self.layout.addLayout(self.norm_layout) self.layout.addWidget(self.autoscale) def set_mappable(self, mappable): """ When a new plot is created this method should be called with the new mappable """ self.ax.clear() try: # Use current cmap cmap = self.colorbar.get_cmap() except AttributeError: try: # else use viridis cmap = cm.viridis except AttributeError: # else default cmap = None self.colorbar = Colorbar(ax=self.ax, mappable=mappable) self.cmin_value, self.cmax_value = self.colorbar.get_clim() self.update_clim_text() self.cmap_changed(cmap) self.cmap.setCurrentIndex(sorted(cm.cmap_d.keys()).index(self.colorbar.get_cmap().name)) self.redraw() def cmap_index_changed(self): self.cmap_changed(self.cmap.currentText()) def cmap_changed(self, name): self.colorbar.set_cmap(name) self.colorbar.mappable.set_cmap(name) self.redraw() def norm_changed(self): """ Called when a different normalization is selected """ idx = self.norm.currentIndex() if NORM_OPTS[idx] == 'Power': self.powerscale.show() self.powerscale_label.show() else: self.powerscale.hide() self.powerscale_label.hide() self.colorbar.mappable.set_norm(self.get_norm()) self.set_mappable(self.colorbar.mappable) def get_norm(self): """ This will create a matplotlib.colors.Normalize from selected idx, limits and powerscale """ idx = self.norm.currentIndex() if self.autoscale.isChecked(): cmin = cmax = None else: cmin = self.cmin_value cmax = self.cmax_value if NORM_OPTS[idx] == 'Power': if self.powerscale.hasAcceptableInput(): self.powerscale_value = float(self.powerscale.text()) return PowerNorm(gamma=self.powerscale_value, vmin=cmin, vmax=cmax) elif NORM_OPTS[idx] == "SymmetricLog10": return SymLogNorm(1e-8 if cmin is None else max(1e-8, abs(cmin)*1e-3), vmin=cmin, vmax=cmax) else: return Normalize(vmin=cmin, vmax=cmax) def clim_changed(self): """ Called when either the min or max is changed. Will unset the autoscale. """ self.autoscale.blockSignals(True) self.autoscale.setChecked(False) self.autoscale.blockSignals(False) self.update_clim() def update_clim(self): """ This will update the clim of the plot based on min, max, and autoscale """ if self.autoscale.isChecked(): data = self.colorbar.mappable.get_array() try: try: self.cmin_value = data[~data.mask].min() self.cmax_value = data[~data.mask].max() except AttributeError: self.cmin_value = np.nanmin(data) self.cmax_value = np.nanmax(data) except (ValueError, RuntimeWarning): # all values mask pass self.update_clim_text() else: if self.cmin.hasAcceptableInput(): cmin = float(self.cmin.text()) if cmin < self.cmax_value: self.cmin_value = cmin else: # reset values back self.update_clim_text() if self.cmax.hasAcceptableInput(): cmax = float(self.cmax.text()) if cmax > self.cmin_value: self.cmax_value = cmax else: #reset values back self.update_clim_text() self.colorbar.set_clim(self.cmin_value, self.cmax_value) self.redraw() def update_clim_text(self): """ Update displayed limit values based on stored ones """ self.cmin.setText("{:.4}".format(self.cmin_value)) self.cmax.setText("{:.4}".format(self.cmax_value)) def redraw(self): """ Redraws the colobar and emits signal to cause the parent to redraw """ self.colorbar.update_ticks() self.colorbar.draw_all() self.canvas.draw_idle() self.colorbarChanged.emit()
class ColorbarWidget(QWidget): colorbarChanged = Signal() # The parent should simply redraw their canvas def __init__(self, parent=None): super(ColorbarWidget, self).__init__(parent) self.setWindowTitle("Colorbar") self.setMaximumWidth(200) self.dval = QDoubleValidator() self.cmin = QLineEdit() self.cmin_value = 0 self.cmin.setMaximumWidth(100) self.cmin.editingFinished.connect(self.clim_changed) self.cmin_layout = QHBoxLayout() self.cmin_layout.addStretch() self.cmin_layout.addWidget(self.cmin) self.cmin_layout.addStretch() self.cmax = QLineEdit() self.cmax_value = 1 self.cmax.setMaximumWidth(100) self.cmax.editingFinished.connect(self.clim_changed) self.cmin.setValidator(self.dval) self.cmax.setValidator(self.dval) self.cmax_layout = QHBoxLayout() self.cmax_layout.addStretch() self.cmax_layout.addWidget(self.cmax) self.cmax_layout.addStretch() self.norm_layout = QHBoxLayout() self.norm = QComboBox() self.norm.addItems(NORM_OPTS) self.norm.currentIndexChanged.connect(self.norm_changed) self.powerscale = QLineEdit() self.powerscale_value = 2 self.powerscale.setText("2") self.powerscale.setValidator(QDoubleValidator(0.001,100,3)) self.powerscale.setMaximumWidth(50) self.powerscale.editingFinished.connect(self.norm_changed) self.powerscale.hide() self.powerscale_label = QLabel("n=") self.powerscale_label.hide() self.norm_layout.addStretch() self.norm_layout.addWidget(self.norm) self.norm_layout.addStretch() self.norm_layout.addWidget(self.powerscale_label) self.norm_layout.addWidget(self.powerscale) self.autoscale = QCheckBox("Autoscaling") self.autoscale.setChecked(True) self.autoscale.stateChanged.connect(self.update_clim) self.canvas = FigureCanvas(Figure()) if parent: # Set facecolor to match parent self.canvas.figure.set_facecolor(parent.palette().window().color().getRgbF()) self.ax = self.canvas.figure.add_axes([0.4,0.05,0.2,0.9]) # layout self.layout = QVBoxLayout(self) self.layout.addLayout(self.cmax_layout) self.layout.addWidget(self.canvas, stretch=1) self.layout.addLayout(self.cmin_layout) self.layout.addLayout(self.norm_layout) self.layout.addWidget(self.autoscale) def set_mappable(self, mappable): """ When a new plot is created this method should be called with the new mappable """ self.ax.clear() self.colorbar = Colorbar(ax=self.ax, mappable=mappable) self.cmin_value, self.cmax_value = self.colorbar.get_clim() self.update_clim_text() self.redraw() def norm_changed(self): """ Called when a different normalization is selected """ idx = self.norm.currentIndex() if NORM_OPTS[idx] == 'Power': self.powerscale.show() self.powerscale_label.show() else: self.powerscale.hide() self.powerscale_label.hide() self.colorbar.mappable.set_norm(self.get_norm()) self.colorbarChanged.emit() def get_norm(self): """ This will create a matplotlib.colors.Normalize from selected idx, limits and powerscale """ idx = self.norm.currentIndex() if self.autoscale.isChecked(): cmin = cmax = None else: cmin = self.cmin_value cmax = self.cmax_value if NORM_OPTS[idx] == 'Power': if self.powerscale.hasAcceptableInput(): self.powerscale_value = float(self.powerscale.text()) return PowerNorm(gamma=self.powerscale_value, vmin=cmin, vmax=cmax) elif NORM_OPTS[idx] == "SymmetricLog10": return SymLogNorm(1e-8 if cmin is None else max(1e-8, abs(cmin)*1e-3), vmin=cmin, vmax=cmax) else: return Normalize(vmin=cmin, vmax=cmax) def clim_changed(self): """ Called when either the min or max is changed. Will unset the autoscale. """ self.autoscale.blockSignals(True) self.autoscale.setChecked(False) self.autoscale.blockSignals(False) self.update_clim() def update_clim(self): """ This will update the clim of the plot based on min, max, and autoscale """ if self.autoscale.isChecked(): data = self.colorbar.mappable.get_array() try: try: self.cmin_value = data[~data.mask].min() self.cmax_value = data[~data.mask].max() except AttributeError: self.cmin_value = np.nanmin(data) self.cmax_value = np.nanmax(data) except (ValueError, RuntimeWarning): # all values mask pass self.update_clim_text() else: if self.cmin.hasAcceptableInput(): self.cmin_value = float(self.cmin.text()) if self.cmax.hasAcceptableInput(): self.cmax_value = float(self.cmax.text()) self.colorbar.set_clim(self.cmin_value, self.cmax_value) self.redraw() def update_clim_text(self): """ Update displayed limit values based on stored ones """ self.cmin.setText("{:.4}".format(self.cmin_value)) self.cmax.setText("{:.4}".format(self.cmax_value)) def redraw(self): """ Redraws the colobar and emits signal to cause the parent to redraw """ self.colorbar.update_ticks() self.colorbar.draw_all() self.canvas.draw_idle() self.colorbarChanged.emit()
class ColorbarWidget(QWidget): colorbarChanged = Signal() # The parent should simply redraw their canvas scaleNormChanged = Signal() # register additional color maps from file register_customized_colormaps() # create the list cmap_list = sorted( [cmap for cmap in cm.cmap_d.keys() if not cmap.endswith('_r')]) def __init__(self, parent=None, default_norm_scale=None): """ :param default_scale: None uses linear, else either a string or tuple(string, other arguments), e.g. tuple('Power', exponent) """ super(ColorbarWidget, self).__init__(parent) self.setWindowTitle("Colorbar") self.setMaximumWidth(100) self.cmap = QComboBox() self.cmap.addItems(self.cmap_list) self.cmap.currentIndexChanged.connect(self.cmap_index_changed) self.crev = QCheckBox('Reverse') self.crev.stateChanged.connect(self.crev_checked_changed) self.cmin = QLineEdit() self.cmin_value = 0 self.cmin.setMaximumWidth(100) self.cmin.editingFinished.connect(self.clim_changed) self.cmin_layout = QHBoxLayout() self.cmin_layout.addStretch() self.cmin_layout.addWidget(self.cmin) self.cmin_layout.addStretch() self.linear_validator = QDoubleValidator(parent=self) self.log_validator = QDoubleValidator(MIN_LOG_VALUE, sys.float_info.max, 3, self) self.cmax = QLineEdit() self.cmax_value = 1 self.cmax.setMaximumWidth(100) self.cmax.editingFinished.connect(self.clim_changed) self.cmax_layout = QHBoxLayout() self.cmax_layout.addStretch() self.cmax_layout.addWidget(self.cmax) self.cmax_layout.addStretch() norm_scale = 'Linear' powerscale_value = 2 if default_norm_scale in NORM_OPTS: norm_scale = default_norm_scale if isinstance(default_norm_scale, tuple) and default_norm_scale[0] in NORM_OPTS: norm_scale = default_norm_scale[0] if norm_scale == 'Power': powerscale_value = float(default_norm_scale[1]) self.norm_layout = QHBoxLayout() self.norm = QComboBox() self.norm.addItems(NORM_OPTS) self.norm.setCurrentText(norm_scale) self.norm.currentIndexChanged.connect(self.norm_changed) self.update_clim_validator() self.powerscale = QLineEdit() self.powerscale_value = powerscale_value self.powerscale.setText(str(powerscale_value)) self.powerscale.setValidator(QDoubleValidator(0.001, 100, 3)) self.powerscale.setMaximumWidth(50) self.powerscale.editingFinished.connect(self.norm_changed) self.powerscale_label = QLabel("n=") if norm_scale != 'Power': self.powerscale.hide() self.powerscale_label.hide() self.norm_layout.addStretch() self.norm_layout.addWidget(self.norm) self.norm_layout.addStretch() self.norm_layout.addWidget(self.powerscale_label) self.norm_layout.addWidget(self.powerscale) self.autoscale = QCheckBox("Autoscaling") self.autoscale.setChecked(True) self.autoscale.stateChanged.connect(self.update_clim) self.canvas = FigureCanvas(Figure()) if parent: # Set facecolor to match parent self.canvas.figure.set_facecolor( parent.palette().window().color().getRgbF()) self.ax = self.canvas.figure.add_axes([0.0, 0.02, 0.2, 0.97]) # layout self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(2) self.layout.addWidget(self.cmap) self.layout.addWidget(self.crev) self.layout.addLayout(self.cmax_layout) self.layout.addWidget(self.canvas, stretch=1) self.layout.addLayout(self.cmin_layout) self.layout.addLayout(self.norm_layout) self.layout.addWidget(self.autoscale) def set_mappable(self, mappable): """ When a new plot is created this method should be called with the new mappable """ # sanity check the mappable mappable = self._validate_mappable(mappable) self.ax.clear() try: # Use current cmap cmap = get_current_cmap(self.colorbar) except AttributeError: # else use default cmap = ConfigService.getString("plots.images.Colormap") self.colorbar = Colorbar(ax=self.ax, mappable=mappable) self.cmin_value, self.cmax_value = mappable.get_clim() self.update_clim_text() self.cmap_changed(cmap, False) mappable_cmap = get_current_cmap(mappable) if mappable_cmap.name.endswith('_r'): self.crev.setChecked(True) else: self.crev.setChecked(False) self.cmap.setCurrentIndex( self.cmap_list.index(mappable_cmap.name.replace('_r', ''))) self.redraw() def cmap_index_changed(self): self.cmap_changed(self.cmap.currentText(), self.crev.isChecked()) def crev_checked_changed(self): self.cmap_changed(self.cmap.currentText(), self.crev.isChecked()) def cmap_changed(self, name, rev): if rev: name += '_r' self.colorbar.mappable.set_cmap(name) if mpl_version_info() >= (3, 1): self.colorbar.update_normal(self.colorbar.mappable) else: self.colorbar.set_cmap(name) self.redraw() def mappable_changed(self): """ Updates the colormap and min/max values of the colorbar when the plot changes via settings. """ mappable_cmap = get_current_cmap(self.colorbar.mappable) low, high = self.colorbar.mappable.get_clim() self.cmin_value = low self.cmax_value = high self.update_clim_text() self.cmap.setCurrentIndex( sorted(cm.cmap_d.keys()).index(mappable_cmap.name)) self.redraw() def norm_changed(self): """ Called when a different normalization is selected """ idx = self.norm.currentIndex() if NORM_OPTS[idx] == 'Power': self.powerscale.show() self.powerscale_label.show() else: self.powerscale.hide() self.powerscale_label.hide() self.colorbar.mappable.set_norm(self.get_norm()) self.set_mappable(self.colorbar.mappable) self.update_clim_validator() self.scaleNormChanged.emit() def get_norm(self): """ This will create a matplotlib.colors.Normalize from selected idx, limits and powerscale """ idx = self.norm.currentIndex() if self.autoscale.isChecked(): cmin = cmax = None else: cmin = self.cmin_value cmax = self.cmax_value if NORM_OPTS[idx] == 'Power': if self.powerscale.hasAcceptableInput(): self.powerscale_value = float(self.powerscale.text()) return PowerNorm(gamma=self.powerscale_value, vmin=cmin, vmax=cmax) elif NORM_OPTS[idx] == "SymmetricLog10": return SymLogNorm( 1e-8 if cmin is None else max(1e-8, abs(cmin) * 1e-3), vmin=cmin, vmax=cmax) elif NORM_OPTS[idx] == "Log": cmin = MIN_LOG_VALUE if cmin is not None and cmin <= 0 else cmin return LogNorm(vmin=cmin, vmax=cmax) else: return Normalize(vmin=cmin, vmax=cmax) def get_colorbar_scale(self): norm = self.colorbar.norm scale = 'linear' kwargs = {} if isinstance(norm, SymLogNorm): scale = 'symlog' elif isinstance(norm, LogNorm): scale = 'log' elif isinstance(norm, PowerNorm): scale = 'function' kwargs = { 'functions': (lambda x: np.power(x, norm.gamma), lambda x: np.power(x, 1 / norm.gamma)) } return scale, kwargs def clim_changed(self): """ Called when either the min or max is changed. Will unset the autoscale. """ self.autoscale.blockSignals(True) self.autoscale.setChecked(False) self.autoscale.blockSignals(False) self.update_clim() def update_clim(self): """ This will update the clim of the plot based on min, max, and autoscale """ if self.autoscale.isChecked(): self._autoscale_clim() else: self._manual_clim() self.colorbar.mappable.set_clim(self.cmin_value, self.cmax_value) self.redraw() def update_clim_text(self): """ Update displayed limit values based on stored ones """ self.cmin.setText("{:.4}".format(self.cmin_value)) self.cmax.setText("{:.4}".format(self.cmax_value)) def redraw(self): """ Redraws the colobar and emits signal to cause the parent to redraw """ self.colorbar.update_ticks() self.colorbar.draw_all() self.canvas.draw_idle() self.colorbarChanged.emit() def update_clim_validator(self): if NORM_OPTS[self.norm.currentIndex()] == "Log": self.cmin.setValidator(self.log_validator) self.cmax.setValidator(self.log_validator) else: self.cmin.setValidator(self.linear_validator) self.cmax.setValidator(self.linear_validator) def _autoscale_clim(self): """Update stored colorbar limits The new limits are found from the colobar data """ data = self.colorbar.mappable.get_array() norm = NORM_OPTS[self.norm.currentIndex()] try: try: masked_data = data[~data.mask] # use the smallest positive value as vmin when using log scale, # matplotlib will take care of the data skipping part. masked_data = masked_data[ data > 0] if norm == "Log" else masked_data self.cmin_value = masked_data.min() self.cmax_value = masked_data.max() except (AttributeError, IndexError): data = data[np.nonzero(data)] if norm == "Log" else data self.cmin_value = np.nanmin(data) self.cmax_value = np.nanmax(data) except (ValueError, RuntimeWarning): # all values mask pass self.update_clim_text() def _manual_clim(self): """Update stored colorbar limits The new limits are found from user input""" if self.cmin.hasAcceptableInput(): cmin = float(self.cmin.text()) if cmin < self.cmax_value: self.cmin_value = cmin else: # reset values back self.update_clim_text() if self.cmax.hasAcceptableInput(): cmax = float(self.cmax.text()) if cmax > self.cmin_value: self.cmax_value = cmax else: # reset values back self.update_clim_text() def _create_linear_normalize_object(self): if self.autoscale.isChecked(): cmin = cmax = None else: cmin = self.cmin_value cmax = self.cmax_value return Normalize(vmin=cmin, vmax=cmax) def _validate_mappable(self, mappable): """Disable the Log option if no positive value can be found from given data (image)""" index = NORM_OPTS.index("Log") if mappable.get_array() is not None: if np.all(mappable.get_array() <= 0): self.norm.model().item(index, 0).setEnabled(False) self.norm.setItemData( index, "Log scale is disabled for non-positive data", Qt.ToolTipRole) if isinstance(mappable.norm, LogNorm): mappable.norm = self._create_linear_normalize_object() self.norm.blockSignals(True) self.norm.setCurrentIndex(0) self.norm.blockSignals(False) else: if not self.norm.model().item(index, 0).isEnabled(): self.norm.model().item(index, 0).setEnabled(True) self.norm.setItemData(index, "", Qt.ToolTipRole) return mappable
def insert_row(self, row=-1, title='', sample_runs='', sample_mass_density='N/A', sample_chemical_formula='N/A', packing_fraction='N/A', align_and_focus_args={}, sample_placzek_arguments={}, normalization_placzek_arguments={}): self.table_ui.insertRow(row) self.set_row_height(row, COLUMN_DEFAULT_HEIGHT) _list_ui_to_unlock = [self.table_ui] _dimension_widgets = {'label': None, 'value': 'N/A', 'units': None} _full_dimension_widgets = {'radius': copy.deepcopy(_dimension_widgets), 'radius2': copy.deepcopy(_dimension_widgets), 'height': copy.deepcopy(_dimension_widgets)} _text_button = {'text': None, 'button': None} _mass_density_options = {'value': "N/A", "selected": False} _mass_density_infos = {'number_density': copy.deepcopy(_mass_density_options), 'mass_density': copy.deepcopy(_mass_density_options), 'mass': copy.deepcopy(_mass_density_options), 'molecular_mass': np.NaN, 'total_number_of_atoms': np.NaN, } _material_infos = {'mantid_format': None, 'addie_format': None} _mass_density_infos['mass_density']["selected"] = True _master_table_row_ui = {'active': None, 'title': None, 'sample': {'runs': None, 'background': {'runs': None, 'background': None, }, 'material': copy.deepcopy(_text_button), 'material_infos': copy.deepcopy(_material_infos), 'mass_density': copy.deepcopy(_text_button), 'mass_density_infos': copy.deepcopy(_mass_density_infos), 'packing_fraction': None, 'geometry': copy.deepcopy(_full_dimension_widgets), 'shape': None, 'abs_correction': None, 'mult_scat_correction': None, 'inelastic_correction': None, 'placzek_button': None, 'placzek_infos': None, }, 'normalization': {'runs': None, 'background': {'runs': None, 'background': None, }, 'material': copy.deepcopy(_text_button), 'material_infos': copy.deepcopy(_material_infos), 'mass_density': copy.deepcopy(_text_button), 'mass_density_infos': copy.deepcopy(_mass_density_infos), 'packing_fraction': None, 'geometry': copy.deepcopy(_full_dimension_widgets), 'shape': None, 'abs_correction': None, 'mult_scat_correction': None, 'inelastic_correction': None, 'placzek_button': None, 'placzek_infos': None, }, 'align_and_focus_args_button': None, 'align_and_focus_args_infos': {}, } random_key = self.generate_random_key() self.key = random_key # block main table events self.table_ui.blockSignals(True) # column 0 (active or not checkBox) _layout = QHBoxLayout() _widget = QCheckBox() _widget.setCheckState(QtCore.Qt.Checked) _widget.setEnabled(True) _master_table_row_ui['active'] = _widget _spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer) _layout.addWidget(_widget) _spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer) _layout.addStretch() _new_widget = QWidget() _new_widget.setLayout(_layout) _widget.stateChanged.connect(lambda state=0, key=random_key: self.main_window.master_table_select_state_changed(state, key)) column = 0 self.table_ui.setCellWidget(row, column, _new_widget) # sample column += 1 # column 1 - title _item = QTableWidgetItem(title) _master_table_row_ui['title'] = _item self.table_ui.setItem(row, column, _item) # column 2 - sample runs column += 1 _item = QTableWidgetItem(sample_runs) _master_table_row_ui['sample']['runs'] = _item self.table_ui.setItem(row, column, _item) # column 3 - background runs column += 1 _item = QTableWidgetItem("") _master_table_row_ui['sample']['background']['runs'] = _item self.table_ui.setItem(row, column, _item) # column 4 - background background column += 1 _item = QTableWidgetItem("") _master_table_row_ui['sample']['background']['background'] = _item self.table_ui.setItem(row, column, _item) # column 5 - material (chemical formula) column += 1 clean_sample_chemical_formula = format_chemical_formula_equation(sample_chemical_formula) _material_text = QLineEdit(clean_sample_chemical_formula) _material_text = QLabel(clean_sample_chemical_formula) _material_button = QPushButton("...") _material_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _material_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _material_button.pressed.connect(lambda key=random_key: self.main_window.master_table_sample_material_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_material_text) _verti_layout.addWidget(_material_button) _material_widget = QWidget() _material_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _material_widget) _master_table_row_ui['sample']['material']['text'] = _material_text _master_table_row_ui['sample']['material']['button'] = _material_button # column 6 - mass density column += 1 _mass_text = QLineEdit(sample_mass_density) _mass_text.returnPressed.connect(lambda key=random_key: self.main_window.master_table_sample_mass_density_line_edit_entered(key)) _mass_units = QLabel("g/cc") _top_widget = QWidget() _top_layout = QHBoxLayout() _top_layout.addWidget(_mass_text) _top_layout.addWidget(_mass_units) _top_widget.setLayout(_top_layout) _mass_button = QPushButton("...") _mass_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _mass_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _mass_button.pressed.connect(lambda key=random_key: self.main_window.master_table_sample_mass_density_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_top_widget) _verti_layout.addWidget(_mass_button) _mass_widget = QWidget() _mass_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _mass_widget) _master_table_row_ui['sample']['mass_density']['text'] = _mass_text _master_table_row_ui['sample']['mass_density']['button'] = _mass_button # column 7 - packing fraction column += 1 if packing_fraction == "N/A": packing_fraction = "{}".format(self.main_window.packing_fraction) _item = QTableWidgetItem(packing_fraction) _master_table_row_ui['sample']['packing_fraction'] = _item self.table_ui.setItem(row, column, _item) # column 8 - shape (cylindrical or spherical) column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _shape_default_index = 0 _widget.currentIndexChanged.connect(lambda index=_shape_default_index, key=random_key: self.main_window.master_table_sample_shape_changed(index, key)) _list_ui_to_unlock.append(_widget) _widget.blockSignals(True) _widget.addItem("cylindrical") _widget.addItem("spherical") _widget.addItem("hollow cylinder") _master_table_row_ui['sample']['shape'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 9 - dimensions column += 1 # layout 1 _grid_layout = QGridLayout() _label1 = QLabel("Radius:") _grid_layout.addWidget(_label1, 1, 0) _value1 = QLabel("N/A") _grid_layout.addWidget(_value1, 1, 1) _dim1 = QLabel("cm") _grid_layout.addWidget(_dim1, 1, 2) _label2 = QLabel("Radius:") _label2.setVisible(False) _grid_layout.addWidget(_label2, 2, 0) _value2 = QLabel("N/A") _value2.setVisible(False) _grid_layout.addWidget(_value2, 2, 1) _dim2 = QLabel("cm") _dim2.setVisible(False) _grid_layout.addWidget(_dim2, 2, 2) _label3 = QLabel("Height:") _grid_layout.addWidget(_label3, 3, 0) _value3 = QLabel("N/A") _grid_layout.addWidget(_value3, 3, 1) _dim3 = QLabel("cm") _grid_layout.addWidget(_dim3, 3, 2) _master_table_row_ui['sample']['geometry']['radius']['value'] = _value1 _master_table_row_ui['sample']['geometry']['radius2']['value'] = _value2 _master_table_row_ui['sample']['geometry']['height']['value'] = _value3 _master_table_row_ui['sample']['geometry']['radius']['label'] = _label1 _master_table_row_ui['sample']['geometry']['radius2']['label'] = _label2 _master_table_row_ui['sample']['geometry']['height']['label'] = _label3 _master_table_row_ui['sample']['geometry']['radius']['units'] = _dim1 _master_table_row_ui['sample']['geometry']['radius2']['units'] = _dim2 _master_table_row_ui['sample']['geometry']['height']['units'] = _dim3 _geometry_widget = QWidget() _geometry_widget.setLayout(_grid_layout) _set_dimensions_button = QPushButton("...") _set_dimensions_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _set_dimensions_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_geometry_widget) _verti_layout.addWidget(_set_dimensions_button) _verti_widget = QWidget() _verti_widget.setLayout(_verti_layout) _set_dimensions_button.pressed.connect(lambda key=random_key: self.main_window.master_table_sample_dimensions_setter_button_pressed(key)) self.table_ui.setCellWidget(row, column, _verti_widget) # column 10 - abs. correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _shape_default_value = 0 list_abs_correction = self.get_absorption_correction_list(shape=_shape_default_value) _widget.currentIndexChanged.connect(lambda value=list_abs_correction[0], key = random_key: self.main_window.master_table_sample_abs_correction_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_abs_correction: _widget.addItem(_item) _master_table_row_ui['sample']['abs_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 11 - multi. scattering correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() list_multi_scat_correction = self.get_multi_scat_correction_list(shape=_shape_default_value) _widget.currentIndexChanged.connect(lambda value=list_multi_scat_correction[0], key=random_key: self.main_window.master_table_sample_multi_scattering_correction_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_multi_scat_correction: _widget.addItem(_item) _master_table_row_ui['sample']['mult_scat_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 12 - inelastic correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget1 = QComboBox() _widget1.setMinimumHeight(20) list_inelastic_correction = self.get_inelastic_scattering_list(shape=_shape_default_value) for _item in list_inelastic_correction: _widget1.addItem(_item) _master_table_row_ui['sample']['inelastic_correction'] = _widget1 _button = QPushButton("...") _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.pressed.connect(lambda key=random_key: self.main_window.master_table_sample_placzek_button_pressed(key)) _master_table_row_ui['sample']['placzek_button'] = _button _button.setVisible(False) _master_table_row_ui['sample']['placzek_button'] = _button _layout.addWidget(_widget1) _layout.addWidget(_button) _widget = QWidget() _widget.setLayout(_layout) _default_value = 'None' _widget1.currentIndexChanged.connect(lambda value=_default_value, key=random_key: self.main_window.master_table_sample_inelastic_correction_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) self.table_ui.setCellWidget(row, column, _widget) # save default placzek settings _sample_formated_placzek_default = self.formated_placzek_default(sample_placzek_arguments) _master_table_row_ui['sample']['placzek_infos'] = _sample_formated_placzek_default ## normalization # column 13 - sample runs column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 14 - background runs column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 15 - background background column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 16 - material (chemical formula) column += 1 #_material_text = QLineEdit("") _material_text = QLabel("N/A") _material_button = QPushButton("...") _material_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _material_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _material_button.pressed.connect(lambda key=random_key: self.main_window.master_table_normalization_material_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_material_text) _verti_layout.addWidget(_material_button) _material_widget = QWidget() _material_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _material_widget) _master_table_row_ui['normalization']['material']['text'] = _material_text _master_table_row_ui['normalization']['material']['button'] = _material_button # column 17 - mass density column += 1 _mass_text = QLineEdit("N/A") _mass_text.returnPressed.connect(lambda key=random_key: self.main_window.master_table_normalization_mass_density_line_edit_entered(key)) _mass_units = QLabel("g/cc") _top_widget = QWidget() _top_layout = QHBoxLayout() _top_layout.addWidget(_mass_text) _top_layout.addWidget(_mass_units) _top_widget.setLayout(_top_layout) _mass_button = QPushButton("...") _mass_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _mass_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _mass_button.pressed.connect(lambda key=random_key: self.main_window.master_table_normalization_mass_density_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_top_widget) _verti_layout.addWidget(_mass_button) _mass_widget = QWidget() _mass_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _mass_widget) _master_table_row_ui['normalization']['mass_density']['text'] = _mass_text _master_table_row_ui['normalization']['mass_density']['button'] = _mass_button # column 18 - packing fraction column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 19 - shape (cylindrical or spherical) column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect(lambda value=_shape_default_value, key=random_key: self.main_window.master_table_normalization_shape_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) _widget.addItem("cylindrical") _widget.addItem("spherical") _widget.addItem("hollow cylinder") _master_table_row_ui['normalization']['shape'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 20 - dimensions column += 1 # layout 1 _grid_layout = QGridLayout() _label1 = QLabel("Radius:") _grid_layout.addWidget(_label1, 1, 0) _value1 = QLabel("N/A") _grid_layout.addWidget(_value1, 1, 1) _dim1 = QLabel("cm") _grid_layout.addWidget(_dim1, 1, 2) _label2 = QLabel("Radius:") _label2.setVisible(False) _grid_layout.addWidget(_label2, 2, 0) _value2 = QLabel("N/A") _value2.setVisible(False) _grid_layout.addWidget(_value2, 2, 1) _dim2 = QLabel("cm") _dim2.setVisible(False) _grid_layout.addWidget(_dim2, 2, 2) _label3 = QLabel("Height:") _grid_layout.addWidget(_label3, 3, 0) _value3 = QLabel("N/A") _grid_layout.addWidget(_value3, 3, 1) _dim3 = QLabel("cm") _grid_layout.addWidget(_dim3, 3, 2) _master_table_row_ui['normalization']['geometry']['radius']['value'] = _value1 _master_table_row_ui['normalization']['geometry']['radius2']['value'] = _value2 _master_table_row_ui['normalization']['geometry']['height']['value'] = _value3 _master_table_row_ui['normalization']['geometry']['radius']['label'] = _label1 _master_table_row_ui['normalization']['geometry']['radius2']['label'] = _label2 _master_table_row_ui['normalization']['geometry']['height']['label'] = _label3 _master_table_row_ui['normalization']['geometry']['radius']['units'] = _dim1 _master_table_row_ui['normalization']['geometry']['radius2']['units'] = _dim2 _master_table_row_ui['normalization']['geometry']['height']['units'] = _dim3 _geometry_widget = QWidget() _geometry_widget.setLayout(_grid_layout) _set_dimensions_button = QPushButton("...") _set_dimensions_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _set_dimensions_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_geometry_widget) _verti_layout.addWidget(_set_dimensions_button) _verti_widget = QWidget() _verti_widget.setLayout(_verti_layout) _set_dimensions_button.pressed.connect(lambda key=random_key: self.main_window.master_table_normalization_dimensions_setter_button_pressed(key)) # noqa self.table_ui.setCellWidget(row, column, _verti_widget) # column 21 - abs. correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect(lambda value=list_abs_correction[0], key=random_key: self.main_window.master_table_normalization_abs_correction_changed(value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_abs_correction: _widget.addItem(_item) _widget.setCurrentIndex(0) _master_table_row_ui['normalization']['abs_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 24 - multi. scattering correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect(lambda value=list_multi_scat_correction[0], key=random_key: self.main_window.master_table_normalization_multi_scattering_correction_changed(value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_multi_scat_correction: _widget.addItem(_item) _widget.setCurrentIndex(0) _master_table_row_ui['normalization']['mult_scat_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 22 - inelastic correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget1 = QComboBox() _widget1.setMinimumHeight(20) list_inelastic_correction = self.get_inelastic_scattering_list(shape=_shape_default_value) for _item in list_inelastic_correction: _widget1.addItem(_item) _widget1.setCurrentIndex(0) _master_table_row_ui['normalization']['inelastic_correction'] = _widget1 _button = QPushButton("...") _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.pressed.connect(lambda key=random_key: self.main_window.master_table_normalization_placzek_button_pressed(key)) _master_table_row_ui['normalization']['placzek_button'] = _button _button.setVisible(False) _layout.addWidget(_widget1) _layout.addWidget(_button) _widget = QWidget() _widget.setLayout(_layout) _default_value = 'None' _widget1.currentIndexChanged.connect( lambda value=_default_value, key=random_key: self.main_window.master_table_normalization_inelastic_correction_changed(value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) self.table_ui.setCellWidget(row, column, _widget) # automatically populate placzek infos with default values _norm_formated_placzek_default = self.formated_placzek_default(normalization_placzek_arguments) _master_table_row_ui['normalization']['placzek_infos'] = _norm_formated_placzek_default # column 23 - key/value pair column += 1 _layout = QHBoxLayout() _spacer_kv1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer_kv1) _button = QPushButton("...") _layout.addWidget(_button) _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.pressed.connect(lambda key=random_key: self.main_window.master_table_keyvalue_button_pressed(key)) _new_widget = QWidget() _new_widget.setLayout(_layout) self.table_ui.setCellWidget(row, column, _new_widget) _master_table_row_ui['align_and_focus_args_button'] = _button _spacer_kv2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer_kv2) _layout.addStretch() _master_table_row_ui['align_and_focus_args_infos'] = align_and_focus_args ## recap self.main_window.master_table_list_ui[random_key] = _master_table_row_ui self.unlock_signals_ui(list_ui=_list_ui_to_unlock) self.main_window.check_status_of_right_click_buttons()
def insert_row(self, row=-1, title='', sample_runs='', sample_mass_density='N/A', sample_chemical_formula='N/A', packing_fraction='N/A', align_and_focus_args={}, sample_placzek_arguments={}, normalization_placzek_arguments={}): self.table_ui.insertRow(row) self.set_row_height(row, COLUMN_DEFAULT_HEIGHT) _list_ui_to_unlock = [self.table_ui] _dimension_widgets = {'label': None, 'value': 'N/A', 'units': None} _full_dimension_widgets = { 'radius': copy.deepcopy(_dimension_widgets), 'radius2': copy.deepcopy(_dimension_widgets), 'height': copy.deepcopy(_dimension_widgets) } _text_button = {'text': None, 'button': None} _mass_density_options = {'value': "N/A", "selected": False} _mass_density_infos = { 'number_density': copy.deepcopy(_mass_density_options), 'mass_density': copy.deepcopy(_mass_density_options), 'mass': copy.deepcopy(_mass_density_options), 'molecular_mass': np.NaN, 'total_number_of_atoms': np.NaN, } _material_infos = {'mantid_format': None, 'addie_format': None} _mass_density_infos['mass_density']["selected"] = True _master_table_row_ui = { 'active': None, 'title': None, 'sample': { 'runs': None, 'background': { 'runs': None, 'background': None, }, 'material': copy.deepcopy(_text_button), 'material_infos': copy.deepcopy(_material_infos), 'mass_density': copy.deepcopy(_text_button), 'mass_density_infos': copy.deepcopy(_mass_density_infos), 'packing_fraction': None, 'geometry': copy.deepcopy(_full_dimension_widgets), 'shape': None, 'abs_correction': None, 'mult_scat_correction': None, 'inelastic_correction': None, 'placzek_button': None, 'placzek_infos': None, }, 'normalization': { 'runs': None, 'background': { 'runs': None, 'background': None, }, 'material': copy.deepcopy(_text_button), 'material_infos': copy.deepcopy(_material_infos), 'mass_density': copy.deepcopy(_text_button), 'mass_density_infos': copy.deepcopy(_mass_density_infos), 'packing_fraction': None, 'geometry': copy.deepcopy(_full_dimension_widgets), 'shape': None, 'abs_correction': None, 'mult_scat_correction': None, 'inelastic_correction': None, 'placzek_button': None, 'placzek_infos': None, }, 'align_and_focus_args_button': None, 'align_and_focus_args_infos': {}, 'align_and_focus_args_use_global': True, } random_key = self.generate_random_key() self.key = random_key # block main table events self.table_ui.blockSignals(True) # column 0 (active or not checkBox) _layout = QHBoxLayout() _widget = QCheckBox() _widget.setCheckState(QtCore.Qt.Checked) _widget.setEnabled(True) _master_table_row_ui['active'] = _widget _spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer) _layout.addWidget(_widget) _spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer) _layout.addStretch() _new_widget = QWidget() _new_widget.setLayout(_layout) _widget.stateChanged.connect( lambda state=0, key=random_key: self.main_window. master_table_select_state_changed(state, key)) column = 0 self.table_ui.setCellWidget(row, column, _new_widget) # sample column += 1 # column 1 - title _item = QTableWidgetItem(title) _master_table_row_ui['title'] = _item self.table_ui.setItem(row, column, _item) # column 2 - sample runs column += 1 _item = QTableWidgetItem(sample_runs) _master_table_row_ui['sample']['runs'] = _item self.table_ui.setItem(row, column, _item) # column 3 - background runs column += 1 _item = QTableWidgetItem("") _master_table_row_ui['sample']['background']['runs'] = _item self.table_ui.setItem(row, column, _item) # column 4 - background background column += 1 _item = QTableWidgetItem("") _master_table_row_ui['sample']['background']['background'] = _item self.table_ui.setItem(row, column, _item) # column 5 - material (chemical formula) column += 1 clean_sample_chemical_formula = format_chemical_formula_equation( sample_chemical_formula) _material_text = QLineEdit(clean_sample_chemical_formula) _material_text = QLabel(clean_sample_chemical_formula) _material_button = QPushButton("...") _material_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _material_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _material_button.pressed.connect( lambda key=random_key: self.main_window. master_table_sample_material_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_material_text) _verti_layout.addWidget(_material_button) _material_widget = QWidget() _material_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _material_widget) _master_table_row_ui['sample']['material']['text'] = _material_text _master_table_row_ui['sample']['material']['button'] = _material_button # column 6 - mass density column += 1 _mass_text = QLineEdit(sample_mass_density) _mass_text.returnPressed.connect( lambda key=random_key: self.main_window. master_table_sample_mass_density_line_edit_entered(key)) _mass_units = QLabel("g/cc") _top_widget = QWidget() _top_layout = QHBoxLayout() _top_layout.addWidget(_mass_text) _top_layout.addWidget(_mass_units) _top_widget.setLayout(_top_layout) _mass_button = QPushButton("...") _mass_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _mass_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _mass_button.pressed.connect( lambda key=random_key: self.main_window. master_table_sample_mass_density_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_top_widget) _verti_layout.addWidget(_mass_button) _mass_widget = QWidget() _mass_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _mass_widget) _master_table_row_ui['sample']['mass_density']['text'] = _mass_text _master_table_row_ui['sample']['mass_density']['button'] = _mass_button # column 7 - packing fraction column += 1 if packing_fraction == "N/A": packing_fraction = "{}".format(self.main_window.packing_fraction) _item = QTableWidgetItem(packing_fraction) _master_table_row_ui['sample']['packing_fraction'] = _item self.table_ui.setItem(row, column, _item) # column 8 - shape (cylinder or sphere) column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _shape_default_index = 0 _widget.currentIndexChanged.connect( lambda index=_shape_default_index, key=random_key: self.main_window .master_table_sample_shape_changed(index, key)) _list_ui_to_unlock.append(_widget) _widget.blockSignals(True) _widget.addItem("Cylinder") _widget.addItem("Sphere") _widget.addItem("Hollow Cylinder") _master_table_row_ui['sample']['shape'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 9 - dimensions column += 1 # layout 1 _grid_layout = QGridLayout() _label1 = QLabel("Radius:") _grid_layout.addWidget(_label1, 1, 0) _value1 = QLabel("N/A") _grid_layout.addWidget(_value1, 1, 1) _dim1 = QLabel("cm") _grid_layout.addWidget(_dim1, 1, 2) _label2 = QLabel("Radius:") _label2.setVisible(False) _grid_layout.addWidget(_label2, 2, 0) _value2 = QLabel("N/A") _value2.setVisible(False) _grid_layout.addWidget(_value2, 2, 1) _dim2 = QLabel("cm") _dim2.setVisible(False) _grid_layout.addWidget(_dim2, 2, 2) _label3 = QLabel("Height:") _grid_layout.addWidget(_label3, 3, 0) _value3 = QLabel("N/A") _grid_layout.addWidget(_value3, 3, 1) _dim3 = QLabel("cm") _grid_layout.addWidget(_dim3, 3, 2) _master_table_row_ui['sample']['geometry']['radius']['value'] = _value1 _master_table_row_ui['sample']['geometry']['radius2'][ 'value'] = _value2 _master_table_row_ui['sample']['geometry']['height']['value'] = _value3 _master_table_row_ui['sample']['geometry']['radius']['label'] = _label1 _master_table_row_ui['sample']['geometry']['radius2'][ 'label'] = _label2 _master_table_row_ui['sample']['geometry']['height']['label'] = _label3 _master_table_row_ui['sample']['geometry']['radius']['units'] = _dim1 _master_table_row_ui['sample']['geometry']['radius2']['units'] = _dim2 _master_table_row_ui['sample']['geometry']['height']['units'] = _dim3 _geometry_widget = QWidget() _geometry_widget.setLayout(_grid_layout) _set_dimensions_button = QPushButton("...") _set_dimensions_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _set_dimensions_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_geometry_widget) _verti_layout.addWidget(_set_dimensions_button) _verti_widget = QWidget() _verti_widget.setLayout(_verti_layout) _set_dimensions_button.pressed.connect( lambda key=random_key: self.main_window. master_table_sample_dimensions_setter_button_pressed(key)) self.table_ui.setCellWidget(row, column, _verti_widget) # column 10 - abs. correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _shape_default_value = 0 list_abs_correction = self.get_absorption_correction_list( shape=_shape_default_value) _widget.currentIndexChanged.connect( lambda value=list_abs_correction[0], key=random_key: self. main_window.master_table_sample_abs_correction_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_abs_correction: _widget.addItem(_item) _master_table_row_ui['sample']['abs_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 11 - multi. scattering correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() list_multi_scat_correction = self.get_multi_scat_correction_list( shape=_shape_default_value) _widget.currentIndexChanged.connect( lambda value=list_multi_scat_correction[ 0], key=random_key: self.main_window. master_table_sample_multi_scattering_correction_changed( value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_multi_scat_correction: _widget.addItem(_item) _master_table_row_ui['sample']['mult_scat_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 12 - inelastic correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget1 = QComboBox() _widget1.setMinimumHeight(20) list_inelastic_correction = self.get_inelastic_scattering_list( shape=_shape_default_value) for _item in list_inelastic_correction: _widget1.addItem(_item) _master_table_row_ui['sample']['inelastic_correction'] = _widget1 _button = QPushButton("...") _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.pressed.connect( lambda key=random_key: self.main_window. master_table_sample_placzek_button_pressed(key)) _master_table_row_ui['sample']['placzek_button'] = _button _button.setVisible(False) _master_table_row_ui['sample']['placzek_button'] = _button _layout.addWidget(_widget1) _layout.addWidget(_button) _widget = QWidget() _widget.setLayout(_layout) _default_value = 'None' _widget1.currentIndexChanged.connect( lambda value=_default_value, key=random_key: self.main_window. master_table_sample_inelastic_correction_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) self.table_ui.setCellWidget(row, column, _widget) # save default placzek settings _sample_formated_placzek_default = self.formated_placzek_default( sample_placzek_arguments) _master_table_row_ui['sample'][ 'placzek_infos'] = _sample_formated_placzek_default ## normalization # column 13 - sample runs column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 14 - background runs column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 15 - background background column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 16 - material (chemical formula) column += 1 #_material_text = QLineEdit("") _material_text = QLabel("N/A") _material_button = QPushButton("...") _material_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _material_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _material_button.pressed.connect( lambda key=random_key: self.main_window. master_table_normalization_material_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_material_text) _verti_layout.addWidget(_material_button) _material_widget = QWidget() _material_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _material_widget) _master_table_row_ui['normalization']['material'][ 'text'] = _material_text _master_table_row_ui['normalization']['material'][ 'button'] = _material_button # column 17 - mass density column += 1 _mass_text = QLineEdit("N/A") _mass_text.returnPressed.connect( lambda key=random_key: self.main_window. master_table_normalization_mass_density_line_edit_entered(key)) _mass_units = QLabel("g/cc") _top_widget = QWidget() _top_layout = QHBoxLayout() _top_layout.addWidget(_mass_text) _top_layout.addWidget(_mass_units) _top_widget.setLayout(_top_layout) _mass_button = QPushButton("...") _mass_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _mass_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _mass_button.pressed.connect( lambda key=random_key: self.main_window. master_table_normalization_mass_density_button_pressed(key)) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_top_widget) _verti_layout.addWidget(_mass_button) _mass_widget = QWidget() _mass_widget.setLayout(_verti_layout) self.table_ui.setCellWidget(row, column, _mass_widget) _master_table_row_ui['normalization']['mass_density'][ 'text'] = _mass_text _master_table_row_ui['normalization']['mass_density'][ 'button'] = _mass_button # column 18 - packing fraction column += 1 _item = QTableWidgetItem("") self.table_ui.setItem(row, column, _item) # column 19 - shape (cylinder or sphere) column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect( lambda value=_shape_default_value, key=random_key: self.main_window .master_table_normalization_shape_changed(value, key)) _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) _widget.addItem("Cylinder") _widget.addItem("Sphere") _widget.addItem("Hollow Cylinder") _master_table_row_ui['normalization']['shape'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 20 - dimensions column += 1 # layout 1 _grid_layout = QGridLayout() _label1 = QLabel("Radius:") _grid_layout.addWidget(_label1, 1, 0) _value1 = QLabel("N/A") _grid_layout.addWidget(_value1, 1, 1) _dim1 = QLabel("cm") _grid_layout.addWidget(_dim1, 1, 2) _label2 = QLabel("Radius:") _label2.setVisible(False) _grid_layout.addWidget(_label2, 2, 0) _value2 = QLabel("N/A") _value2.setVisible(False) _grid_layout.addWidget(_value2, 2, 1) _dim2 = QLabel("cm") _dim2.setVisible(False) _grid_layout.addWidget(_dim2, 2, 2) _label3 = QLabel("Height:") _grid_layout.addWidget(_label3, 3, 0) _value3 = QLabel("N/A") _grid_layout.addWidget(_value3, 3, 1) _dim3 = QLabel("cm") _grid_layout.addWidget(_dim3, 3, 2) _master_table_row_ui['normalization']['geometry']['radius'][ 'value'] = _value1 _master_table_row_ui['normalization']['geometry']['radius2'][ 'value'] = _value2 _master_table_row_ui['normalization']['geometry']['height'][ 'value'] = _value3 _master_table_row_ui['normalization']['geometry']['radius'][ 'label'] = _label1 _master_table_row_ui['normalization']['geometry']['radius2'][ 'label'] = _label2 _master_table_row_ui['normalization']['geometry']['height'][ 'label'] = _label3 _master_table_row_ui['normalization']['geometry']['radius'][ 'units'] = _dim1 _master_table_row_ui['normalization']['geometry']['radius2'][ 'units'] = _dim2 _master_table_row_ui['normalization']['geometry']['height'][ 'units'] = _dim3 _geometry_widget = QWidget() _geometry_widget.setLayout(_grid_layout) _set_dimensions_button = QPushButton("...") _set_dimensions_button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _set_dimensions_button.setFixedWidth(CONFIG_BUTTON_WIDTH) _verti_layout = QVBoxLayout() _verti_layout.addWidget(_geometry_widget) _verti_layout.addWidget(_set_dimensions_button) _verti_widget = QWidget() _verti_widget.setLayout(_verti_layout) _set_dimensions_button.pressed.connect( lambda key=random_key: self.main_window. master_table_normalization_dimensions_setter_button_pressed( key)) # noqa self.table_ui.setCellWidget(row, column, _verti_widget) # column 21 - abs. correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect( lambda value=list_abs_correction[0], key=random_key: self. main_window.master_table_normalization_abs_correction_changed( value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_abs_correction: _widget.addItem(_item) _widget.setCurrentIndex(0) _master_table_row_ui['normalization']['abs_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 24 - multi. scattering correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget = QComboBox() _widget.currentIndexChanged.connect( lambda value=list_multi_scat_correction[ 0], key=random_key: self.main_window. master_table_normalization_multi_scattering_correction_changed( value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) for _item in list_multi_scat_correction: _widget.addItem(_item) _widget.setCurrentIndex(0) _master_table_row_ui['normalization']['mult_scat_correction'] = _widget _layout.addWidget(_widget) _w = QWidget() _w.setLayout(_layout) self.table_ui.setCellWidget(row, column, _w) # column 22 - inelastic correction column += 1 _layout = QHBoxLayout() _layout.setContentsMargins(0, 0, 0, 0) _widget1 = QComboBox() _widget1.setMinimumHeight(20) list_inelastic_correction = self.get_inelastic_scattering_list( shape=_shape_default_value) for _item in list_inelastic_correction: _widget1.addItem(_item) _widget1.setCurrentIndex(0) _master_table_row_ui['normalization'][ 'inelastic_correction'] = _widget1 _button = QPushButton("...") _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.pressed.connect( lambda key=random_key: self.main_window. master_table_normalization_placzek_button_pressed(key)) _master_table_row_ui['normalization']['placzek_button'] = _button _button.setVisible(False) _layout.addWidget(_widget1) _layout.addWidget(_button) _widget = QWidget() _widget.setLayout(_layout) _default_value = 'None' _widget1.currentIndexChanged.connect( lambda value=_default_value, key=random_key: self.main_window. master_table_normalization_inelastic_correction_changed( value, key)) # noqa _widget.blockSignals(True) _list_ui_to_unlock.append(_widget) self.table_ui.setCellWidget(row, column, _widget) # automatically populate placzek infos with default values _norm_formated_placzek_default = self.formated_placzek_default( normalization_placzek_arguments) _master_table_row_ui['normalization'][ 'placzek_infos'] = _norm_formated_placzek_default # column 23 - key/value pair column += 1 _layout = QHBoxLayout() _spacer_kv1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer_kv1) _button = QPushButton("...") _layout.addWidget(_button) _button.setFixedWidth(CONFIG_BUTTON_WIDTH) _button.setFixedHeight(CONFIG_BUTTON_HEIGHT) _button.pressed.connect(lambda key=random_key: self.main_window. master_table_keyvalue_button_pressed(key)) _new_widget = QWidget() _new_widget.setLayout(_layout) self.table_ui.setCellWidget(row, column, _new_widget) _master_table_row_ui['align_and_focus_args_button'] = _button _spacer_kv2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) _layout.addItem(_spacer_kv2) _layout.addStretch() align_and_focus_args = self.add_global_key_value_to_local_key_value( align_and_focus_args) _master_table_row_ui[ 'align_and_focus_args_infos'] = align_and_focus_args # Recap. self.main_window.master_table_list_ui[ random_key] = _master_table_row_ui self.unlock_signals_ui(list_ui=_list_ui_to_unlock) self.main_window.check_status_of_right_click_buttons()