Skip to content

Commit

Permalink
Window now also shows the atomic density
Browse files Browse the repository at this point in the history
  • Loading branch information
CPrescher committed Jul 6, 2015
1 parent fdc6915 commit 7d1de5d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Controller/MainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Models/GlassureModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
54 changes: 33 additions & 21 deletions Views/ControlWidgets/CompositionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7d1de5d

Please sign in to comment.