def __init__(self, symbol): self.symbol = symbol self.Z = Xrf.atomic_number(self.symbol) self.show = False k_lines = { 'Ka': False, 'Ka1': True, 'Ka2': True, 'Kb': False, 'Kb1': True, 'Kb2': True } l_lines = { 'La1': False, 'Lb1': False, 'Lb2': False, 'Lg1': False, 'Lg2': False, 'Lg3': False, 'Lg4': False, 'Ll': False } g_lines = {'G1': True, 'G2': True, 'G3': True} self.toggles = { 'Ka': ['Ka1', 'Ka2'], 'Kb': ['Kb1', 'Kb2'], 'Ka1': ['Ka'], 'Kb1': ['Kb'], 'Ka2': ['Ka'], 'Kb2': ['Kb'] } # dict = {key: [e, selected]} self.k_selection = dict() for k in k_lines: e = Xrf.lookup_xrf_line(self.symbol + ' ' + k) #if (e != 0.): self.k_selection.update({k: [e, k_lines[k]]}) self.l_selection = dict() for l in l_lines: e = Xrf.lookup_xrf_line(self.symbol + ' ' + l) #if (e != 0.): show = False self.l_selection.update({l: [e, l_lines[l] or show]}) self.g_selection = dict() for g in g_lines: e = Xrf.lookup_xrf_line(self.symbol + ' ' + g) #if (e != 0.): self.g_selection.update({g: [e, g_lines[g]]}) self.all_lines = dict() self.all_lines.update(self.k_selection) self.all_lines.update(self.l_selection) self.all_lines.update(self.g_selection)
def menu_line(self, roi): """ Private method """ line = self.widgets.line[roi].text() energy = Xrf.lookup_xrf_line(line) if (energy == None): energy = Xrf.lookup_gamma_line(line) if (energy != None): self.roi[roi].energy = energy self.widgets.energy[roi].setText('%.3f' % energy) print('line: ' + line)
def initUI(self): self.verticalLayout_4 = QtWidgets.QVBoxLayout(self) self.groupBox = QtWidgets.QGroupBox(self) self.container = self.groupBox self.gridLayout = QtWidgets.QGridLayout(self.container) self.gridLayout.setContentsMargins(7, 15, 7, 7) self.gridLayout.setSpacing(5) header = { 'ROI': 0, 'Use?': 1, 'Centroid': 2, 'FWHM': 3, 'Energy': 4, 'Fluor. line': 5, 'Energy error': 6 } row = 0 for key, col in header.items(): t = QtWidgets.QLabel(self.groupBox) t.setText(key) t.setAlignment(QtCore.Qt.AlignHCenter) #t.setMinimumSize(QtCore.QSize(60, 0)) self.gridLayout.addWidget(t, row, col, QtCore.Qt.AlignHCenter) for i in range(self.nrois): row = i + 1 t = QtWidgets.QLabel(self.groupBox) t.setText(str(i)) t.setAlignment(QtCore.Qt.AlignHCenter) self.gridLayout.addWidget(t, row, 0, QtCore.Qt.AlignHCenter) self.widgets.use_flag[i] = t = QtWidgets.QCheckBox(self.groupBox) t.setChecked(self.roi[i].use == 1) t.toggled.connect( functools.partial(self.menu_use, i) ) # lambda expression didn't work so using functools.partial instead self.gridLayout.addWidget(t, row, 1, QtCore.Qt.AlignHCenter) self.widgets.centroid[i] = t = QtWidgets.QLineEdit(self.groupBox) t.setText('%.3f' % self.roi[i].centroid) t.setFixedWidth(70) t.setAlignment(QtCore.Qt.AlignHCenter) t.returnPressed.connect(functools.partial(self.menu_centroid, i)) self.gridLayout.addWidget(t, row, 2, QtCore.Qt.AlignHCenter) self.widgets.fwhm[i] = t = QtWidgets.QLineEdit(self.groupBox) t.setText('%.3f' % self.roi[i].fwhm) t.setFixedWidth(70) t.setAlignment(QtCore.Qt.AlignHCenter) self.gridLayout.addWidget(t, row, 3, QtCore.Qt.AlignHCenter) # If the ROI energy is zero, then try to use the label to lookup an # XRF line energy self.roi[i].energy = 0 if (self.roi[i].energy == 0.0): self.roi[i].energy = Xrf.lookup_xrf_line(self.roi[i].label) if (self.roi[i].energy == None): self.roi[i].energy = Xrf.lookup_gamma_line( self.roi[i].label) if (self.roi[i].energy == None): self.roi[i].energy = 0.0 self.widgets.energy[i] = t = QtWidgets.QLineEdit(self.groupBox) t.setText('%.3f' % self.roi[i].energy) t.setFixedWidth(70) t.setAlignment(QtCore.Qt.AlignHCenter) t.returnPressed.connect(functools.partial(self.menu_energy, i)) self.gridLayout.addWidget(t, row, 4, QtCore.Qt.AlignHCenter) self.widgets.line[i] = t = QtWidgets.QLineEdit(self.groupBox) t.setText(self.roi[i].label) t.setFixedWidth(70) t.setAlignment(QtCore.Qt.AlignHCenter) self.widgets.line[i].returnPressed.connect( functools.partial(self.menu_line, i)) self.gridLayout.addWidget(t, row, 5, QtCore.Qt.AlignHCenter) self.widgets.energy_diff[i] = t = QtWidgets.QLineEdit( self.groupBox) t.setText('%.3f' % 0.0) t.setFixedWidth(70) t.setAlignment(QtCore.Qt.AlignHCenter) self.gridLayout.addWidget(t, row, 6, QtCore.Qt.AlignHCenter) self.verticalLayout_4.addWidget(self.groupBox) self.groupBox_2 = QtWidgets.QGroupBox(self) self.groupBox_2.setTitle("") self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.groupBox_2) self.horizontalLayout = QtWidgets.QHBoxLayout() self.lblCalibrationType = QtWidgets.QLabel(self.groupBox_2) self.lblCalibrationType.setText("Calibration type:") self.lblCalibrationType.setAlignment(QtCore.Qt.AlignRight) self.horizontalLayout.addWidget(self.lblCalibrationType) self.fit_type = QtWidgets.QComboBox(self.groupBox_2) self.fit_type.addItem('Linear') self.fit_type.addItem('Quadratic') self.horizontalLayout.addWidget(self.fit_type) # in QtDialong, setting default=False, autoDefault=False prevents button from default trigger by Enter key self.do_fit = QtWidgets.QPushButton(self.groupBox_2, default=False, autoDefault=False) self.do_fit.setText("Compute calibration") self.do_fit.clicked.connect(self.menu_do_fit) self.horizontalLayout.addWidget(self.do_fit) self.plot_cal = QtWidgets.QPushButton(self.groupBox_2, default=False, autoDefault=False) self.plot_cal.setText("Plot calibration error") self.plot_cal.clicked.connect(self.menu_plot_calibration) self.horizontalLayout.addWidget(self.plot_cal) self.plot_fwhm = QtWidgets.QPushButton(self.groupBox_2, default=False, autoDefault=False) self.plot_fwhm.setText("Plot FWHM") self.plot_fwhm.clicked.connect(self.menu_plot_fwhm) self.horizontalLayout.addWidget(self.plot_fwhm) self.verticalLayout_3.addLayout(self.horizontalLayout) self.verticalLayout_4.addWidget(self.groupBox_2) self.groupBox_3 = QtWidgets.QGroupBox(self) self.groupBox_3.setTitle("") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox_3) self.gridLayout_2 = QtWidgets.QGridLayout() self.label_12 = QtWidgets.QLabel(self.groupBox_3) self.label_12.setText("Units") self.gridLayout_2.addWidget(self.label_12, 0, 1, 1, 1) self.label_13 = QtWidgets.QLabel(self.groupBox_3) self.label_13.setText("Offset") self.gridLayout_2.addWidget(self.label_13, 0, 2, 1, 1) self.label_14 = QtWidgets.QLabel(self.groupBox_3) self.label_14.setText("Slope") self.gridLayout_2.addWidget(self.label_14, 0, 3, 1, 1) self.label_15 = QtWidgets.QLabel(self.groupBox_3) self.label_15.setText("Quadratic") self.gridLayout_2.addWidget(self.label_15, 0, 4, 1, 1) self.label_11 = QtWidgets.QLabel(self.groupBox_3) self.label_11.setText("Calibration coefficients:") self.label_11.setAlignment(QtCore.Qt.AlignRight) self.gridLayout_2.addWidget(self.label_11, 1, 0, 1, 1) self.cal_units = t = QtWidgets.QLineEdit(self.groupBox_3) t.setText(self.calibration.units) t.setFixedWidth(90) self.gridLayout_2.addWidget(t, 1, 1, 1, 1) self.cal_offset = t = QtWidgets.QLineEdit(self.groupBox_3) t.setText('%.7f' % (self.calibration.offset)) t.setFixedWidth(90) self.gridLayout_2.addWidget(t, 1, 2, 1, 1) self.cal_slope = t = QtWidgets.QLineEdit(self.groupBox_3) t.setText('%.7f' % (self.calibration.slope)) t.setFixedWidth(90) self.gridLayout_2.addWidget(t, 1, 3, 1, 1) self.cal_quad = t = QtWidgets.QLineEdit(self.groupBox_3) t.setText('%.7f' % (self.calibration.quad)) t.setFixedWidth(90) self.gridLayout_2.addWidget(t, 1, 4, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_2) self.verticalLayout_4.addWidget(self.groupBox_3) self.groupBox_4 = QtWidgets.QGroupBox(self) self.groupBox_4.setTitle("") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.groupBox_4) self.btnOK = QtWidgets.QPushButton(self.groupBox_4, default=False, autoDefault=False) self.btnOK.clicked.connect(functools.partial(self.menu_ok_cancel, 'OK')) self.btnOK.setText("OK") self.horizontalLayout_2.addWidget(self.btnOK) self.btnCancel = QtWidgets.QPushButton(self.groupBox_4, default=False, autoDefault=False) self.btnCancel.clicked.connect( functools.partial(self.menu_ok_cancel, 'Cancel')) self.btnCancel.setText("Cancel") self.horizontalLayout_2.addWidget(self.btnCancel) self.verticalLayout_4.addWidget(self.groupBox_4) self.setWindowTitle("Energy Calibration") self.groupBox.setTitle("Defined regions") self.setFixedSize(self.verticalLayout_4.sizeHint())