@@ -154,8 +154,8 @@ def construct_dict(
154154 """
155155 dct : dict = {}
156156 add_entry = ask_for_input (dict_name , False )
157- key_message = f"Please enter a { key_name } "
158- value_message = f"Please enter a { value_name } "
157+ key_message = f"Please enter the { key_name } "
158+ value_message = f"Please enter the { value_name } "
159159 while add_entry is True :
160160 key = prompt (key_message , style = "yellow" ).strip ().lower ()
161161 # Reject empty keys if set
@@ -241,32 +241,10 @@ def add_calibrations(
241241 """
242242 Populate the 'calibrations' field with dictionaries.
243243 """
244-
245- def get_calibration ():
246- # Request for a file to read settings from
247- calibration_file = Path (
248- prompt (
249- "What is the full file path to the calibration file? This should be a "
250- "JSON file." ,
251- style = "yellow" ,
252- )
253- )
254- try :
255- with open (calibration_file , "r" ) as file :
256- calibration_values : dict = json .load (file )
257- return calibration_values
258- except Exception as e :
259- console .print (
260- f"Error opening the provided file: { e } " ,
261- style = "red" ,
262- )
263- if ask_for_input ("calibration file" , True ) is True :
264- return get_calibration ()
265- else :
266- return {}
267-
268- # Settings
269- known_calibraions = ("magnification" ,)
244+ # Known calibrations and what to call their keys and values
245+ known_calibrations : dict [str , tuple [str , str ]] = {
246+ "magnification" : ("magnification" , "pixel size (in angstroms)" )
247+ }
270248
271249 # Start of add_calibrations
272250 print_field_info (field )
@@ -279,7 +257,7 @@ def get_calibration():
279257 style = "yellow" ,
280258 ).lower ()
281259 # Check if it's a known type of calibration
282- if calibration_type not in known_calibraions :
260+ if calibration_type not in known_calibrations . keys () :
283261 console .print (
284262 f"{ calibration_type } is not a known type of calibration" ,
285263 style = "red" ,
@@ -292,7 +270,15 @@ def get_calibration():
292270 add_calibration = ask_for_input (category , True )
293271 continue
294272 # Skip failed inputs
295- calibration_values = get_calibration ()
273+ calibration_values = construct_dict (
274+ f"{ calibration_type } setting" ,
275+ known_calibrations [calibration_type ][0 ],
276+ known_calibrations [calibration_type ][1 ],
277+ allow_empty_key = False ,
278+ allow_empty_value = False ,
279+ allow_eval = True ,
280+ sort_keys = True ,
281+ )
296282 if not calibration_values :
297283 add_calibration = ask_for_input (category , True )
298284 continue
0 commit comments