55@author: Sarthak
66"""
77
8+ import sys
9+ from pathlib import Path
10+
811import pyqtgraph as pg
912from pyqtgraph .Qt import QtCore , QtGui , QtWidgets #, QColorDialog
1013import numpy as np
11- import sys
14+
1215from Spectra_fit_funcs import Spectra_Fit , Single_Gaussian
1316import matplotlib .pyplot as plt
1417
2326pg .mkQApp ()
2427pg .setConfigOption ('background' , 'w' )
2528
26- uiFile = "Spectra_plot_fit_gui.ui"
29+ base_path = Path (__file__ ).parent
30+ file_path = (base_path / "Spectra_plot_fit_gui.ui" ).resolve ()
31+
32+ uiFile = file_path
2733
2834WindowTemplate , TemplateBaseClass = pg .Qt .loadUiType (uiFile )
2935
@@ -120,19 +126,24 @@ def clear_plot(self):
120126 def fit_and_plot (self ):
121127 fit_func = self .ui .fitFunc_comboBox .currentText ()
122128
123- if fit_func == "Single Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
129+ if self .ui .subtract_bck_checkBox .isChecked () == False :
130+ self .ui .result_textBrowser .setText ("You need to check the subtract background option!" )
131+
132+ else :
133+ if fit_func == "Single Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
134+
135+ single_gauss = Single_Gaussian (self .file , self .bck_file )
136+ self .result = single_gauss .gaussian_model ()
137+ self .ui .plot .plot (self .x , self .y , clear = True , pen = 'r' )
138+ self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
139+ self .ui .result_textBrowser .setText (self .result .fit_report ())
140+
141+ elif fit_func == "Double Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
142+ self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
143+
144+ elif fit_func == "Multiple Gaussians" and self .ui .subtract_bck_checkBox .isChecked () == True :
145+ self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
124146
125- single_gauss = Single_Gaussian (self .file , self .bck_file )
126- self .result = single_gauss .gaussian_model ()
127- self .ui .plot .plot (self .x , self .y , clear = True , pen = 'r' )
128- self .ui .plot .plot (self .x , self .result .best_fit , clear = False , pen = 'k' )
129- self .ui .result_textBrowser .setText (self .result .fit_report ())
130-
131- elif fit_func == "Double Gaussian" and self .ui .subtract_bck_checkBox .isChecked () == True :
132- self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
133-
134- elif fit_func == "Multiple Gaussians" and self .ui .subtract_bck_checkBox .isChecked () == True :
135- self .ui .result_textBrowser .setText ("Not Implemented Yet!" )
136147
137148 def pub_ready_plot_export (self ):
138149 filename = QtWidgets .QFileDialog .getSaveFileName (self ,caption = "Filename with EXTENSION" )
@@ -161,19 +172,10 @@ def close_application(self):
161172 else :
162173 pass
163174
164-
165- win = MainWindow ()
166- #def main():
167- # app = QtGui.QApplication(sys.argv)
168- # main = MainWindow()
169- # main.show()
170- # sys.exit(app.exec_())
171- #
172- #if __name__ == '__main__':
173- # main()
175+ def run ():
176+ win = MainWindow ()
177+ QtGui .QApplication .instance ().exec_ ()
178+ return win
174179
175- # Start Qt event loop unless running in interactive mode or using pyside.
176- if __name__ == '__main__' :
177- import sys
178- if (sys .flags .interactive != 1 ) or not hasattr (QtCore , 'PYQT_VERSION' ):
179- QtGui .QApplication .instance ().exec_ ()
180+ #Uncomment below if you want to run this as standalone
181+ #run()
0 commit comments