diff --git a/Controller/MainController.py b/Controller/MainController.py index 5fb7f6e..24e3f2a 100644 --- a/Controller/MainController.py +++ b/Controller/MainController.py @@ -115,6 +115,9 @@ def model_changed(self): self.main_widget.spectrum_widget.plot_sq(self.model.sq_spectrum) self.main_widget.spectrum_widget.plot_pdf(self.model.gr_spectrum) + self.main_widget.left_control_widget.composition_widget.density_atomic_units_lbl.\ + setText("{:.4f}".format(self.model.atomic_density)) + def bkg_scale_changed(self, value): self.model.background_scaling = value diff --git a/Models/GlassureModel.py b/Models/GlassureModel.py index df3989d..ed63619 100644 --- a/Models/GlassureModel.py +++ b/Models/GlassureModel.py @@ -47,6 +47,13 @@ def load_bkg(self, filename): self.background_spectrum.load(filename) self.calculate_spectra() + @property + def atomic_density(self): + if len(self.composition): + return convert_density_to_atoms_per_cubic_angstrom(self.composition, self.density) + return 0 + + @property def background_spectrum(self): if self.diamond_background_spectrum is None: @@ -73,7 +80,6 @@ def set_smooth(self, value): def update_parameter(self, composition, density, q_min, q_max, r_cutoff, r_min, r_max, use_modification_fcn=False, interpolation_method=None, interpolation_parameters=None): - print "update" self.composition = composition self.density = density diff --git a/Views/ControlWidgets/CompositionWidget.py b/Views/ControlWidgets/CompositionWidget.py index 2c5b3b9..c7f8200 100644 --- a/Views/ControlWidgets/CompositionWidget.py +++ b/Views/ControlWidgets/CompositionWidget.py @@ -10,49 +10,61 @@ class CompositionWidget(QtGui.QWidget): def __init__(self, *args): super(CompositionWidget, self).__init__(*args) - self.create_widgets() - def create_widgets(self): + self._create_widgets() + self._create_layout() + self._style_widgets() + + def _create_widgets(self): + self.add_element_btn = QtGui.QPushButton("Add") + self.delete_element_btn = QtGui.QPushButton("Delete") + + self.density_lbl = QtGui.QLabel("Density:") + self.density_txt = QtGui.QLineEdit("2.2") + self.density_atomic_units_lbl = QtGui.QLabel("") + + self.composition_tw = QtGui.QTableWidget() + self.composition_tw.cellChanged.connect(self.emit_composition_changed_signal) + + def _create_layout(self): self.main_layout = QtGui.QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setSpacing(5) self.button_layout = QtGui.QHBoxLayout() self.button_layout.setSpacing(15) - self.add_element_btn = QtGui.QPushButton("Add") - self.delete_element_btn = QtGui.QPushButton("Delete") self.button_layout.addWidget(self.add_element_btn) self.button_layout.addWidget(self.delete_element_btn) - self.density_layout = QtGui.QHBoxLayout() - self.density_lbl = QtGui.QLabel("Density:") + self.density_layout = QtGui.QGridLayout() + self.density_layout.addWidget(self.density_lbl, 0, 0) + self.density_layout.addWidget(self.density_txt, 0, 1) + self.density_layout.addWidget(QtGui.QLabel('g/cm^3'), 0, 2) + self.density_layout.addWidget(self.density_atomic_units_lbl, 1, 1) + self.density_layout.addWidget(QtGui.QLabel('at/A^3'), 1, 2) + + self.main_layout.addLayout(self.button_layout) + self.main_layout.addWidget(self.composition_tw) + self.main_layout.addLayout(self.density_layout) + + self.setLayout(self.main_layout) + + + def _style_widgets(self): self.density_lbl.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight) - self.density_txt = QtGui.QLineEdit("2.2") + self.density_atomic_units_lbl.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight) + self.density_txt.setAlignment(QtCore.Qt.AlignRight) self.density_txt.setValidator(QtGui.QDoubleValidator()) self.density_txt.editingFinished.connect(self.emit_composition_changed_signal) self.density_txt.setMaximumWidth(100) - self.density_error_lbl = QtGui.QLabel("NaN") - self.density_layout.addWidget(self.density_lbl) - self.density_layout.addWidget(self.density_txt) - self.density_layout.addWidget(QtGui.QLabel('+-')) - self.density_layout.addWidget(self.density_error_lbl) - self.density_layout.addWidget(QtGui.QLabel('g/cm^3')) - self.composition_tw = QtGui.QTableWidget() self.composition_tw.setColumnCount(2) self.composition_tw.horizontalHeader().setVisible(False) self.composition_tw.verticalHeader().setVisible(False) self.composition_tw.setColumnWidth(0, 80) self.composition_tw.setColumnWidth(1, 80) self.composition_tw.setItemDelegate(TextDoubleDelegate(self)) - self.composition_tw.cellChanged.connect(self.emit_composition_changed_signal) - - self.main_layout.addLayout(self.button_layout) - self.main_layout.addWidget(self.composition_tw) - self.main_layout.addLayout(self.density_layout) - - self.setLayout(self.main_layout) def add_element(self, element=None, value=None): current_rows = self.composition_tw.rowCount()