1313from RefRed .configuration .global_settings import GlobalSettings
1414from RefRed .interfaces import load_ui
1515
16+ DEFAULT_INSTRUMENT_SETTINGS = {
17+ "apply_instrument_settings" : False ,
18+ "source_detector_distance" : 15.75 ,
19+ "sample_detector_distance" : 1.83 ,
20+ "num_x_pixels" : 256 ,
21+ "num_y_pixels" : 304 ,
22+ "pixel_width" : 0.70 ,
23+ "xi_reference" : 445 ,
24+ "s1_sample_distance" : 1.485 ,
25+ }
26+
1627
1728class InstrumentSettingsEntryPoint (QGroupBox ):
1829 def __init__ (self , title = "Instrument Settings" ):
@@ -37,16 +48,12 @@ def initUI(self):
3748 self .applyCheckBox = QCheckBox ("Apply" , self )
3849 self .applyCheckBox .stateChanged .connect (self .toggleSettingsButton )
3950 self .settingsButton = QPushButton ("Settings" , self )
40- self .settingsButton .setEnabled (
41- # enabled if we use the correction
42- self .applyCheckBox .isChecked ()
43- )
51+ self .settingsButton .setEnabled (self .applyCheckBox .isChecked ())
4452
4553 # Create a horizontal layout for the checkbox and settings button
4654 hbox = QHBoxLayout ()
4755 hbox .addWidget (self .applyCheckBox )
4856 hbox .addWidget (self .settingsButton )
49- # hbox.addStretch(1) # This adds a stretchable space after the button (optional)
5057
5158 # Set the layout for the group box
5259 self .setLayout (hbox )
@@ -129,14 +136,14 @@ class InstrumentSettings(GlobalSettings):
129136 """
130137
131138 # pydantic fields
132- apply_instrument_settings : bool = False
133- source_detector_distance : float = 15.75
134- sample_detector_distance : float = 1.83
135- num_x_pixels : int = 256
136- num_y_pixels : int = 304
137- pixel_width : float = 0.70
138- xi_reference : float = 445
139- s1_sample_distance : float = 1.485
139+ apply_instrument_settings : bool = DEFAULT_INSTRUMENT_SETTINGS [ "apply_instrument_settings" ]
140+ source_detector_distance : float = DEFAULT_INSTRUMENT_SETTINGS [ "source_detector_distance" ]
141+ sample_detector_distance : float = DEFAULT_INSTRUMENT_SETTINGS [ "sample_detector_distance" ]
142+ num_x_pixels : int = DEFAULT_INSTRUMENT_SETTINGS [ "num_x_pixels" ]
143+ num_y_pixels : int = DEFAULT_INSTRUMENT_SETTINGS [ "num_y_pixels" ]
144+ pixel_width : float = DEFAULT_INSTRUMENT_SETTINGS [ "pixel_width" ]
145+ xi_reference : float = DEFAULT_INSTRUMENT_SETTINGS [ "xi_reference" ]
146+ s1_sample_distance : float = DEFAULT_INSTRUMENT_SETTINGS [ "s1_sample_distance" ]
140147
141148 # class variable, translates fields to XML tag names, same names as the lr_reduction package
142149 def to_xml (self , indent : str = "" ) -> str :
@@ -193,9 +200,10 @@ def from_xml(self, node: Element):
193200 if len (tmp ):
194201 value = tmp [0 ].childNodes [0 ].nodeValue
195202 setattr (self , field , converter (value ))
196- # elif field == "apply_instrument_settings":
197- # # old XML files don't have instrument settings, so we make sure it's not used.
198- # setattr(self, "apply_instrument_settings", False)
203+ else :
204+ # if the field is not found in the XML, we use the default value
205+ setattr (self , field , DEFAULT_INSTRUMENT_SETTINGS [field ])
206+
199207 return self
200208
201209 def as_template_reader_dict (self ) -> Dict [str , Any ]:
0 commit comments