Skip to content

Commit

Permalink
Merge branch 'next' into SC-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici authored Jan 9, 2025
2 parents 801cd60 + b97f373 commit 0951f38
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 195 deletions.
3 changes: 3 additions & 0 deletions src/hyspecppt/hppt/experiment_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
DEFAULT_LATTICE = dict(a=1, b=1, c=1, alpha=90, beta=90, gamma=90, h=0, k=0, l=0)
DEFAULT_EXPERIMENT = dict(Ei=20, S2=30, alpha_p=0, plot_type=PLOT_TYPES[1])
DEFAULT_CROSSHAIR = dict(DeltaE=0, modQ=0)
DEFAULT_MODE = dict(current_experiment_type="single_crystal")

# maximum momentum transfer
MaxQ = 15

# invalid style
Expand Down
9 changes: 9 additions & 0 deletions src/hyspecppt/hppt/hppt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def set_experiment_data(self, Ei: float, S2: float, alpha_p: float, plot_type: s
self.alpha_p = alpha_p
self.plot_type = plot_type

def get_experiment_data(self) -> dict[str, float]:
data = dict()

data["Ei"] = self.Ei
data["S2"] = self.S2
data["alpha_p"] = self.alpha_p
data["plot_type"] = self.plot_type
return data

def get_graph_data(self) -> list[float, float, float, list, list, list]:
return self.calculate_graph_data()

Expand Down
133 changes: 72 additions & 61 deletions src/hyspecppt/hppt/hppt_presenter.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
"""Presenter for the Main tab"""

from qtpy.QtWidgets import QWidget

from .experiment_settings import DEFAULT_CROSSHAIR, DEFAULT_EXPERIMENT, DEFAULT_LATTICE, PLOT_TYPES
from .experiment_settings import DEFAULT_CROSSHAIR, DEFAULT_EXPERIMENT, DEFAULT_LATTICE, DEFAULT_MODE, PLOT_TYPES


class HyspecPPTPresenter:
"""Main presenter"""

def __init__(self, view: "[QWidget]", model: "[QWidget]"):
def __init__(self, view: any, model: any):
"""Constructor
:view: hppt_view class type
:model:hppt_model class type
"""
self._view = view
self._model = model

# M-V-P connections through callbacks
self.view.connect_fields_update(self.handle_field_values_update)
self.view.connect_powder_mode_switch(self.handle_switch_to_powder)
self.view.connect_sc_mode_switch(self.handle_switch_to_sc)

# populate fields
self.view.SCW.set_values(DEFAULT_LATTICE)
self.view.EW.initializeCombo(PLOT_TYPES)
self.view.EW.set_values(DEFAULT_EXPERIMENT)
self.view.CW.set_values(DEFAULT_CROSSHAIR)
self.view.SelW.set_SC_toggle(True)

self.get_Experiment_values()
self.get_SingleCrystal_values()
self.get_Selector_values()
self.get_Crosshair_values()
# model init
# to be removed needs to happen in the model
self.model.set_experiment_data(**DEFAULT_EXPERIMENT)
self.model.set_crosshair_data(**DEFAULT_CROSSHAIR, **DEFAULT_MODE)
self.model.set_single_crystal_data(params=DEFAULT_LATTICE)

# set default selection mode
experiment_type = self.view.SelW.powder_label
if DEFAULT_MODE["current_experiment_type"].startswith("single"):
experiment_type = self.view.SelW.sc_label
self.view.SelW.selector_init(experiment_type) # pass the default mode from experiment type

@property
def view(self):
Expand All @@ -36,55 +47,55 @@ def model(self):
"""Return the model for this presenter"""
return self._model

def get_Experiment_values(self) -> dict:
"""Get Ei, Pangle, S2, Type values from Experiment
return: dict of Experiment key value pairs
"""
EW_dict = {}
EW_dict["Ei"] = self.view.EW.Ei_edit.text()
EW_dict["Pangle"] = self.view.EW.Pangle_edit.text()
EW_dict["S2"] = self.view.EW.S2_edit.text()
EW_dict["Type"] = self.view.EW.Type_combobox.currentText()
return EW_dict

def get_Selector_values(self):
"""Check if Single Crystal radio button is checked
return: True - Single Crystal radio button is toggled
False - Single Crystal radio button is not toggled. Powder radio button is toggled
"""
return self.view.SelW.sc_rb.isChecked()

def get_SingleCrystal_values(self):
"""Get Single Crystal mode specific values from SingleCrystalWidget
return: dict of Single Crystal key value pairs
"""
SC_dict = {}
SC_dict["a"] = self.view.SCW.a_edit.text()
SC_dict["b"] = self.view.SCW.b_edit.text()
SC_dict["c"] = self.view.SCW.c_edit.text()

SC_dict["alpha"] = self.view.SCW.alpha_edit.text()
SC_dict["beta"] = self.view.SCW.beta_edit.text()
SC_dict["gamma"] = self.view.SCW.gamma_edit.text()

SC_dict["h"] = self.view.SCW.h_edit.text()
SC_dict["k"] = self.view.SCW.k_edit.text()
SC_dict["l"] = self.view.SCW.l_edit.text()
return SC_dict

def get_Crosshair_values(self):
"""Get Crosshair mode specific values from CrosshairWidget
return: dict of Crosshair key value pairs
"""
CH_dict = {}
CH_dict["DeltaE"] = self.view.CW.DeltaE_edit.text()
CH_dict["modQ"] = self.view.CW.modQ_edit.text()
return CH_dict

def set_PlotWidget_values(self):
"""Pass through intensity matrix into plot in view"""
pass
def handle_field_values_update(self, field_values):
"""Save the values in the model"""
section = field_values["name"]
data = field_values["data"]
if section == "crosshair":
# get the current experiment type
experiment_type_label = self.view.SelW.get_selected_mode_label()
experiment_type = "powder"
if experiment_type_label.startswith("Single"):
experiment_type = "single_crystal"
self.model.set_crosshair_data(
current_experiment_type=experiment_type, DeltaE=float(data["DeltaE"]), modQ=float(data["modQ"])
)
elif section == "experiment":
self.model.set_experiment_data(
float(data["Ei"]), float(data["S2"]), float(data["alpha_p"]), data["plot_type"]
)
else:
self.model.set_single_crystal_data(data)

def handle_switch_to_powder(self):
"""Switch to Powder mode"""
# update the fields' visibility
self.view.field_visibility_in_Powder()
# update the experiment type in the model
experiment_type = "powder"
self.model.set_crosshair_data(current_experiment_type=experiment_type)

# get the valid values for crosshair saved fields
# if the view contains an invalid value it is overwritten
saved_values = self.model.get_crosshair_data()
self.view.CW.set_values(saved_values)

saved_values = self.model.get_experiment_data()
self.view.EW.set_values(saved_values)

def handle_switch_to_sc(self):
"""Switch to Single Crystal mode"""
# update the fields' visibility
self.view.field_visibility_in_SC()
# update the experiment type in the model
experiment_type = "single_crystal"
self.model.set_crosshair_data(current_experiment_type=experiment_type)

# get the valid values for crosshair saved fields
# if the view contains an invalid value it is overwritten
saved_values = self.model.get_crosshair_data()
self.view.CW.set_values(saved_values)

# get the valid values for lattice saved fields
# saved_values = self.model.get_single_crystal_data()
# self.view.CW.set_values(saved_values)
Loading

0 comments on commit 0951f38

Please sign in to comment.