1111from intensity_table_dialog import IntensityTableDialog
1212
1313ICON_PATH = os .path .join (os .path .dirname (__file__ ), "eds_icon.png" )
14- print (f"Icon path: { ICON_PATH } " )
14+ # print(f"Icon path: {ICON_PATH}")
1515
1616class NavigatorWidget (QtWidgets .QWidget ):
1717 def __init__ (self , session : EDSSession ):
@@ -86,6 +86,7 @@ def __init__(self, session: EDSSession):
8686 self .bg_checkbox .stateChanged .connect (self ._on_signal_type_changed )
8787 self .bg_open_btn .clicked .connect (self ._on_bg_open )
8888
89+
8990 # Row 3: Remove selected | Remove all
9091 remove_row = QtWidgets .QHBoxLayout ()
9192 self .remove_spec_btn = QtWidgets .QPushButton ("Remove Selected Spectrum" )
@@ -96,6 +97,25 @@ def __init__(self, session: EDSSession):
9697 self .remove_spec_btn .clicked .connect (self .remove_selected_spectrum )
9798 self .remove_all_btn .clicked .connect (self .remove_all_spectra )
9899
100+ # Row 3a: Export Selected | Export All
101+ export_row = QtWidgets .QHBoxLayout ()
102+ self .export_selected_btn = QtWidgets .QPushButton ("Export Selected" )
103+ self .export_all_btn = QtWidgets .QPushButton ("Export All" )
104+ export_row .addWidget (self .export_selected_btn )
105+ export_row .addWidget (self .export_all_btn )
106+ layout .addLayout (export_row )
107+ self .export_selected_btn .clicked .connect (self .export_selected_spectrum )
108+ self .export_all_btn .clicked .connect (self .export_all_spectra )
109+
110+ # Row 3b: Ask for folder (checkbox) and Format (entry)
111+ export_opts_row = QtWidgets .QHBoxLayout ()
112+ self .ask_folder_checkbox = QtWidgets .QCheckBox ("Ask for folder" )
113+ self .format_entry = QtWidgets .QLineEdit ("emsa, csv" )
114+ export_opts_row .addWidget (self .ask_folder_checkbox )
115+ export_opts_row .addWidget (QtWidgets .QLabel ("Format:" ))
116+ export_opts_row .addWidget (self .format_entry )
117+ layout .addLayout (export_opts_row )
118+
99119 # Row 4: Intensities (sel) | Intensities (all)
100120 int_row = QtWidgets .QHBoxLayout ()
101121 self .intensity_btn = QtWidgets .QPushButton ("Intensities (sel)" )
@@ -480,6 +500,50 @@ def remove_all_spectra(self):
480500 if self .show_fitted_table_checkbox .isChecked ():
481501 self .show_fitted_intensity_table ()
482502
503+ # --- Export helper and handler methods (moved out of __init__) ---
504+ def _get_export_folder_and_formats (self ):
505+ folder = None
506+ if self .ask_folder_checkbox .isChecked ():
507+ folder = QtWidgets .QFileDialog .getExistingDirectory (self , "Select Export Folder" )
508+ if not folder :
509+ return None , None # User cancelled
510+ # Parse formats from entry (split by comma or space)
511+ fmt_text = self .format_entry .text ().strip ()
512+ if not fmt_text :
513+ formats = ["emsa" , "csv" ]
514+ else :
515+ # Split by comma or whitespace
516+ import re
517+ formats = [f .strip () for f in re .split (r'[\s,]+' , fmt_text ) if f .strip ()]
518+ return folder , formats
519+
520+ def export_selected_spectrum (self ):
521+ rec = self .session .active_record
522+ if rec is None :
523+ QtWidgets .QMessageBox .warning (self , "No Spectrum Selected" , "Please select a spectrum to export." )
524+ return
525+ folder , formats = self ._get_export_folder_and_formats ()
526+ if formats is None :
527+ return # Cancelled
528+ try :
529+ rec .export (folder = folder , formats = formats )
530+ QtWidgets .QMessageBox .information (self , "Export Complete" , f"Exported '{ rec .name } ' to { folder or os .path .dirname (rec .path )} in formats: { ', ' .join (formats )} " )
531+ except Exception as e :
532+ QtWidgets .QMessageBox .warning (self , "Export Error" , str (e ))
533+
534+ def export_all_spectra (self ):
535+ if not self .session .records :
536+ QtWidgets .QMessageBox .warning (self , "No Spectra" , "No spectra loaded to export." )
537+ return
538+ folder , formats = self ._get_export_folder_and_formats ()
539+ if formats is None :
540+ return # Cancelled
541+ try :
542+ self .session .export_all (folder = folder , formats = formats )
543+ QtWidgets .QMessageBox .information (self , "Export Complete" , f"Exported all spectra to { folder or 'default folders' } in formats: { ', ' .join (formats )} " )
544+ except Exception as e :
545+ QtWidgets .QMessageBox .warning (self , "Export Error" , str (e ))
546+
483547 def _refresh_spectrum_list (self ):
484548 self .list .blockSignals (True )
485549 self .list .clear ()
0 commit comments