class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas = FigureCanvas(self.ui.mplwidget.figure) self.canvas.setParent(self.ui.widget) # We need the toolbar widget for the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.ui.widget) # Create the QVBoxLayout object and add the widget into the layout vbox = QVBoxLayout() # The matplotlib canvas vbox.addWidget(self.canvas) # The matplotlib toolbar vbox.addWidget(self.mpl_toolbar) self.ui.widget.setLayout(vbox) # Connect the mplwidget with canvas self.ui.mplwidget = self.canvas self.connect(self.ui.pushButton_browse, SIGNAL('clicked()'), self.Browse) self.connect(self.ui.pushButton_plot, SIGNAL('clicked()'), self.Plot) self.connect(self.ui.pushButton_show, SIGNAL('clicked()'), self.Show) self.connect(self.ui.radioButton_qmd, SIGNAL('clicked()'), self.Choose1) self.connect(self.ui.radioButton_ppms, SIGNAL('clicked()'), self.Choose1) self.connect(self.ui.radioButton_other, SIGNAL('clicked()'), self.Choose1) self.connect(self.ui.pushButton_choose2, SIGNAL('clicked()'), self.Choose2) self.connect(self.ui.pushButton_recent, SIGNAL('clicked()'), self.Open_Recent) self.first_round = True self.open_dir = '' self.open_files_number = 0 self.all_info = [] def Choose1(self): if self.ui.radioButton_qmd.isChecked(): self.divider = 'Collected Data' self.ui.lineEdit_divider.setText(self.divider) self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_ppms.isChecked(): self.divider = '[Data]' self.ui.lineEdit_divider.setText(self.divider) self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_other.isChecked(): self.ui.lineEdit_divider.setText('') self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please enter data divider.') def Browse(self): if self.ui.radioButton_other.isChecked(): if self.ui.lineEdit_divider.text() == '': self.ui.lineEdit_condition1.setText( 'Data divider cannot be empty.') else: self.divider = self.ui.lineEdit_divider.text() self.file_list = [] if self.first_round == True: self.prev_dir = 'C:\Google Drive' else: self.prev_dir = self.open_dir self.fileDir = QFileDialog.getOpenFileName( self, 'Select File to Open:', self.prev_dir) self.open_dir = '' if self.fileDir != '': self.file_list = str(self.fileDir).split('/') for i in range(0, len(self.file_list) - 1): if i < len(self.file_list) - 1: self.open_dir += self.file_list[i] + '\\' elif i == len(self.file_list) - 1: self.open_dir += self.file_list[i] self.fileDir.replace('/', '\\') self.ui.lineEdit_address.setText(self.fileDir) self.ui.lineEdit_condition1.setText('Open Source File') else: self.ui.lineEdit_address.setText('None') self.ui.lineEdit_condition1.setText('Failed to Read File') self.ui.pushButton_show.setEnabled(True) self.ui.groupBox_labels.setEnabled(True) self.first_round = False self.file_name = self.file_list[len(self.file_list) - 1] else: self.file_list = [] if self.first_round == True: self.prev_dir = 'C:\Google Drive' else: self.prev_dir = self.open_dir self.fileDir = QFileDialog.getOpenFileName(self, 'Select File to Open:', self.prev_dir) self.open_dir = '' if self.fileDir != '': self.file_list = str(self.fileDir).split('/') for i in range(0, len(self.file_list) - 1): if i < len(self.file_list) - 1: self.open_dir += self.file_list[i] + '\\' elif i == len(self.file_list) - 1: self.open_dir += self.file_list[i] self.fileDir.replace('/', '\\') self.ui.lineEdit_address.setText(self.fileDir) self.ui.lineEdit_condition1.setText('Open Source File') else: self.ui.lineEdit_address.setText('None') self.ui.lineEdit_condition1.setText('Failed to Read File') self.ui.pushButton_show.setEnabled(True) self.ui.groupBox_labels.setEnabled(True) self.first_round = False self.file_name = self.file_list[len(self.file_list) - 1] def Show(self): '''self.item_info = [] self.item_info.append(self.divider) self.item_info.append(self.file_name) self.item_info.append(self.ui.lineEdit_address.text()) self.all_info.append(self.item_info)''' self.ui.comboBox_recent.addItem(self.file_name) # Every you click the "Open File" button, the content in the plot combox is refreshed self.reset_plot() self.ui.comboBox_x.clear() self.ui.comboBox_y.clear() self.ui.lineEdit_x.setText('') self.ui.lineEdit_y.setText('') self.ui.lineEdit_name.setText('') self.ui.lineEdit_condition2.setText('') labels = '' raw_parameters = [] units = [] parameters = [] new_parameters = [] self.data = [] new_data = [] first_data = [] item = 0 length = 0 # This count is the number of the reading loops for labels. If count is over 1000, that means there's something wrong with the divider line and it helps to stop the program count = 0 # It is false when program cannot find the line divider and runs the while loop 1000 times self.divider_found = True self.fileDir = self.ui.lineEdit_address.text() fp = open(self.fileDir) while True: if count > 1000: self.ui.lineEdit_condition1.setText( 'Line divider is not found.') self.divider_found = False break line = fp.readline() #print 1, line linelist = line.split(',') if linelist[0].upper() == self.divider.upper() + '\n': break for i in range(0, len(linelist)): labels += linelist[i] count += 1 if self.divider_found == True: self.ui.textEdit_labels.setText(labels) parameters = fp.readline().replace("\n", '') parameters = parameters.split(',') if self.ui.radioButton_ppms.isChecked(): lines = fp.readline().replace("\n", "") first_data = lines.split(",") for i in range(0, len(first_data)): par = [] if first_data[i] != '': par = parameters[i].split(' (') if len(par) == 2: units.append(par[1].replace(')', '')) elif len(par) == 1: units.append('1') new_parameters.append(par[0]) parameters = new_parameters elif self.ui.radioButton_qmd.isChecked(): units = fp.readline().replace("\n", '') units = units.split(",") for i in range(0, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y.addItem(parameters[i]) for i in range(0, len(parameters)): new_data = [parameters[i], units[i], []] self.data.append(new_data) if self.ui.radioButton_ppms.isChecked(): for i in range(0, len(first_data)): if first_data[i] != '': self.data[item][2].append(first_data[i]) item += 1 length = item while True: val = [] lines = fp.readline().replace("\n", "") if lines == '': break values = lines.split(',') for i in range(0, len(values)): if values[0] != 'Measurement was Aborted': if values[i] != '': val.append(values[i]) if self.ui.radioButton_ppms.isChecked(): if len(val) < length: break for i in range(0, len(val)): self.data[i][2].append(val[i]) self.ui.groupBox_plot.setEnabled(True) self.ui.lineEdit_condition2.setText('Ready to Plot.') self.ui.label_11.setEnabled(True) self.ui.comboBox_recent.setEnabled(True) self.ui.pushButton_recent.setEnabled(True) def Open_Recent(self): pass def Choose2(self): self.x_value = 0 self.y_value = 0 self.x_value = self.ui.comboBox_x.currentIndex() self.y_value = self.ui.comboBox_y.currentIndex() xaxis = self.data[self.x_value][0] xunit = self.data[self.x_value][1] yaxis = self.data[self.y_value][0] yunit = self.data[self.y_value][1] self.ui.lineEdit_x.setText(xaxis + ' (' + xunit + ')') self.ui.lineEdit_y.setText(yaxis + ' (' + yunit + ')') self.ui.lineEdit_name.setText(yaxis + ' vs ' + xaxis) self.ui.pushButton_plot.setEnabled(True) self.Plot() def Plot(self): self.reset_plot() self.axes.plot(self.data[self.x_value][2], self.data[self.y_value][2], marker='.', linestyle=':') self.axes.set_title(self.ui.lineEdit_name.text()) self.axes.set_xlabel(self.ui.lineEdit_x.text()) self.axes.set_ylabel(self.ui.lineEdit_y.text()) self.ui.mplwidget.draw() self.ui.lineEdit_condition2.setText('Plot successfully.') def reset_plot(self): self.ui.mplwidget.figure.clear() self.axes = self.ui.mplwidget.figure.add_subplot(111) def closeEvent(self, question): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) # If your answer is "yes", then quit if reply == QMessageBox.Yes: question.accept() # If your answer is "no", then get back else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas_general = FigureCanvas(self.ui.mplwidget_general.figure) self.canvas_general.setParent(self.ui.widget_general) # We need the toolbar widget for the canvas self.mpl_toolbar_general = NavigationToolbar(self.canvas_general, self.ui.widget_general) self.canvas_import = FigureCanvas(self.ui.mplwidget_import.figure) self.canvas_import.setParent(self.ui.widget_import) # This is the toolbar widget for the import canvas self.mpl_toolbar_import = NavigationToolbar(self.canvas_import, self.ui.widget_import) self.canvas_analysis = FigureCanvas(self.ui.mplwidget_analysis.figure) self.canvas_analysis.setParent(self.ui.widget_analysis) # This is the toolbar widget for the scan canvas self.mpl_toolbar_analysis = NavigationToolbar(self.canvas_analysis, self.ui.widget_analysis) self.canvas_ct_analysis = FigureCanvas( self.ui.mplwidget_ct_analysis.figure) self.canvas_ct_analysis.setParent(self.ui.widget_ct_analysis) # This is the toolbar widget for the scan canvas self.mpl_toolbar_ct_analysis = NavigationToolbar( self.canvas_ct_analysis, self.ui.widget_ct_analysis) self.canvas_vt_analysis = FigureCanvas( self.ui.mplwidget_vt_analysis.figure) self.canvas_vt_analysis.setParent(self.ui.widget_vt_analysis) # This is the toolbar widget for the scan canvas self.mpl_toolbar_vt_analysis = NavigationToolbar( self.canvas_vt_analysis, self.ui.widget_vt_analysis) # Create the QVBoxLayout object and add the widget into the layout vbox_general = QVBoxLayout() # The matplotlib canvas vbox_general.addWidget(self.canvas_general) # The matplotlib toolbar vbox_general.addWidget(self.mpl_toolbar_general) self.ui.widget_general.setLayout(vbox_general) # Create the QVBoxLayout object and add the widget into the Layout vbox_import = QVBoxLayout() # The matplotlib canvas vbox_import.addWidget(self.canvas_import) # The matplotlib toolbar vbox_import.addWidget(self.mpl_toolbar_import) self.ui.widget_import.setLayout(vbox_import) # Create the QVBoxLayout object and add the widget into the Layout vbox_analysis = QVBoxLayout() # The matplotlib canvas vbox_analysis.addWidget(self.canvas_analysis) # The matplotlib toolbar vbox_analysis.addWidget(self.mpl_toolbar_analysis) self.ui.widget_analysis.setLayout(vbox_analysis) # Create the QVBoxLayout object and add the widget into the Layout vbox_ct_analysis = QVBoxLayout() # The matplotlib canvas vbox_ct_analysis.addWidget(self.canvas_ct_analysis) # The matplotlib toolbar vbox_ct_analysis.addWidget(self.mpl_toolbar_ct_analysis) self.ui.widget_ct_analysis.setLayout(vbox_ct_analysis) # Create the QVBoxLayout object and add the widget into the Layout vbox_vt_analysis = QVBoxLayout() # The matplotlib canvas vbox_vt_analysis.addWidget(self.canvas_vt_analysis) # The matplotlib toolbar vbox_vt_analysis.addWidget(self.mpl_toolbar_vt_analysis) self.ui.widget_vt_analysis.setLayout(vbox_vt_analysis) # Connect the mplwidget with canvas self.ui.mplwidget_general = self.canvas_general self.ui.mplwidget_import = self.canvas_import self.ui.mplwidget_analysis = self.canvas_analysis self.ui.mplwidget_ct_analysis = self.canvas_ct_analysis self.ui.mplwidget_vt_analysis = self.canvas_vt_analysis self.connect(self.ui.actionArray_Builder, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(0)) self.connect(self.ui.actionKeithley_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(1)) self.connect(self.ui.actionAgilent_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(2)) self.connect(self.ui.actionLockIn_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(3)) self.connect(self.ui.actionResonant_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(4)) self.Array_Builder_programs = Array_Builder(main=self, ui=self.ui) # Connect buttons in the General Array tab # self.connect(self.ui.pushButton_plot, SIGNAL('clicked()'), self.Array_Builder_programs.Plot_general) # self.connect(self.ui.pushButton_clear, SIGNAL('clicked()'), self.Array_Builder_programs.Clear) # self.connect(self.ui.pushButton_save, SIGNAL('clicked()'), self.Array_Builder_programs.Save) # self.connect(self.ui.pushButton_browse_save, SIGNAL('clicked()'), self.Array_Builder_programs.Browse_save) self.Keithley_programs = Keithley(main=self, ui=self.ui) self.Keithley_programs.Refresh_visa() # Connect buttons in the Keithely tab # self.connect(self.ui.pushButton_browse_keithley, SIGNAL('clicked()'), self.Keithley_programs.Browse_keithley) # self.connect(self.ui.pushButton_import_keithley, SIGNAL('clicked()'), self.Keithley_programs.Import_keithley) # self.connect(self.ui.pushButton_close_keithley, SIGNAL('clicked()'), self.Keithley_programs.Close_keithley) # self.connect(self.ui.pushButton_select_keithley, SIGNAL('clicked()'), self.Keithley_programs.Select_keithley) # self.connect(self.ui.pushButton_scan_keithley, SIGNAL('clicked()'), self.Keithley_programs.Scan_keithley) # self.connect(self.ui.pushButton_pause_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.pause) # self.connect(self.ui.pushButton_stop_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.stop) # self.connect(self.ui.pushButton_clear_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.Clear_keithley) # self.connect(self.ui.pushButton_copy_keithley, SIGNAL('clicked()'), self.CopyData) # self.connect(self.ui.pushButton_fit_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.Fit) # self.connect(self.ui.radioButton_voltage_keithley, SIGNAL("clicked()"), lambda : self.ui.tabWidget_scan_keithley.setCurrentIndex(0)) # self.connect(self.ui.radioButton_timescan_keithley, SIGNAL("clicked()"), self.Keithley_programs.collect_data_thread.Pre_MPL_Plot) # self.connect(self.ui.radioButton_stepscan_keithley, SIGNAL("clicked()"), self.Keithley_programs.collect_data_thread.Pre_MPL_Plot) # self.connect(self.Keithley_programs.collect_data_thread, SIGNAL("plot"), self.Keithley_programs.Plot_data) # self.connect(self.Keithley_programs.collect_data_thread, SIGNAL("mpl_plot"), self.Keithley_programs.Plot_analysis) # self.connect(self.Keithley_programs.collect_data_thread, SIGNAL("data_available"), self.Keithley_programs.Pre_save) # self.connect(self.Keithley_programs.collect_data_thread, SIGNAL("clear_plot"), self.Keithley_programs.Clear_plot) self.Values = [] self.Step = [] self.Peak = [] self.round = 0 self.new_start = 0 self.ui.lineEdit_directory_save.setText(os.getcwd()) #Agilent_Yokogawa self.canvas_import_ay = FigureCanvas( self.ui.mplwidget_import_ay.figure) self.canvas_import_ay.setParent(self.ui.widget_import_ay) # This is the toolbar widget for the import canvas self.mpl_toolbar_import_ay = NavigationToolbar( self.canvas_import_ay, self.ui.widget_import_ay) #Agilent_Yokogawa self.canvas_analysis_ay = FigureCanvas( self.ui.mplwidget_analysis_ay.figure) self.canvas_analysis_ay.setParent(self.ui.widget_analysis_ay) # This is the toolbar widget for the import canvas self.mpl_toolbar_analysis_ay = NavigationToolbar( self.canvas_analysis_ay, self.ui.widget_analysis_ay) # Create the QVBoxLayout object and add the widget into the Layout vbox_import_ay = QVBoxLayout() # The matplotlib canvas vbox_import_ay.addWidget(self.canvas_import_ay) # The matplotlib toolbar vbox_import_ay.addWidget(self.mpl_toolbar_import_ay) self.ui.widget_import_ay.setLayout(vbox_import_ay) # Create the QVBoxLayout object and add the widget into the Layout vbox_analysis_ay = QVBoxLayout() # The matplotlib canvas vbox_analysis_ay.addWidget(self.canvas_analysis_ay) # The matplotlib toolbar vbox_analysis_ay.addWidget(self.mpl_toolbar_analysis_ay) self.ui.widget_analysis_ay.setLayout(vbox_analysis_ay) # Connect the mplwidget with canvass self.ui.mplwidget_import_ay = self.canvas_import_ay self.ui.mplwidget_analysis_ay = self.canvas_analysis_ay # Connect buttons in the Agilent Yokogawa tab self.Agilent_Yokogawa_programs = Agilent_Yokogawa(self.ui) self.connect(self.ui.startButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.start) self.connect(self.ui.stopButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.stop) #self.connect(self.action_timer, SIGNAL("timeout()"), self.Agilent_Yokogawa_programs.action) self.connect(self.ui.pushButton_browse_ay, SIGNAL('clicked()'), self.Agilent_Yokogawa_programs.Browse_ay) self.connect(self.ui.pushButton_import_ay, SIGNAL('clicked()'), self.Agilent_Yokogawa_programs.Import_ay) self.connect(self.ui.pushButton_copy_ay, SIGNAL('clicked()'), self.Copy_ay) self.connect(self.ui.selectVisaButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.select_visa) self.connect(self.ui.updateVisaButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.update_visa) self.connect(self.ui.closeVisaButton0, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.close_visa0) self.connect(self.ui.closeVisaButton1, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.close_visa1) self.connect(self.Agilent_Yokogawa_programs.collectDataThread, SIGNAL("plot"), self.Agilent_Yokogawa_programs.plotData) self.connect(self.Agilent_Yokogawa_programs.collectDataThread, SIGNAL("analyse"), self.Agilent_Yokogawa_programs.analyse) self.connect(self.ui.browseButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.browse) self.connect(self.ui.saveButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.save) self.ui.mplwidget_analysis_ay.figure.canvas.mpl_connect( 'button_release_event', self.Agilent_Yokogawa_programs.slope) #Connects the buttons in the Resonant Sweeper Tab #self.Resonant_programs = Resonance_Sweep(main = self, ui = self.ui) self.Resonant_Sweeper_functions = Resonance_Sweep(main=self, ui=self.ui) self.Resonant_Sweeper_functions.update_visa() self.connect(self.ui.pushButtonSelectRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.choose_visa) self.connect(self.ui.pushButtonUpdateRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.update_visa) self.connect(self.ui.pushButtonSourceSelectRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.choose_visa) self.connect(self.ui.pushButtonSourceUpdateRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.update_visa) self.connect(self.ui.pushButtonStartRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.start) self.connect(self.ui.pushButtonStopRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.stop) self.connect(self.ui.pushButtonPauseRS, SIGNAL("clicked()"), self.Resonant_Sweeper_functions.collectDataThread.pause) self.connect(self.Resonant_Sweeper_functions.collectDataThread, SIGNAL("plot"), self.Resonant_Sweeper_functions.plotData) self.connect(self.Resonant_Sweeper_functions.collectDataThread, SIGNAL("stop"), self.Resonant_Sweeper_functions.stop) #Connects the buttons in the Lock-In Program Tab self.Lock_In_programs = Lock_In(main=self, ui=self.ui) self.connect(self.ui.pushButtonSelectLI, SIGNAL("clicked()"), self.Lock_In_programs.choose_visa) self.connect(self.ui.pushButtonUpdateLI, SIGNAL("clicked()"), self.Lock_In_programs.update_visa) self.connect(self.ui.pushButtonStartLI, SIGNAL("clicked()"), self.Lock_In_programs.start) self.connect(self.ui.pushButtonStopLI, SIGNAL("clicked()"), self.Lock_In_programs.stop) self.connect(self.ui.pushButtonStopLI, SIGNAL("clicked()"), self.Lock_In_programs.final_append) self.connect(self.ui.pushButtonPauseLI, SIGNAL("clicked()"), self.Lock_In_programs.append_parameters) self.connect(self.ui.pushButtonPauseLI, SIGNAL("clicked()"), self.Lock_In_programs.collectDataThread.pause) self.connect(self.ui.pushButtonPauseLI, SIGNAL('clicked()'), self.Lock_In_programs.collectDataThread.appendSessionData) self.connect(self.ui.pushButtonStopLI, SIGNAL('clicked()'), self.Lock_In_programs.collectDataThread.appendSessionData) self.connect(self.ui.pushButtonPauseLI, SIGNAL('clicked()'), self.Lock_In_programs.tableAppend) self.connect(self.ui.pushButtonStopLI, SIGNAL('clicked()'), self.Lock_In_programs.tableAppend) self.connect(self.ui.pushButtonSaveLI, SIGNAL('clicked()'), self.Lock_In_programs.save) self.connect(self.ui.pushButtonBrowseLI, SIGNAL('clicked()'), self.Lock_In_programs.browse) self.connect(self.ui.pushButtonFolderSelectLI, SIGNAL('clicked()'), self.Lock_In_programs.select_name) self.connect(self.ui.radioButtonDateTimeLI, SIGNAL('clicked()'), self.Lock_In_programs.save_name) self.connect(self.ui.radioButtonCustomLI, SIGNAL('clicked()'), self.Lock_In_programs.save_name) self.connect(self.ui.radioButton_csvLI, SIGNAL('clicked()'), self.Lock_In_programs.save_type) self.connect(self.ui.radioButton_txtLI, SIGNAL('clicked()'), self.Lock_In_programs.save_type) self.connect(self.Lock_In_programs.collectDataThread, SIGNAL("plot"), self.Lock_In_programs.plotData) self.connect(self.Lock_In_programs.collectDataThread, SIGNAL("Begin_Save"), self.Lock_In_programs.pre_save) # This method is to transfer the array data from the Array Builder tab to the Keithley tab # If the array is valid, data_available is true and execute the data transfer # If the array is not valid, execution cannot be done def CopyDataFunc(self): if self.Array_Builder_programs.data_available == True: return self.Array_Builder_programs.Values else: return None def Copy_ay(self): try: #self.Array_Builder_programs.data_available == True: self.Agilent_Yokogawa_programs.Copy_ay( self.Array_Builder_programs.Values) self.ui.output.setText('Array has been copied and plotted.') except: self.ui.output.setText('No valid array to copy.') # Make sure the user is going to quit the program def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas_general = FigureCanvas(self.ui.mplwidget_general.figure) self.canvas_general.setParent(self.ui.widget_general) # We need the toolbar widget for the canvas self.mpl_toolbar_general = NavigationToolbar(self.canvas_general, self.ui.widget_general) # Create the QVBoxLayout object and add the widget into the layout vbox_general = QVBoxLayout() # The matplotlib canvas vbox_general.addWidget(self.canvas_general) # The matplotlib toolbar vbox_general.addWidget(self.mpl_toolbar_general) self.ui.widget_general.setLayout(vbox_general) # Connect the mplwidget with canvas self.ui.mplwidget_general = self.canvas_general self.connect(self.ui.actionArray_Builder, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(0)) self.connect(self.ui.actionKeithley_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(1)) self.connect(self.ui.actionAgilent_Single_scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(2)) self.connect(self.ui.actionKeithley_Stepper_Single_Scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(3)) self.connect(self.ui.actionKeithley_Gate_Sweep, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(4)) self.connect(self.ui.actionLockIn_Single_Scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(5)) self.connect(self.ui.actionResonant_Single_Scan, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(6)) self.connect(self.ui.actionSee_Visa_List, SIGNAL('triggered()'), lambda: self.ui.stackedWidget.setCurrentIndex(7)) self.List_Visas = List_Visas(main=self, ui=self.ui) self.Array_Builder_programs = Array_Builder(main=self, ui=self.ui) self.Keithley_programs = Keithley(main=self, ui=self.ui) self.Keithley_programs.Refresh_visa() self.Values = [] self.Step = [] self.Peak = [] self.round = 0 self.new_start = 0 self.ui.lineEdit_directory_save.setText(os.getcwd()) self.Agilent_Yokogawa_programs = Agilent_Yokogawa(main=self, ui=self.ui) self.Resonant_Sweeper_functions = Resonance_Sweep(main=self, ui=self.ui) self.Resonant_Sweeper_functions.update_visa() self.Lock_In_programs = Lock_In(main=self, ui=self.ui) self.KeithleyGateSweep = KeithleyGateSweep(main=self, ui=self.ui) # This method is to transfer the array data from the Array Builder tab to the Keithley tab # If the array is valid, data_available is true and execute the data transfer # If the array is not valid, execution cannot be done def CopyDataFunc(self): if self.Array_Builder_programs.data_available == True: return self.Array_Builder_programs.Values else: return None def copyData(self): try: if self.Array_Builder_programs.data_available: return self.Array_Builder_programs.Values self.ui.output.setText('Array has been copied and plotted.') except: return False self.ui.output.setText('No valid array to copy.') # Make sure the user is going to quit the program def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # When you open the window, the visas get refreshed self.refresh_visa() # This is to check whether user click start before they save self.data_check = False # We set up a QTimer variable called collect_timer. # It runs as a countdown clock that runs in the background and emits a timeout signal when it reaches 0. # Because this variable, we do not to use a for loop function for collecting and timing since the for loop can not be stopped in progress and can cause program frozen. # Also it allows the rest of the commands to run normally self.collect_timer = QTimer() # Set up guiqwt plot self.curve_item = make.curve([], [], color='r') self.ui.curvewidgetPlot.plot.add_item(self.curve_item) self.ui.curvewidgetPlot.plot.set_antialiasing(True) self.ui.curvewidgetPlot.plot.set_titles( "Agilent 34460A Digit Multimeter", "Time (s)", "Y-Axis") # The following connects the signals sent from an action on the GUI to a function that does something # When the button is clicked, it does the corresponding function self.connect(self.ui.pushButton_Select_Visa, SIGNAL("clicked()"), self.choose_visa) self.connect(self.ui.pushButton_Start, SIGNAL("clicked()"), self.start) self.connect(self.ui.pushButton_Stop, SIGNAL("clicked()"), self.stop) self.connect(self.ui.pushButton_Refresh, SIGNAL("clicked()"), self.refresh_visa) # This works as a clock running in the background, different functions can use this clock at the same time # It is better than .sleep() function because during the sleep time, the whole program is frozen and cannot do anything else # Everytime collect_timer gets the time_step, it sends a "timeout()" signal to the device and runs the collect function self.connect(self.collect_timer, SIGNAL("timeout()"), self.collect) self.connect(self.ui.comboBox_Meas_Type, SIGNAL("clicked()"), self.meas_type) # To give a click signal to the checkBox self.connect(self.ui.checkBox_Continue, SIGNAL("clicked()"), self.continue_check) # I add a slect button for the measurement type # Only if you click the button, the computer knows your measurement type # It shows the current measurement type and warning at the same time self.connect(self.ui.pushButton_Select_Measurement, SIGNAL("clicked()"), self.choose_meas) # To save the data self.connect(self.ui.pushButton_Save, SIGNAL("clicked()"), self.save) # To see and change the directory self.connect(self.ui.pushButton_Browse, SIGNAL("clicked()"), self.browse) # To choose a name folder to save file self.connect(self.ui.pushButton_Select_Directory, SIGNAL("clicked()"), self.select_directory) # To select name for the file, date and time or custom name entered by the user self.connect(self.ui.radioButton_Timename, SIGNAL("clicked()"), self.select_name) self.connect(self.ui.radioButton_Custom_Name, SIGNAL("clicked()"), self.select_name) # To select a file type, either .csv or .txt self.connect(self.ui.radioButton_csv, SIGNAL('clicked()'), self.select_type) self.connect(self.ui.radioButton_csv, SIGNAL('clicked()'), self.select_type) def refresh_visa(self): # Put all the visa resources into all_visas # If there is no visa resource at all, an error is returned. So this helps to prevent this kind of situation rm = visa.ResourceManager() try: # put the visa resources into a list all_visas = rm.list_resources() except: # return "No visas available" if there is no visa all_visas = 'No visa available right now.' # Remove the previous results in the comboBox self.ui.comboBox_All_Visas.clear() # Show all the visas in the combox for item in all_visas: self.ui.comboBox_All_Visas.addItem(item) # Click select button and choose the visa you want def choose_visa(self): self.visa_address = str(self.ui.comboBox_All_Visas.currentText()) rm = visa.ResourceManager() rm.list_resources() dmm = rm.open_resource(self.visa_address) valid = self.check_visa(dmm) if valid == True: self.ui.lineEdit_Error.setText("Everything goes well right now.") self.ui.label_CurrentVisa.setText(self.visa_address) elif valid == False: self.ui.lineEdit_Error.setText("Invalid visa address.") self.ui.label_CurrentVisa.setText('None') # This one is used to check whether the Agilent is connected correctly # It can be frequently used in the beginning of each function because if the Agilent is not linked it would report error when program running. def check_visa(self, dmm): try: dmm.ask('*IDN?') valid = True except: valid = False return valid def set_timestep(self): try: self.timestep = float(self.ui.lineEdit_Steps.text()) except: self.timestep = -1 if self.timestep <= 0: self.ui.lineEdit_Error.setText("Invalid time step input") # This is the number of points you want to collect # Also it is the number of points plotted on the figure def set_points(self): try: self.points = int(self.ui.lineEdit_Points.text()) print self.points except: self.points = -1 if self.points <= 0: self.ui.lineEdit_Error.setText("Invalid data points input") # Set two numpy arrays to store data and time def init_nparray(self): # self.data is used to store the response collected from the device self.data = np.array([0], dtype=float) # self.time is used to store the time each response is collected self.time = np.array([0], dtype=float) # To judge whether the checkBox is checked or not def continue_check(self): # If the checkBox is checked, return true and store it into cont_check if self.ui.checkBox_Continue.isChecked() == True: self.cont_check = True # If the checkBox hasn't been checked, return false and store it into cont_check elif self.ui.checkBox_Continue.isChecked() == False: self.cont_check = False # Return the result return self.cont_check # To vary from which types of measurements the user want to do def meas_type(self): self.meas = str(self.ui.comboBox_Meas_Type.currentText()) self.meas_type_check = True self.unit = 'V' if self.meas == 'None': self.meas_type_check = False elif self.meas == 'AC Current': self.command = 'MEAS:CURR:AC?' self.delay_correct = 0.5143113484 self.unit = 'A' elif self.meas == 'DC Current': self.command = 'MEAS:CURR:DC?' self.delay_correct = 0.4683864132 self.unit = 'A' elif self.meas == 'AC Voltage': self.command = 'MEAS:VOLT:AC?' self.delay_correct = 0.7460769785 elif self.meas == 'DC Voltage': self.command = 'MEAS:VOLT:DC?' self.delay_correct = 0.3845665093 elif self.meas == 'Resistance': self.unit = 'Ohms' self.command = 'MEAS:RES?' def choose_meas(self): self.meas_type() self.ui.label_CurrentMeasurement.setText(self.meas) if self.meas == 'AC Current': self.ui.label_Step_Reminder.setText( "Please enter a time step larger than 0.6s.") elif self.meas == 'DC Current': self.ui.label_Step_Reminder.setText( "Please enter a time step larger than 0.5s.") elif self.meas == 'AC Voltage': self.ui.label_Step_Reminder.setText( "Please enter a time step larger than 0.8s.") elif self.meas == 'DC Voltage': self.ui.label_Step_Reminder.setText( "Please enter a time step larger than 0.4s.") elif self.meas == 'None': self.ui.lineEdit_Error.setText("Please choose a valid command") def start(self): self.meas_type() # If user does not choose a meas_type if self.meas_type_check == False: self.ui.lineEdit_Error.setText("Please choose a valid command") self.meas_type() else: start_check = False # Collect the time steps entered by the user try: self.steps = float(self.ui.lineEdit_Steps.text()) # In case the user type something instead of a number except: self.steps = -1 # To judge whether the checkBox is checked or not self.continue_check() # If the user does not choose the continue measurement mode if self.cont_check == False: # Collect the points entered by the user in the edit line try: self.points = float(self.ui.lineEdit_Points.text()) # In case the user enters anything strange instead of a number except: self.points = -1 # If the user choose the continue mode, then the points do not matter # So set it to be a positive number such as 1 elif self.cont_check == True: self.points = 1 # Both the time steps and points are invalid if self.steps <= 0 and self.points <= 0: self.ui.lineEdit_Error.setText( "Invalid time steps and points input") # Only the time steps are invalid elif self.steps <= 0: self.ui.lineEdit_Error.setText("Invalid ti me steps input") # Only the points number are invalid elif self.points <= 0: self.ui.lineEdit_Error.setText("Invalid points input") # Both the time steps and points are valid else: start_check = True # This helps to check whther the input time step is in the range # If it is smaller than the minimum step, if self.steps < self.delay_correct: self.ui.lineEdit_Error.setText( "Your time step is too small. Please enter again.") start_check = False # Set the address of the digit multimeter # I do not use self.rm & self.dmm, so I need to put them here before the data collection rm = visa.ResourceManager() rm.list_resources() dmm = rm.open_resource(self.visa_address) # Check if everything is ready to start if start_check == True: valid = self.check_visa(dmm) # If the visa address is valid if valid == True: self.data_check = True # Tell user there is no error right now self.ui.lineEdit_Error.setText( "Everything goes well right now.") self.meas_type() # Set the numpy arrays for time and data self.init_nparray() # To calculate the time difference for system responce, set starting time t1 self.t1 = time.clock() # The default time step for collect_timer function is 1ms # So for 1 second, we have to multiply 1000 self.collect_timer.start(1000 * self.steps) # Run the collect function self.collect() # This is to collect the data from the device def collect(self): self.meas_type() self.t2 = time.clock() self.t = self.t2 - self.t1 self.t1 = time.clock() self.time_now = self.time[-1] + self.t collect_check = True rm = visa.ResourceManager() rm.list_resources() dmm = rm.open_resource(self.visa_address) try: reading = float(dmm.ask(self.command)) self.ui.lineEdit_Error.setText("Start to collect data and plot.") except: collect_check = False valid = self.check_visa(self.visa_address) if valid == True: self.ui.lineEdit_Error.setText("Invalid command syntax.") elif valid == False: self.ui.lineEdit_Error.setText("Connection disabled") # The problem here is that the numpy array is going to append automatically and in the end the length will surplus the number of points we want to plot # Therefore we have to make sure the points on the plot is less than or equal to the number we want if collect_check == True: self.continue_check() # If the continue checkBox is checked, run the collect until the user click stop self.data = np.append(self.data, reading) self.time = np.append(self.time, self.time_now) if self.cont_check == True: # We do not need the zero point, so we start plot from the first data self.x = self.time[1:] self.y = self.data[1:] elif self.cont_check == False: if len(self.time) > self.points: self.x = self.time[(len(self.time) - self.points):] else: self.x = self.time[1:] if len(self.data) > self.points: self.y = self.data[(len(self.data) - self.points):] else: self.y = self.data[1:] # To adjust the scale of the result # You do not want to see E-9 in the y-axis on the plot # Take absolute for all the data in the self.data in case some data are negative self.abs_y = np.absolute(self.y) # Set the first number in the self.abs_y First = self.abs_y[0] # Set a specific string for scale self.scale = '' self.out_y = self.y # The scale is E-3 if First < 1E-1 and First >= 1E-4: self.out_y = 1E3 * self.y self.scale = 'm' # The scale is E-6 elif First < 1E-4 and First >= 1E-7: self.out_y = 1E6 * self.y self.scale = 'u' # The scale is E-9 elif First < 1E-7 and First >= 1E-10: self.out_y = 1E9 * self.y self.scale = 'n' # Refresh the lables, especially the scally for yLable self.refresh_labels() # Sets the data in the guiqwt plot self.curve_item.set_data(self.x, self.out_y) self.curve_item.plot().replot() else: self.stop() # Refresh the lables when it starts to plot def refresh_labels(self): self.title = "Measure " + self.meas + " by Agilent 34460A Digit Multimeter" self.yLabel = self.meas + ' (' + self.scale + self.unit + ')' self.ui.curvewidgetPlot.plot.set_titles(self.title, "Time (s)", self.yLabel) def stop(self): self.collect_timer.stop() # This function let user to search for the OneDrive folder # The lineEdit_OneDrive has already shown the directory of OneDrive in this computer # However, the directory maybe different in different computer # So if someone use different pc or mac, they can use browse to find the OneDrive folder def browse(self): # The default OneDrive folder directory self.pre_directory = self.ui.lineEdit_OneDrive.text() # Open the browse window and let use to choose a new OneDrive directory self.directory = QFileDialog.getExistingDirectory( self, 'Select GoogleDrive Directory') # If there is a new directory, refresh the default OneDrive directory to this new one if self.directory != '': # Chang the '/' into '\' string.replace(self.directory, '/', '\\') # Switch the OneDrive to the new directory self.ui.lineEdit_OneDrive.setText(self.directory) # This function works to locate the address to the namefolder\Data def select_directory(self): # The previous directory self.pre_directory = str(self.ui.lineEdit_OneDrive.text()) # The name of the folder you want to save self.namefolder = str(self.ui.comboBox_Name_Folder.currentText()) self.select_directory_check = True if self.namefolder == 'None': self.ui.lineEdit_Error.setText( "Please choose a name folder to save file.") self.select_directory_check = False else: self.ui.lineEdit_Error.setText("Save to GoogleDrive\\" + self.namefolder + "\Data" + '\\' + self.date) # Set the file name # User can choose whether to save the data by date and time or their custom name def select_name(self): self.custom_name_check = True if self.ui.radioButton_DateTime.isChecked() == True: self.now = datetime.now() self.date = '%s-%s-%s' % (now.year, now.month, now.day) self.current_time = '%s.%s.%s' % (now.hour, now.minute, now.second) self.date_and_time = self.date + ' ' + self.current_time self.file_name = str(self.date_and_time) else: self.custom_name_check = False # Let user to choose which type of the file they want to save def select_type(self): self.select_type_check = True if self.ui.radioButton_csv.isChecked() == True: self.type = '.csv' self.divide = ',' self.form = '' elif self.ui.radioButton_txt.isChecked() == True: self.type = '.txt' self.divide = '\t' self.form = ' ' else: self.select_type_check = False # To save the data def save(self): self.select_directory() self.select_name() self.select_type() # Check whether user collect data before they save if self.data_check == False: self.ui.lineEdit_Error.setText("There is no data to be saved.") else: # If the user choose to type their own file name, set their input to be the file name if self.ui.radioButton_Custom_Name.isChecked() == True: self.custom_name_check = True self.file_name = str(self.ui.lineEdit_custom_Name.text()) # Check if the user choose one of the name folder to save # If they do not choose one, ask them to pick up a name folder if self.select_directory_check == False: self.ui.lineEdit_Error.setText( "Please pick up a name folder to save file.") else: # If user does not choose any of two radio buttons for the file name, ask them to choose one if self.custom_name_check == False: self.ui.lineEdit_Error.setText( "Please choose a kind of file name.") # If user input nothing in the text line for the custom file name, ask them to fill in a name elif self.file_name == '': self.ui.lineEdit_Error.setText( "Please enter a valid file name.") else: # If user does not choose any of two types of the file, ask them to choose one if self.select_type_check == False: self.ui.lineEdit_Error.setText( "Please select a file type to save.") else: self.path = self.pre_directory + '\\' + self.namefolder + '\\' + 'Data' + '\\' + self.date if not os.path.isdir(self.path): os.makedirs(self.path) # Complete the file adddress to OneDrive\NameFolder\Data self.name = self.pre_directory + '\\' + self.namefolder + '\\' + 'Data' + '\\' + self.date + '\\' + self.file_name + self.type # Open a file f = open(self.name, 'w') # Write the name in the first line f.write('Name: ' + self.namefolder + '\n') # Write the time in the second line f.write('Time: ' + str(datetime.now()) + '\n') # This is all the measurements Agilent can do in this program f.write('#' + self.divide + 'Time (s)' + self.divide + 'AC Current (A)' + self.divide + 'DC Current (A)' + self.divide + 'AC Voltage (V)' + self.divide + 'DC Voltage (V)' + self.divide + 'Resistance (Ohms)' + '\n') # The number of measurements n = 1 for i in range(1, len(self.data)): # self.divide is to divide the different types of data. For .csv file it's ',' while for .txt file it's '\t' # self.form is to make the data looks better if self.meas == 'AC Current': f.write( str(n) + self.divide + str(self.time[i]) + self.divide + str(self.data[i]) + '\n') elif self.meas == 'DC Current': f.write( str(n) + self.divide + str(self.time[i]) + self.divide + self.form + self.divide + str(self.data[i]) + '\n') elif self.meas == 'AC Voltage': f.write( str(n) + self.divide + str(self.time[i]) + self.divide + self.form + self.divide + self.form + self.divide + str(self.data[i]) + '\n') elif self.meas == 'DC Voltage': f.write( str(n) + self.divide + str(self.time[i]) + self.divide + self.form + self.divide + self.form + self.divide + self.form + self.divide + str(self.data[i]) + '\n') elif self.meas == 'Resistance': f.write( str(n) + self.divide + str(self.time[i]) + self.divide + self.form + self.divide + self.form + self.divide + self.form + self.divide + self.form + self.divide + str(self.data[i]) + '\n') n += 1 # Don't forget to close the file in the end f.close() self.ui.lineEdit_Error.setText( "Your file has been successfully saved!") # When you close the window, there will be a new window comes out and ask you "Do you want to quit the program?" def closeEvent(self, question): print question quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) # If your answer is "yes", then quit if reply == QMessageBox.Yes: question.accept() # If your answer is "no", then get back else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what is everything the user wants to be initialized when the class is called. # Here we shall define the trig functions to corresponding variables. # Note that the "self" variable means that the function is part of the class and can be called inside and outside the class.(Although __init__ is special.) def __init__(self, parent = None): self.collect_data_thread = Collect_data() # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to self.ui # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) self.connect(self.ui.pushButton_update_1, SIGNAL('clicked()'), lambda : self.Update("visa1", self.ui.comboBox_visa_1)) self.connect(self.ui.pushButton_update_2, SIGNAL('clicked()'), lambda : self.Update("visa2", self.ui.comboBox_visa_2)) self.connect(self.ui.pushButton_update_3, SIGNAL('clicked()'), lambda : self.Update("visa3", self.ui.comboBox_visa_3)) self.connect(self.ui.pushButton_update_4, SIGNAL('clicked()'), lambda : self.Update("visa4", self.ui.comboBox_visa_4)) self.connect(self.ui.pushButton_update_5, SIGNAL('clicked()'), lambda : self.Update("visa5", self.ui.comboBox_visa_5)) self.connect(self.ui.pushButton_update_6, SIGNAL('clicked()'), lambda : self.Update("visa6", self.ui.comboBox_visa_6)) self.connect(self.ui.pushButton_update_7, SIGNAL('clicked()'), lambda : self.Update("visa7", self.ui.comboBox_visa_7)) self.connect(self.ui.pushButton_update_8, SIGNAL('clicked()'), lambda : self.Update("visa8", self.ui.comboBox_visa_8)) self.connect(self.ui.pushButton_update_9, SIGNAL('clicked()'), lambda : self.Update("visa9", self.ui.comboBox_visa_9)) self.connect(self.ui.pushButton_update_10, SIGNAL('clicked()'), lambda : self.Update("visa10", self.ui.comboBox_visa_10)) self.connect(self.ui.pushButton_select_1, SIGNAL('clicked()'), lambda : self.Select("visa1", self.visa1, self.ui.comboBox_visa_1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_select_2, SIGNAL('clicked()'), lambda : self.Select("visa2", self.visa2, self.ui.comboBox_visa_2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_select_3, SIGNAL('clicked()'), lambda : self.Select("visa3", self.visa3, self.ui.comboBox_visa_3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_select_4, SIGNAL('clicked()'), lambda : self.Select("visa4", self.visa4, self.ui.comboBox_visa_4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_select_5, SIGNAL('clicked()'), lambda : self.Select("visa5", self.visa5, self.ui.comboBox_visa_5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_select_6, SIGNAL('clicked()'), lambda : self.Select("visa6", self.visa6, self.ui.comboBox_visa_6, self.ui.label_visa_6, [self.ui.pushButton_select_6, self.ui.pushButton_close_6])) self.connect(self.ui.pushButton_select_7, SIGNAL('clicked()'), lambda : self.Select("visa7", self.visa7, self.ui.comboBox_visa_7, self.ui.label_visa_7, [self.ui.pushButton_select_7, self.ui.pushButton_close_7])) self.connect(self.ui.pushButton_select_8, SIGNAL('clicked()'), lambda : self.Select("visa8", self.visa8, self.ui.comboBox_visa_8, self.ui.label_visa_8, [self.ui.pushButton_select_8, self.ui.pushButton_close_8])) self.connect(self.ui.pushButton_select_9, SIGNAL('clicked()'), lambda : self.Select("visa9", self.visa9, self.ui.comboBox_visa_9, self.ui.label_visa_9, [self.ui.pushButton_select_9, self.ui.pushButton_close_9])) self.connect(self.ui.pushButton_select_10, SIGNAL('clicked()'), lambda : self.Select("visa10", self.visa10, self.ui.comboBox_visa_10, self.ui.label_visa_10, [self.ui.pushButton_select_10, self.ui.pushButton_close_10])) self.connect(self.ui.pushButton_close_1, SIGNAL('clicked()'), lambda : self.Close("visa1", self.visa1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_close_2, SIGNAL('clicked()'), lambda : self.Close("visa2", self.visa2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_close_3, SIGNAL('clicked()'), lambda : self.Close("visa3", self.visa3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_close_4, SIGNAL('clicked()'), lambda : self.Close("visa4", self.visa4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_close_5, SIGNAL('clicked()'), lambda : self.Close("visa5", self.visa5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_close_6, SIGNAL('clicked()'), lambda : self.Close("visa6", self.visa6, self.ui.label_visa_6, [self.ui.pushButton_select_6, self.ui.pushButton_close_6])) self.connect(self.ui.pushButton_close_7, SIGNAL('clicked()'), lambda : self.Close("visa7", self.visa7, self.ui.label_visa_7, [self.ui.pushButton_select_7, self.ui.pushButton_close_7])) self.connect(self.ui.pushButton_close_8, SIGNAL('clicked()'), lambda : self.Close("visa8", self.visa8, self.ui.label_visa_8, [self.ui.pushButton_select_8, self.ui.pushButton_close_8])) self.connect(self.ui.pushButton_close_9, SIGNAL('clicked()'), lambda : self.Close("visa9", self.visa9, self.ui.label_visa_9, [self.ui.pushButton_select_9, self.ui.pushButton_close_9])) self.connect(self.ui.pushButton_close_10, SIGNAL('clicked()'), lambda : self.Close("visa10", self.visa10, self.ui.label_visa_10, [self.ui.pushButton_select_10, self.ui.pushButton_close_10])) self.connect(self.ui.pushButton_Start, SIGNAL('clicked()'), self.start) self.connect(self.ui.pushButton_Stop, SIGNAL('clicked()'), self.collect_data_thread.stop) self.connect(self.ui.pushButton_Pause, SIGNAL('clicked()'), self.collect_data_thread.pause) self.connect(self.collect_data_thread, SIGNAL("curve_plot"), self.curvePlots_update) self.connect(self.collect_data_thread, SIGNAL("print"), self.Print_data) self.connect(self.ui.textEdit, SIGNAL('textChanged ()'), lambda : self.start_font("C")) self.Update("visa1", self.ui.comboBox_visa_1) self.Update("visa2", self.ui.comboBox_visa_2) self.Update("visa3", self.ui.comboBox_visa_3) self.Update("visa4", self.ui.comboBox_visa_4) self.Update("visa5", self.ui.comboBox_visa_5) self.Update("visa6", self.ui.comboBox_visa_6) self.Update("visa7", self.ui.comboBox_visa_7) self.Update("visa8", self.ui.comboBox_visa_8) self.Update("visa9", self.ui.comboBox_visa_9) self.Update("visa10", self.ui.comboBox_visa_10) self.curve_1 = self.make_curveWidgets(self.ui.curvewidget_1, "r", "black", titles = ["Plot 1", "X (x)", "Y (y)"]) self.curve_2 = self.make_curveWidgets(self.ui.curvewidget_2, "r", "black", titles = ["Plot 2", "X (x)", "Y (y)"]) self.curve_3 = self.make_curveWidgets(self.ui.curvewidget_3, "r", "black", titles = ["Plot 3", "X (x)", "Y (y)"]) self.curve_4 = self.make_curveWidgets(self.ui.curvewidget_4, "r", "black", titles = ["Plot 4", "X (x)", "Y (y)"]) self.curve_5 = self.make_curveWidgets(self.ui.curvewidget_5, "r", "black", titles = ["Plot 5", "X (x)", "Y (y)"]) self.curve_6 = self.make_curveWidgets(self.ui.curvewidget_6, "r", "black", titles = ["Plot 6", "X (x)", "Y (y)"]) self.curve_7 = self.make_curveWidgets(self.ui.curvewidget_7, "r", "black", titles = ["Plot 7", "X (x)", "Y (y)"]) self.curve_8 = self.make_curveWidgets(self.ui.curvewidget_8, "r", "black", titles = ["Plot 8", "X (x)", "Y (y)"]) self.curve_9 = self.make_curveWidgets(self.ui.curvewidget_9, "r", "black", titles = ["Plot 9", "X (x)", "Y (y)"]) self.curve_10 = self.make_curveWidgets(self.ui.curvewidget_10, "r", "black", titles = ["Plot 10", "X (x)", "Y (y)"]) self.curve_11 = self.make_curveWidgets(self.ui.curvewidget_11, "r", "black", titles = ["Plot 11", "X (x)", "Y (y)"]) self.curve_12 = self.make_curveWidgets(self.ui.curvewidget_12, "r", "black", titles = ["Plot 12", "X (x)", "Y (y)"]) self.ui.mplwidget_1 = self.make_mplToolBar(self.ui.mplwidget_1, self.ui.widget_1) self.ui.mplwidget_2 = self.make_mplToolBar(self.ui.mplwidget_2, self.ui.widget_2) self.ui.mplwidget_3 = self.make_mplToolBar(self.ui.mplwidget_3, self.ui.widget_3) self.ui.mplwidget_4 = self.make_mplToolBar(self.ui.mplwidget_4, self.ui.widget_4) self.visa1 = None self.visa2 = None self.visa3 = None self.visa4 = None self.visa5 = None self.visa6 = None self.visa7 = None self.visa8 = None self.visa9 = None self.visa10 = None # Set the visa names of the tabWidget # font = QFont() # font.setPointSize(8) # self.ui.tabWidget_visa.setFont(font) # self.ui.tabWidget_visa.setTabText(0, "Visa Name 1") # self.ui.tabWidget_visa.setTabText(1, "Visa Name 2") # self.ui.tabWidget_visa.setTabText(2, "Visa Name 3") # self.ui.tabWidget_visa.setTabText(3, "Visa Name 4") # self.ui.tabWidget_visa.setTabText(4, "Visa Name 5") # self.ui.tabWidget_visa.setTabText(5, "Visa Name 6") # self.ui.tabWidget_visa.setTabText(6, "Visa Name 7") # self.ui.tabWidget_visa.setTabText(7, "Visa Name 8") # self.ui.tabWidget_visa.setTabText(8, "Visa Name 9") # self.ui.tabWidget_visa.setTabText(8, "Visa Name 10") # Input parameters by string # Remember to keep the last one as "Comments: ..." so that the program could see that as an end. self.input_string = [] # self.input_string.append("00 Parameter: 1\n") # self.input_string.append("01 Parameter: 1\n") # self.input_string.append("02 Parameter: 1\n") # self.input_string.append("03 Parameter: 1\n") # self.input_string.append("04 Parameter: 1\n") # self.input_string.append("05 Parameter: 1\n") # self.input_string.append("06 Parameter: 1\n") # self.input_string.append("07 Parameter: 1\n") # self.input_string.append("08 Parameter: 1\n") # self.input_string.append("09 Parameter: 1\n") # self.input_string.append("10 Parameter: 1\n") # self.input_string.append("11 Parameter: 1\n") # self.input_string.append("12 Parameter: 1\n") # self.input_string.append("13 Comments: ") self.start_font("C") try: file_par = open("parameters.txt", "r") input_string_print = file_par.read() file_par.close() except: input_string_print = "" for st_i in self.input_string: input_string_print = input_string_print + st_i font = QFont() font.setPointSize(8) self.ui.textEdit.setFont(font) self.ui.textEdit.setText(input_string_print) self.inputted_data = [] self.array_sweep = [] def start_font(self, status): if status == "C": font = QFont() font.setPointSize(8) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Check Array") elif status == "S": font = QFont() font.setPointSize(12) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Start") def Update(self, signal, comboBoxVisa): rm = visa.ResourceManager() try: alls = rm.list_resources() except: alls = "No Visa Available." if signal == "visa1": self.ui.comboBox_visa_1.clear() elif signal == "visa2": self.ui.comboBox_visa_2.clear() elif signal == "visa3": self.ui.comboBox_visa_3.clear() elif signal == "visa4": self.ui.comboBox_visa_4.clear() elif signal == "visa5": self.ui.comboBox_visa_5.clear() elif signal == "visa6": self.ui.comboBox_visa_6.clear() elif signal == "visa7": self.ui.comboBox_visa_7.clear() elif signal == "visa8": self.ui.comboBox_visa_8.clear() elif signal == "visa9": self.ui.comboBox_visa_9.clear() elif signal == "visa10": self.ui.comboBox_visa_10.clear() for temp in alls: if signal == "visa1": self.ui.comboBox_visa_1.addItem(temp) elif signal == "visa2": self.ui.comboBox_visa_2.addItem(temp) elif signal == "visa3": self.ui.comboBox_visa_3.addItem(temp) elif signal == "visa4": self.ui.comboBox_visa_4.addItem(temp) elif signal == "visa5": self.ui.comboBox_visa_5.addItem(temp) elif signal == "visa6": self.ui.comboBox_visa_6.addItem(temp) elif signal == "visa7": self.ui.comboBox_visa_7.addItem(temp) elif signal == "visa8": self.ui.comboBox_visa_8.addItem(temp) elif signal == "visa9": self.ui.comboBox_visa_9.addItem(temp) elif signal == "visa10": self.ui.comboBox_visa_10.addItem(temp) def Select(self, signal, visa_chosen, comboBoxVisa, lineEditVisa, selectClose, baud = None): visa_address = str(comboBoxVisa.currentText()) rm = visa.ResourceManager() rm.list_resources() if baud == None: inst = rm.open_resource(visa_address) else: inst = rm.open_resource(visa_address, baud_rate = baud) visa_check = self.Check(inst) if visa_check == True: self.ui.label_condition.setText("Visa is selected succefully!") visa_name = inst.query("*IDN?") name_list = visa_name.split(',') first_name = name_list[0] if signal == "visa1": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa1 = inst elif signal == "visa2": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa2 = inst elif signal == "visa3": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa3 = inst elif signal == "visa4": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa4 = inst elif signal == "visa5": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa5 = inst elif signal == "visa6": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa6 = inst elif signal == "visa7": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa7 = inst elif signal == "visa8": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa8 = inst elif signal == "visa9": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa9 = inst elif signal == "visa10": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa10 = inst elif visa_check == False: self.ui.label_condition.setText("Invalid visa address.") lineEditVisa.setText("None.") visa_chosen = False def Close(self, signal, visa_chosen, lineEditVisa, selectClose): self.ui.label_condition.setText('Visa address is closed') lineEditVisa.setText('') selectClose[0].setEnabled(True) selectClose[1].setEnabled(False) if signal == "visa1": visa_chosen.close() self.visa1 = None elif signal == "visa2": visa_chosen.close() self.visa2 = None elif signal == "visa3": visa_chosen.close() self.visa3 = None elif signal == "visa4": visa_chosen.close() self.visa4 = None elif signal == "visa5": visa_chosen.close() self.visa5 = None elif signal == "visa6": visa_chosen.close() self.visa6 = None elif signal == "visa7": visa_chosen.close() self.visa7 = None elif signal == "visa8": visa_chosen.close() self.visa8 = None elif signal == "visa9": visa_chosen.close() self.visa9 = None elif signal == "visa10": visa_chosen.close() self.visa10 = None def Check(self, inst): try: inst.ask("*IDN?") valid = True except: valid = False return valid def make_curveWidgets(self, curvewidget, color, markerColor, titles): curve_temp = make.curve([], [], color = color, marker = "o", markerfacecolor = markerColor, markersize = 5) curvewidget.plot.add_item(curve_temp) curvewidget.plot.set_antialiasing(True) curvewidget.plot.set_titles(titles[0], titles[1], titles[2]) return curve_temp def make_mplToolBar(self, mplwidget, widget): canvas_mpl = FigureCanvas(mplwidget.figure) canvas_mpl.setParent(widget) # This is the toolbar widget for the import canvas mpl_toolbar = NavigationToolbar(canvas_mpl, mplwidget) vbox_ = QVBoxLayout() # The matplotlib canvas vbox_.addWidget(canvas_mpl) # The matplotlib toolbar vbox_.addWidget(mpl_toolbar) widget.setLayout(vbox_) return canvas_mpl def mplPlots(self): self.ui.tabWidget.setCurrentIndex(1) self.ui.mplwidget_1.draw() self.ui.mplwidget_2.draw() self.ui.mplwidget_3.draw() self.ui.mplwidget_4.draw() def plot_reset(self, axes, mplwidget): mplwidget.figure.clear() axes = mplwidget.figure.add_subplot(111) return axes def plot_data(self, axes, x, y, titles, mplwidget): axes = self.plot_reset(axes, mplwidget) axes.plot(x, y, marker = '.', linestyle = '-') axes.grid() axes.set_title(titles[0]) axes.set_xlabel(titles[1]) axes.set_ylabel(titles[2]) mplwidget.draw() def start(self): instruments = [self.visa1, self.visa2, self.visa3, self.visa4, self.visa5] curves = [self.curve_1, self.curve_2, self.curve_3, self.curve_4] curveWidgets =[self.ui.curvewidget_1, self.ui.curvewidget_2, self.ui.curvewidget_3, self.ui.curvewidget_4] go_on = True inputted_string = str(self.ui.textEdit.toPlainText()) input_data = inputted_string.split("Comments:") comments = input_data[1] input_data = input_data[0].split("\n") inputted_data = [] for i in range(0, len(input_data)): for j in range(0, len(self.input_string)): if len(input_data[i].split(self.input_string[j].split(":")[0])) > 1: inputted_data.append(input_data[i].split(self.input_string[j].split(":")[0])[1].replace(":", "").replace(" ", "")) print inputted_data #Make Array array_start = float(inputted_data[1]) array_step = float(inputted_data[3]) array_stop = float(inputted_data[4]) double_lin = inputted_data[5].upper() if array_start < array_stop: array_1 = numpy.arange(array_start, array_stop + array_step, array_step) elif array_start > array_stop: array_1 = numpy.arange(array_stop, array_start + array_step, array_step)[::-1] if double_lin == "Y": array_2 = array_1[::-1] array_sweep = numpy.append(array_1, array_2) else: array_sweep = array_1 run_program = True for i in range(0, len(inputted_data)): try: if self.inputted_data[i] != inputted_data[i]: run_program = False self.start_font("C") except: run_program = False self.start_font("C") for i in range(0, len(array_sweep)): try: if self.array_sweep[i] != array_sweep[i]: run_program = False self.start_font("C") except: run_program = False self.start_font("C") if not run_program: self.inputted_data = inputted_data self.array_sweep = array_sweep self.ui.curvewidget_1.plot.set_titles("Magnetic Field Steps", "Steps", "Field (T)") self.curve_1.set_data(range(0, len(self.array_sweep)), self.array_sweep) self.ui.curvewidget_1.plot.do_autoscale() self.curve_1.plot().replot() self.start_font("S") elif run_program: if str(self.ui.pushButton_Start.text()) == "Start": self.start_font("C") self.collect_data_thread.input(self.ui, instruments, curves, curveWidgets, go_on, inputted_data, comments, array_sweep, inputted_string, self.input_string) else: self.start_font("S") def curvePlots_update(self, curveInfo): curveWidget = curveInfo[0] curve = curveInfo[1] curveWidget.plot.do_autoscale() curve.plot().replot() def Print_data(self, display_text): font = QFont() font.setPointSize(8) self.ui.textEditDisplay.setFont(font) self.ui.textEditDisplay.setText(display_text) def Switch_scale(self, num): temp = abs(num) if temp >= 1E9: scale = [1E-9, "G"] elif temp >= 1E6 and temp < 1E9: scale = [1E-6, "M"] elif temp >= 1E3 and temp < 1E6: scale = [1E-3, "k"] elif temp >= 1 and temp < 1000: scale = [1, ""] elif temp >= 1E-3 and temp < 1: scale = [1E3, "m"] elif temp >= 1E-6 and temp < 1E-3: scale = [1E6, "u"] elif temp >= 1E-9 and temp < 1E-6: scale = [1E9, "n"] elif temp < 1E-9: scale = [1E12, "p"] return scale def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas = FigureCanvas(self.ui.mplwidget.figure) self.canvas.setParent(self.ui.widget) # We need the toolbar widget for the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.ui.widget) # For the canvas. self.canvas_first_step = FigureCanvas( self.ui.mplwidget_first_step.figure) self.canvas_first_step.setParent(self.ui.widget_first_step) # We need the toolbar widget for the canvas self.mpl_toolbar_first_step = NavigationToolbar( self.canvas_first_step, self.ui.widget_first_step) # For the canvas. self.canvas_second_step = FigureCanvas( self.ui.mplwidget_second_step.figure) self.canvas_second_step.setParent(self.ui.widget_second_step) # We need the toolbar widget for the canvas self.mpl_toolbar_second_step = NavigationToolbar( self.canvas_second_step, self.ui.widget_second_step) # Create the QVBoxLayout object and add the widget into the layout vbox = QVBoxLayout() # The matplotlib canvas vbox.addWidget(self.canvas) # The matplotlib toolbar vbox.addWidget(self.mpl_toolbar) self.ui.widget.setLayout(vbox) # Create the QVBoxLayout object and add the widget into the layout vbox_first_step = QVBoxLayout() # The matplotlib canvas vbox_first_step.addWidget(self.canvas_first_step) # The matplotlib toolbar vbox_first_step.addWidget(self.mpl_toolbar_first_step) self.ui.widget_first_step.setLayout(vbox_first_step) # Create the QVBoxLayout object and add the widget into the layout vbox_second_step = QVBoxLayout() # The matplotlib canvas vbox_second_step.addWidget(self.canvas_second_step) # The matplotlib toolbar vbox_second_step.addWidget(self.mpl_toolbar_second_step) self.ui.widget_second_step.setLayout(vbox_second_step) # Connect the mplwidget with canvas self.ui.mplwidget = self.canvas # Connect the mplwidget with canvas self.ui.mplwidget_first_step = self.canvas_first_step # Connect the mplwidget with canvas self.ui.mplwidget_second_step = self.canvas_second_step self.connect(self.ui.pushButton_browse, SIGNAL('clicked()'), self.Browse) self.connect(self.ui.pushButton_change_name, SIGNAL('clicked()'), self.Plot) self.connect(self.ui.pushButton_openfile, SIGNAL('clicked()'), self.OpenFile) self.connect(self.ui.radioButton_qmd, SIGNAL('clicked()'), self.Choose_type) self.connect(self.ui.radioButton_ppms, SIGNAL('clicked()'), self.Choose_type) self.connect(self.ui.radioButton_frontpanel, SIGNAL('clicked()'), self.Choose_type) self.connect(self.ui.radioButton_zbridge, SIGNAL('clicked()'), self.Choose_type) self.connect(self.ui.radioButton_compressor, SIGNAL('clicked()'), self.Choose_type) self.connect(self.ui.pushButton_Plot, SIGNAL('clicked()'), self.Plot_ready) self.connect(self.ui.pushButton_recent, SIGNAL('clicked()'), self.Open_Recent) self.connect(self.ui.pushButton_plot_first_step, SIGNAL('clicked()'), self.plot1) self.connect(self.ui.pushButton_plot_second_step, SIGNAL('clicked()'), self.plot2) self.connect(self.ui.pushButton_find, SIGNAL('clicked()'), self.Find) self.first_round = True self.open_dir = '' self.open_files_number = 0 self.all_info = [] def Choose_type(self): if self.ui.radioButton_qmd.isChecked(): self.divider = 'Collected Data' self.ui.lineEdit_divider.setText(self.divider) self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_ppms.isChecked(): self.divider = '[Data]' self.ui.lineEdit_divider.setText(self.divider) self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_frontpanel.isChecked(): self.divider = 'frontpanel' self.ui.lineEdit_divider.setText('None') self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_zbridge.isChecked(): self.divider = '#' self.ui.lineEdit_divider.setText(self.divider) self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') elif self.ui.radioButton_compressor.isChecked(): self.divider = 'compressor' self.ui.lineEdit_divider.setText('None') self.ui.pushButton_browse.setEnabled(True) self.ui.lineEdit_condition1.setText('Please choose your file.') def Browse(self): self.open_recent = False prev_dir = os.getcwd() fileDir = QFileDialog.getOpenFileName(self, 'Select Folder to Save', prev_dir) if fileDir != '': open_dir = '' file_list = str(fileDir).split('/') for i in range(0, len(file_list) - 1): if i < len(file_list) - 1: open_dir += file_list[i] + '\\' elif i == len(file_list) - 1: open_dir += file_list[i] fileDir.replace('/', '\\') self.ui.lineEdit_address.setText(fileDir) self.ui.pushButton_openfile.setEnabled(True) self.ui.groupBox_labels.setEnabled(True) self.first_round = False filedir = str(fileDir).split('\\') self.file_name = filedir[len(filedir) - 1] print filedir else: self.ui.lineEdit_address.setText('None') self.ui.lineEdit_condition1.setText('Failed to Read File') def OpenFile(self): # Every you click the "Open File" button, the content in the plot combox is refreshed self.reset_plot() self.ui.mplwidget.draw() self.reset_first_step_plot() self.reset_second_step_plot() self.ui.comboBox_x.clear() self.ui.comboBox_y.clear() self.ui.comboBox_x_2.clear() self.ui.comboBox_y_2.clear() self.ui.comboBox_y_first_step.clear() self.ui.comboBox_y_second_step.clear() self.ui.comboBox_first.clear() self.ui.comboBox_second.clear() self.ui.lineEdit_x.setText('') self.ui.lineEdit_y.setText('') self.ui.lineEdit_name.setText('') self.ui.lineEdit_condition2.setText('') self.ui.lineEdit_minute.setText('') self.ui.lineEdit_date.setText('') labels = '' raw_parameters = [] units = [] parameters = [] new_parameters = [] self.data = [] new_data = [] first_data = [] item = 0 length = 0 # This count is the number of the reading loops for labels. If count is over 1000, that means there's something wrong with the divider line and it helps to stop the program count = 0 # It is false when program cannot find the line divider and runs the while loop 1000 times self.divider_found = True self.fileDir = self.ui.lineEdit_address.text() self.divider = str(self.ui.lineEdit_divider.text()) fp = open(self.fileDir) if self.ui.radioButton_frontpanel.isChecked(): labels = 'None' elif self.ui.radioButton_compressor.isChecked(): labels = fp.readline() else: while True: if count > 1000: self.ui.lineEdit_condition1.setText( 'Line divider is not found.') self.divider_found = False break line = fp.readline() #print 1, line linelist = line.split(',') if linelist[0].upper() == self.divider.upper() + '\n': break for i in range(0, len(linelist)): labels += linelist[i] count += 1 if self.divider_found == True: self.ui.textEdit_labels.setText(labels) parameters = fp.readline().replace("\n", '') if self.ui.radioButton_frontpanel.isChecked(): parameters = parameters.split('\t') for i in range(0, len(parameters)): if parameters[i] == 'P1': parameters[i] = 'Probe Line (P1)' elif parameters[i] == 'P2': parameters[i] = ' OVC Line (P2)' elif parameters[i] == 'P3': parameters[i] = 'IVC/Aux Port Line (P3)' elif parameters[i] == 'P4': parameters[i] = 'Turbo-to-S3 (P4)' elif parameters[i] == 'P5': parameters[i] = 'S3-to-traps (P5)' elif parameters[i] == 'P6': parameters[i] = '4He Dump (P6)' elif parameters[i] == 'P7': parameters[i] = '3He Dump (P7)' elif parameters[i] == 'MG2': parameters[i] = 'OVC Maxigauge (MG2)' elif parameters[i] == 'MG3': parameters[i] = 'Still Maxiguage (MG3)' elif parameters[i] == 'MG4': parameters[i] = 'IVC Maxiguage (MG4)' elif parameters[i] == 'MG5': parameters[i] = 'Probe Maxiguage (MG5)' elif self.ui.radioButton_compressor.isChecked(): parameters = parameters.split('\t') else: parameters = parameters.split(',') if self.ui.radioButton_ppms.isChecked(): lines = fp.readline().replace("\n", "") first_data = lines.split(",") for i in range(0, len(first_data)): par = [] if first_data[i] != '': par = parameters[i].split(' (') if len(par) == 2: units.append(par[1].replace(')', '')) elif len(par) == 1: units.append('1') new_parameters.append(par[0]) parameters = new_parameters elif self.ui.radioButton_qmd.isChecked(): units = fp.readline().replace("\n", '') units = units.split(",") elif self.ui.radioButton_frontpanel.isChecked(): for i in range(0, len(parameters)): units.append('') elif self.ui.radioButton_compressor.isChecked(): units.append('') new_parameters.append(parameters[0]) for i in range(1, len(parameters)): par = [] par = parameters[i].split('(') if par[1].replace(')', '') == 's': units.append('h') else: units.append(par[1].replace(')', '')) new_parameters.append(par[0]) parameters = new_parameters self.ui.comboBox_x_2.addItem('None') self.ui.comboBox_y_2.addItem('None') self.ui.comboBox_first.addItem('None') self.ui.comboBox_second.addItem('None') if self.ui.radioButton_compressor.isChecked(): for i in range(1, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y.addItem(parameters[i]) self.ui.comboBox_y_first_step.addItem(parameters[i]) self.ui.comboBox_y_second_step.addItem(parameters[i]) self.ui.comboBox_x_2.addItem(parameters[i]) self.ui.comboBox_y_2.addItem(parameters[i]) self.ui.comboBox_first.addItem(parameters[i]) self.ui.comboBox_second.addItem(parameters[i]) else: for i in range(0, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y.addItem(parameters[i]) self.ui.comboBox_y_first_step.addItem(parameters[i]) self.ui.comboBox_y_second_step.addItem(parameters[i]) self.ui.comboBox_x_2.addItem(parameters[i]) self.ui.comboBox_y_2.addItem(parameters[i]) self.ui.comboBox_first.addItem(parameters[i]) self.ui.comboBox_second.addItem(parameters[i]) for i in range(0, len(parameters)): new_data = [parameters[i], units[i], [], []] self.data.append(new_data) if self.ui.radioButton_ppms.isChecked(): for i in range(0, len(first_data)): if first_data[i] != '': self.data[item][2].append(first_data[i]) item += 1 length = item while True: val = [] lines = fp.readline().replace("\n", "") if lines == '': break if self.ui.radioButton_frontpanel.isChecked( ) or self.ui.radioButton_compressor.isChecked(): values = lines.split('\t') else: values = lines.split(',') for i in range(0, len(values)): if values[0] != 'Measurement was Aborted': if values[i] != '': val.append(values[i]) if self.ui.radioButton_ppms.isChecked(): if len(val) < length: break if self.ui.radioButton_frontpanel.isChecked(): date_info = val[0].split(' ') weekday = datetime.datetime.strptime( date_info[0], '%Y-%m-%d').strftime('%a') date = date_info[0] + ' ' + weekday + ' ' + date_info[1] self.data[0][3].append(date) self.data[0][3].append(self.convert_time(val[0])) for i in range(0, len(val)): self.data[i][2].append(val[i]) if self.ui.radioButton_frontpanel.isChecked(): set_zero = self.data[0][3][1] for i in range(0, len(self.data[0][2])): self.data[0][2][i] = ( (float(self.data[0][3][2 * i + 1]) - set_zero) / 3600) self.data[0][1] = 'hour' if self.open_recent == False: self.item_info = [] if self.ui.radioButton_frontpanel.isChecked(): self.item_info.append('frontpanel') elif self.ui.radioButton_compressor.isChecked(): self.item_info.append('compressor') else: self.item_info.append(self.divider) self.item_info.append(self.file_name) self.item_info.append(str(self.ui.lineEdit_address.text())) self.all_info.append(self.item_info) self.ui.comboBox_recent.addItem( self.all_info[len(self.all_info) - 1][1]) if self.ui.radioButton_compressor.isChecked(): self.date_transfer = [] date_tran = [] date_tran = self.data[0][2] for i in range(0, len(date_tran)): date_info = [] date_info = date_tran[i].split(' ') weekday = date_info[0] day = date_info[2] year = date_info[4] mon = date_info[1] if mon == 'Jan': mon = '01' elif mon == 'Feb': mon = '02' elif mon == 'Mar': mon = '03' elif mon == 'Apr': mon = '04' elif mon == 'May': mon = '05' elif mon == 'Jun': mon = '06' elif mon == 'Jul': mon = '07' elif mon == 'Aug': mon = '08' elif mon == 'Sep': mon = '09' elif mon == 'Oct': mon = '10' elif mon == 'Nov': mon = '11' elif mon == 'Dec': mon = '12' date = year + '-' + mon + '-' + day + ' ' + weekday + ' ' + date_info[ 3] self.date_transfer.append(date) #self.date_transfer.append(self.data[1][2]) self.data = self.data[1:] for i in range(0, len(self.data[0][2])): self.data[0][2][i] = float(self.data[0][2][i]) / 3600 self.ui.groupBox_plot.setEnabled(True) self.ui.groupBox_first.setEnabled(True) self.ui.groupBox_second.setEnabled(True) self.ui.lineEdit_condition2.setText('Ready to Plot.') self.ui.label_11.setEnabled(True) self.ui.comboBox_recent.setEnabled(True) self.ui.pushButton_recent.setEnabled(True) self.ui.comboBox_y_first_step.setEnabled(True) self.ui.pushButton_plot_first_step.setEnabled(True) self.ui.pushButton_plot_second_step.setEnabled(True) self.ui.comboBox_y_second_step.setEnabled(True) self.ui.label_14.setEnabled(True) self.ui.label_15.setEnabled(True) if self.ui.radioButton_frontpanel.isChecked( ) or self.ui.radioButton_compressor.isChecked(): self.ui.groupBox_date.setEnabled(True) def Open_Recent(self): file_number = self.ui.comboBox_recent.currentIndex() if self.all_info[file_number][0].upper() == '[Data]'.upper(): self.ui.radioButton_ppms.setChecked(True) self.ui.lineEdit_divider.setText('[Data]') self.divider = '[Data]' + '\n' self.ui.lineEdit_address.setText(self.all_info[file_number][2]) elif self.all_info[file_number][0].upper() == 'Collected Data'.upper(): self.ui.radioButton_qmd.setChecked(True) self.ui.lineEdit_divider.setText('Collected Data') self.divider = 'Collected Data' + '\n' self.ui.lineEdit_address.setText(self.all_info[file_number][2]) elif self.all_info[file_number][0].upper() == 'frontpanel'.upper(): self.ui.radioButton_frontpanel.setChecked(True) self.ui.lineEdit_divider.setText('') self.divider = self.all_info[file_number][1] + '\n' self.ui.lineEdit_address.setText(self.all_info[file_number][2]) self.ui.lineEdit_divider.setText('None') self.ui.lineEdit_condition1.setText( self.ui.comboBox_recent.currentText() + ' has been opened.') elif self.all_info[file_number][0].upper() == 'compressor'.upper(): self.ui.radioButton_compressor.setChecked(True) self.ui.lineEdit_divider.setText('') self.divider = self.all_info[file_number][1] + '\n' self.ui.lineEdit_address.setText(self.all_info[file_number][2]) self.ui.lineEdit_divider.setText('None') self.ui.lineEdit_condition1.setText( self.ui.comboBox_recent.currentText() + ' has been opened.') self.reset_plot() self.ui.mplwidget.draw() self.open_recent = True self.OpenFile() def Find(self): try: time = float(self.ui.lineEdit_minute.text()) if time <= self.data[0][2][0]: if self.ui.radioButton_frontpanel.isChecked(): self.ui.lineEdit_date.setText(self.data[0][3][0]) elif self.ui.radioButton_compressor.isChecked(): self.ui.lineEdit_date.setText(self.date_transfer[0]) elif time >= self.data[0][2][len(self.data[0][2]) - 1]: if self.ui.radioButton_frontpanel.isChecked(): self.ui.lineEdit_date.setText( self.data[0][3][2 * (len(self.data[0][2]) - 1)]) elif self.ui.radioButton_compressor.isChecked(): self.ui.lineEdit_date.setText( self.date_transfer[len(self.date_transfer) - 1]) else: item = 0 while self.data[0][2][item] - time < 0: item += 1 if abs(self.data[0][2][item - 1] - time) <= abs(self.data[0][2][item] - time): if self.ui.radioButton_frontpanel.isChecked(): self.ui.lineEdit_date.setText( self.data[0][3][2 * (item - 1)]) elif self.ui.radioButton_compressor.isChecked(): self.ui.lineEdit_date.setText(self.date_transfer[item - 1]) else: if self.ui.radioButton_frontpanel.isChecked(): self.ui.lineEdit_date.setText(self.data[0][3][2 * item]) elif self.ui.radioButton_compressor.isChecked(): self.ui.lineEdit_date.setText(self.date_transfer[item]) except ValueError: self.ui.lineEdit_date.setText('') self.ui.lineEdit_condition2.setText('Please enter valid time.') def Plot_ready(self): self.x_value = 0 self.y_value = 0 self.x_value = self.ui.comboBox_x.currentIndex() self.y_value = self.ui.comboBox_y.currentIndex() xaxis = self.data[self.x_value][0] xunit = self.data[self.x_value][1] yaxis = self.data[self.y_value][0] yunit = self.data[self.y_value][1] self.x2_value = 0 self.y2_value = 0 self.x2_value = self.ui.comboBox_x_2.currentIndex() - 1 self.y2_value = self.ui.comboBox_y_2.currentIndex() - 1 x2axis = self.data[self.x2_value][0] x2unit = self.data[self.x2_value][1] y2axis = self.data[self.y2_value][0] y2unit = self.data[self.y2_value][1] if self.x2_value == -1: self.ui.lineEdit_x.setText(xaxis + ' (' + xunit + ')') self.x_value = self.data[self.x_value][2] elif self.x2_value >= 0: self.ui.lineEdit_x.setText(xaxis + '/' + x2axis + ' (' + xunit + '/' + x2unit + ')') if self.ui.radioButton_x_divide.isChecked(): self.x_value = numpy.array( self.data[self.x_value][2], dtype='float') / numpy.array( self.data[self.x2_value][2], dtype='float') elif self.ui.radioButton_x_multiply.isChecked(): self.x_value = numpy.array( self.data[self.x_value][2], dtype='float') * numpy.array( self.data[self.x2_value][2], dtype='float') elif self.ui.radioButton_x_plus.isChecked(): self.x_value = numpy.array( self.data[self.x_value][2], dtype='float') + numpy.array( self.data[self.x2_value][2], dtype='float') elif self.ui.radioButton_x_minus.isChecked(): self.x_value = numpy.array( self.data[self.x_value][2], dtype='float') - numpy.array( self.data[self.x2_value][2], dtype='float') if self.ui.checkBox_x_value.isChecked(): self.x_value = numpy.absolute(self.x_value) if self.y2_value == -1: self.ui.lineEdit_y.setText(yaxis + ' (' + yunit + ')') self.y_value = self.data[self.y_value][2] elif self.y2_value >= 0: self.ui.lineEdit_y.setText(yaxis + '/' + y2axis + ' (' + yunit + '/' + y2unit + ')') if self.ui.radioButton_y_divide.isChecked(): self.y_value = numpy.array( self.data[self.y_value][2], dtype='float') / numpy.array( self.data[self.y2_value][2], dtype='float') elif self.ui.radioButton_x_multiply.isChecked(): self.y_value = numpy.array( self.data[self.y_value][2], dtype='float') * numpy.array( self.data[self.y2_value][2], dtype='float') elif self.ui.radioButton_x_plus.isChecked(): self.y_value = numpy.array( self.data[self.y_value][2], dtype='float') + numpy.array( self.data[self.y2_value][2], dtype='float') elif self.ui.radioButton_x_minus.isChecked(): self.y_value = numpy.array( self.data[self.y_value][2], dtype='float') - numpy.array( self.data[self.y2_value][2], dtype='float') if self.ui.checkBox_y_value.isChecked(): self.y_value = numpy.absolute(self.y_value) if self.x2_value == -1 and self.y2_value == -1: self.ui.lineEdit_name.setText(yaxis + ' vs. ' + xaxis) elif self.x2_value >= 0 and self.y2_value == -1: self.ui.lineEdit_name.setText(yaxis + ' vs. ' + xaxis + '/' + x2axis) elif self.x2_value == -1 and self.y2_value >= 0: self.ui.lineEdit_name.setText(yaxis + '/' + y2axis + ' vs. ' + xaxis) else: self.ui.lineEdit_name.setText(yaxis + '/' + y2axis + ' vs. ' + xaxis + '/' + x2axis) self.ui.pushButton_change_name.setEnabled(True) self.Plot() def Plot(self): self.reset_plot() self.axes.plot(self.x_value, self.y_value, marker='.', linestyle=':') self.axes.grid() self.axes.set_title(self.ui.lineEdit_name.text()) self.axes.set_xlabel(self.ui.lineEdit_x.text()) self.axes.set_ylabel(self.ui.lineEdit_y.text()) self.ui.mplwidget.draw() self.ui.lineEdit_condition2.setText('Plot successfully.') def plot1(self): y_value1 = self.ui.comboBox_y_first_step.currentIndex() y_value2 = self.ui.comboBox_first.currentIndex() - 1 y_axis1 = self.data[y_value1][0] y_axis2 = self.data[y_value2][0] y_unit1 = self.data[y_value1][1] y_unit2 = self.data[y_value2][1] yv1 = self.data[y_value1][2] yv2 = self.data[y_value2][2] xv = [] item = 0 for i in range(0, len(yv1)): xv.append(item) item += 1 if y_value2 == -1: y_value = yv1 y_name = y_axis1 + ' (' + y_unit1 + ')' name = y_axis1 + ' Steps' elif y_value2 >= 0: if self.ui.radioButton_first_divide.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') / numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' / ' + y_axis2 + ' (' + y_unit1 + ' / ' + y_unit2 + ')' name = y_axis1 + ' / ' + y_axis2 + ' Steps' elif self.ui.radioButton_first_multiply.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') * numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' * ' + y_axis2 + ' (' + y_unit1 + ' * ' + y_unit2 + ')' name = y_axis1 + ' * ' + y_axis2 + ' Steps' elif self.ui.radioButton_first_plus.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') + numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' + ' + y_axis2 + ' (' + y_unit1 + ' + ' + y_unit2 + ')' name = y_axis1 + ' + ' + y_axis2 + ' Steps' elif self.ui.radioButton_first_minus.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') - numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' - ' + y_axis2 + ' (' + y_unit1 + ' - ' + y_unit2 + ')' name = y_axis1 + ' - ' + y_axis2 + ' Steps' if self.ui.checkBox_first.isChecked(): y_value = numpy.absolute(y_value) self.reset_first_step_plot() self.axes_first_step.plot(xv, y_value, marker='.', linestyle=':') self.axes_first_step.grid() self.axes_first_step.set_title(name) self.axes_first_step.set_xlabel('Unit Step (1)') self.axes_first_step.set_ylabel(y_name) self.ui.mplwidget_first_step.draw() def plot2(self): y_value1 = self.ui.comboBox_y_second_step.currentIndex() y_value2 = self.ui.comboBox_second.currentIndex() - 1 y_axis1 = self.data[y_value1][0] y_axis2 = self.data[y_value2][0] y_unit1 = self.data[y_value1][1] y_unit2 = self.data[y_value2][1] yv1 = self.data[y_value1][2] yv2 = self.data[y_value2][2] xv = [] item = 0 for i in range(0, len(yv1)): xv.append(item) item += 1 if y_value2 == -1: y_value = yv1 y_name = y_axis1 + ' (' + y_unit1 + ')' name = y_axis1 + ' Steps' elif y_value2 >= 0: if self.ui.radioButton_second_divide.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') / numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' / ' + y_axis2 + ' (' + y_unit1 + ' / ' + y_unit2 + ')' name = y_axis1 + ' / ' + y_axis2 + ' Steps' elif self.ui.radioButton_second_multiply.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') * numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' * ' + y_axis2 + ' (' + y_unit1 + ' * ' + y_unit2 + ')' name = y_axis1 + ' * ' + y_axis2 + ' Steps' elif self.ui.radioButton_second_plus.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') + numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' + ' + y_axis2 + ' (' + y_unit1 + ' + ' + y_unit2 + ')' name = y_axis1 + ' + ' + y_axis2 + ' Steps' elif self.ui.radioButton_second_minus.isChecked(): y_value = numpy.array( self.data[y_value1][2], dtype='float') - numpy.array( self.data[y_value2][2], dtype='float') y_name = y_axis1 + ' - ' + y_axis2 + ' (' + y_unit1 + ' - ' + y_unit2 + ')' name = y_axis1 + ' - ' + y_axis2 + ' Steps' if self.ui.checkBox_second.isChecked(): y_value = numpy.absolute(y_value) self.reset_second_step_plot() self.axes_second_step.plot(xv, y_value, marker='.', linestyle=':') self.axes_second_step.grid() self.axes_second_step.set_title(name) self.axes_second_step.set_xlabel('Unit Step (1)') self.axes_second_step.set_ylabel(y_name) self.ui.mplwidget_second_step.draw() def reset_plot(self): self.ui.mplwidget.figure.clear() self.axes = self.ui.mplwidget.figure.add_subplot(111) def reset_first_step_plot(self): self.ui.mplwidget_first_step.figure.clear() self.axes_first_step = self.ui.mplwidget_first_step.figure.add_subplot( 111) def reset_second_step_plot(self): self.ui.mplwidget_second_step.figure.clear() self.axes_second_step = self.ui.mplwidget_second_step.figure.add_subplot( 111) def convert_time(self, d): date, times = d.split(" ") year, month, day = date.split("-") hour, minute, second = times.split(":") t = datetime.datetime(int(year), int(month), int(day), int(hour), int(minute), int(second)) t_sec = time.mktime(t.timetuple()) return t_sec def closeEvent(self, question): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) # If your answer is "yes", then quit if reply == QMessageBox.Yes: question.accept() # If your answer is "no", then get back else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what is everything the user wants to be initialized when the class is called. # Here we shall define the trig functions to corresponding variables. # Note that the "self" variable means that the function is part of the class and can be called inside and outside the class.(Although __init__ is special.) def __init__(self, parent = None): self.collect_data_thread = Collect_data() self.dsave_thread = Dynamic_Save_Thread() # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to self.ui # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) self.connect(self.ui.pushButton_update_1, SIGNAL('clicked()'), lambda : self.Update("visa1", self.ui.comboBox_visa_1)) self.connect(self.ui.pushButton_update_2, SIGNAL('clicked()'), lambda : self.Update("visa2", self.ui.comboBox_visa_2)) self.connect(self.ui.pushButton_update_3, SIGNAL('clicked()'), lambda : self.Update("visa3", self.ui.comboBox_visa_3)) self.connect(self.ui.pushButton_update_4, SIGNAL('clicked()'), lambda : self.Update("visa4", self.ui.comboBox_visa_4)) self.connect(self.ui.pushButton_select_1, SIGNAL('clicked()'), lambda : self.Select("visa1", self.visa1, self.ui.comboBox_visa_1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_select_2, SIGNAL('clicked()'), lambda : self.Select("visa2", self.visa2, self.ui.comboBox_visa_2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_select_3, SIGNAL('clicked()'), lambda : self.Select("visa3", self.visa3, self.ui.comboBox_visa_3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_select_4, SIGNAL('clicked()'), lambda : self.Select("visa4", self.visa4, self.ui.comboBox_visa_4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_close_1, SIGNAL('clicked()'), lambda : self.Close("visa1", self.visa1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_close_2, SIGNAL('clicked()'), lambda : self.Close("visa2", self.visa2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_close_3, SIGNAL('clicked()'), lambda : self.Close("visa3", self.visa3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_close_4, SIGNAL('clicked()'), lambda : self.Close("visa4", self.visa4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_Start, SIGNAL('clicked()'), self.start) self.connect(self.ui.pushButton_Stop, SIGNAL('clicked()'), self.collect_data_thread.stop) self.connect(self.ui.pushButton_Pause, SIGNAL('clicked()'), self.collect_data_thread.pause) self.connect(self.collect_data_thread, SIGNAL("curve_plot"), self.curvePlots_update) self.connect(self.collect_data_thread, SIGNAL("freq_update"), self.setup_plot) self.connect(self.collect_data_thread, SIGNAL("power_update"), self.setup_plot) self.connect(self.collect_data_thread, SIGNAL("print_value"), self.Print_data) self.connect(self.ui.checkBox_dsave, SIGNAL("clicked()"), self.Pre_dsave) self.connect(self.ui.textEdit, SIGNAL('textChanged ()'), lambda : self.start_font("C")) self.connect(self.ui.pushButton_dsave_browse, SIGNAL('clicked()'), self.Dsave_browse) self.Update("visa1", self.ui.comboBox_visa_1) self.Update("visa2", self.ui.comboBox_visa_2) self.Update("visa3", self.ui.comboBox_visa_3) self.Update("visa4", self.ui.comboBox_visa_4) self.curve_3 = self.make_curveWidgets(self.ui.curvewidget_3, "b", "blue", titles = ["RF Power", "Step", "Power (dBm)"]) self.curve_3_update = self.make_curveWidgets(self.ui.curvewidget_3, "red", "red", titles = ["RF Power", "Step", "Power (dBm)"]) self.curve_2_b = self.make_curveWidgets(self.ui.curvewidget_2, "black", "black", titles = ["Keithley", "Step", "Voltage (V)"]) self.curve_2_r = self.make_curveWidgets(self.ui.curvewidget_2, "red", "red", titles = ["Keithley", "Step", "Voltage (V)"]) self.curve_1 = self.make_curveWidgets(self.ui.curvewidget_1, "b", "blue", titles = ["Keithley", "Step", "Voltage (V)"]) self.curve_1_update = self.make_curveWidgets(self.ui.curvewidget_1, "red", "red", titles = ["Keithley", "Step", "Voltage (V)"]) self.Curve1 = self.make_curveWidgets(self.ui.curvewidget_13, "r", "black", titles = ["Plot 1", "X (x)", "Y (y)"]) self.Curve2 = self.make_curveWidgets(self.ui.curvewidget_14, "g", "black", titles = ["Plot 2", "X (x)", "Y (y)"]) self.Curve3 = self.make_curveWidgets(self.ui.curvewidget_15, "r", "black", titles = ["Plot 3", "X (x)", "Y (y)"]) self.Curve4 = self.make_curveWidgets(self.ui.curvewidget_16, "g", "black", titles = ["Plot 4", "X (x)", "Y (y)"]) self.visa1 = None self.visa2 = None self.visa3 = None self.visa4 = None self.setWindowTitle("Sweep with Lock-in without Magnetic") self.input_string = [] self.input_string.append("00 Run_Number: 01\n\n") self.input_string.append("01 Start Gate Voltage (V): 35\n") self.input_string.append("02 Step Gate Voltage (V): 0.1\n") self.input_string.append("03 03 End Gate Voltage (V): 0\n") self.input_string.append("04 Double Linear (y/n): n\n") self.input_string.append("05 Turn off Keithley (y/n): n\n") self.input_string.append("06 CurrBias Lock-in Sens: 20e-6\n") self.input_string.append("07 Reading wait time(s): .25\n\n") self.input_string.append("08 Current Bias Resistor: 1.009e9\n") self.input_string.append("09 Lock-in Output Voltage: 10\n") self.input_string.append("10 Additional Lock-in Volt Gain: 1\n\n") self.input_string.append("11 User: Vannucci\n") self.input_string.append("12 File Name: S-SiA0036-V_B1_leads\n") self.input_string.append("13 TimeStamp (y/n): y\n") self.input_string.append("14 Comments:\n\n") self.start_font("C") self.out0_1 = "None" self.out0_2 = "None" self.out0_3 = "None" self.out0_4 = "None" self.out1_0 = "None" self.out1_1 = "None" self.out1_2 = "None" self.out1_3 = "None" self.out2_0 = "None" self.out2_1 = "None" self.out2_2 = "None" self.out2_3 = "None" self.out3_0 = "None" self.out3_1 = "None" self.out3_2 = "None" self.out3_3 = "None" self.scale1_1 = [1, ""] self.scale1_2 = [1, ""] self.scale1_3 = [1, ""] self.scale2_1 = [1, ""] self.scale2_2 = [1, ""] self.scale2_3 = [1, ""] self.scale3_1 = [1, ""] self.scale3_2 = [1, ""] self.scale3_3 = [1, ""] self.Coil_Constant = 1E-3/9.1E-3 try: file_par = open("parameters.txt", "r") input_string_print = file_par.read() except: input_string_print = "" for st_i in self.input_string: input_string_print = input_string_print + st_i font = QFont() font.setPointSize(10) self.ui.textEdit.setFont(font) self.ui.textEdit.setText(input_string_print) self.inputted_data = [] self.array_sweep = [] rm = visa.ResourceManager() self.Visa_states = [] try: alls = rm.list_resources() for i in range(0, len(alls)): self.Visa_states.append([alls[i], True]) except: alls = "No Visa Available." def start_font(self, status): if status == "C": font = QFont() font.setPointSize(8) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Check Array") elif status == "S": font = QFont() font.setPointSize(12) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Start") def Update(self, signal, comboBoxVisa): rm = visa.ResourceManager() try: alls = rm.list_resources() except: alls = "No Visa Available." if signal == "visa1": self.ui.comboBox_visa_1.clear() elif signal == "visa2": self.ui.comboBox_visa_2.clear() elif signal == "visa3": self.ui.comboBox_visa_3.clear() elif signal == "visa4": self.ui.comboBox_visa_4.clear() for temp in alls: if signal == "visa1": self.ui.comboBox_visa_1.addItem(temp) elif signal == "visa2": self.ui.comboBox_visa_2.addItem(temp) elif signal == "visa3": self.ui.comboBox_visa_3.addItem(temp) elif signal == "visa4": self.ui.comboBox_visa_4.addItem(temp) # if signal == "visa1": # self.ui.comboBox_visa_1.addItem(alls[3]) # elif signal == "visa2": # self.ui.comboBox_visa_2.addItem(alls[0]) # elif signal == "visa3": # self.ui.comboBox_visa_3.addItem(alls[4]) # elif signal == "visa4": # self.ui.comboBox_visa_4.addItem(alls[1]) def Select(self, signal, visa_chosen, comboBoxVisa, lineEditVisa, selectClose, baud = None): visa_address = str(comboBoxVisa.currentText()) rm = visa.ResourceManager() rm.list_resources() if baud == None: inst = rm.open_resource(visa_address) else: inst = rm.open_resource(visa_address, baud_rate = baud) visa_check = self.Check(inst) if visa_check == True: visa_name = inst.query("*IDN?") name_list = visa_name.split(',') first_name = name_list[0] if signal == "visa1": if self.Ready(inst): lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa1 = inst self.Mark(inst, False) self.ui.label_condition.setText("Visa is selected succefully!") else: self.ui.label_condition.setText("Pick another Lock_In address") elif signal == "visa2": if self.Ready(inst): lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.visa2 = inst self.Mark(inst, False) self.ui.label_condition.setText("Visa is selected succefully!") else: self.ui.label_condition.setText("Pick another Keithley address") elif visa_check == False: self.ui.label_condition.setText("Invalid visa address.") lineEditVisa.setText("None.") visa_chosen = False def Ready(self, inst): temp = str(inst).split(' ') address = temp[len(temp) - 1] for i in range(0, len(self.Visa_states)): if self.Visa_states[i][0] == address: return self.Visa_states[i][1] return False def Mark(self, inst, bol): temp = str(inst).split(' ') address = temp[len(temp) - 1] for i in range(0, len(self.Visa_states)): if self.Visa_states[i][0] == address: self.Visa_states[i][1] = bol def Close(self, signal, visa_chosen, lineEditVisa, selectClose): self.ui.label_condition.setText('Visa address is closed') lineEditVisa.setText('') selectClose[0].setEnabled(True) selectClose[1].setEnabled(False) self.Mark(visa_chosen, True) if signal == "visa1": visa_chosen.close() self.visa1 = None #self.Disable(signal) elif signal == "visa2": visa_chosen.close() self.visa2 = None #self.Disable(signal) elif signal == "visa3": visa_chosen.close() self.visa3 = None #self.Disable(signal) elif signal == "visa4": visa_chosen.close() self.visa4 = None #self.Disable(signal) def Check(self, inst): try: inst.ask("*IDN?") valid = True except: valid = False return valid def make_curveWidgets(self, curvewidget, color, markerColor, titles): curve_temp = make.curve([], [], color = color, marker = "o", markerfacecolor = markerColor, markersize = 5) curvewidget.plot.add_item(curve_temp) curvewidget.plot.set_antialiasing(True) curvewidget.plot.set_titles(titles[0], titles[1], titles[2]) return curve_temp def array_builder(self, start, step, stop, double_linear): if start < stop: array_1 = numpy.arange(start, stop + step, abs(step)) elif start > stop: array_1 = numpy.arange(stop, start - step, abs(step))[::-1] else: array_1 = numpy.array([start]) if double_linear == "y": array = array_1[::-1] array_2 = numpy.delete(array, 0) array_sweep = numpy.append(array_1, array_2) else: array_sweep = array_1 return array_sweep def start(self): self.Device1_state = False self.instruments = [] curves = [self.Curve1, self.Curve2, self.Curve3, self.Curve4, self.curve_3, self.curve_3_update, self.curve_1, self.curve_1_update] curveWidgets =[self.ui.curvewidget_13, self.ui.curvewidget_14, self.ui.curvewidget_15, self.ui.curvewidget_16, self.ui.curvewidget_1] array_1 = [] go_on = True input_data = [] temp = str(self.ui.textEdit.toPlainText()).split("\n") for i in range(0, len(temp)): if temp[i] != '': input_data.append(temp[i]) inputted_data = [] inputted_data.append([input_data[0].split(":")[1].replace(" ", "")]) temp = [] for i in range(1, 8): temp.append(input_data[i].split(":")[1].replace(" ", "")) inputted_data.append(temp) temp = [] for i in range(8, 11): temp.append(input_data[i].split(":")[1].replace(" ", "")) inputted_data.append(temp) temp = [] for i in range(11, 15): temp.append(input_data[i].split(":")[1].replace(" ", "")) inputted_data.append(temp) self.Device1_state = True device_state = [self.Device1_state] #Make Array count = 0 if self.Device1_state: count += 1 temp = [] array_1 = self.array_builder(float(inputted_data[1][0]), float(inputted_data[1][1]), float(inputted_data[1][2]), inputted_data[1][3]) if str(self.ui.pushButton_Start.text()) == "Start": if self.Check_ready(count): if self.ui.checkBox_dsave.isChecked(): self.Dsave_directory() if self.dsave_dir_ok: self.Dsave_filename() if self.dsave_filename_ok: self.Dsave_username() if self.dsave_username_ok: self.Dsave_filetype() dsave = [self.dsave_directory, self.dsave_filename, self.dsave_username, self.dsave_thread, self.dsave_filetype, self.dsave_divide, self.date] self.start_font("C") self.ui.tabWidget.setCurrentIndex(2) self.ui.pushButton_Start.setEnabled(False) self.ui.pushButton_Pause.setEnabled(True) self.ui.pushButton_Stop.setEnabled(True) file_par = open("parameters.txt", "w").write(str(self.ui.textEdit.toPlainText())) self.collect_data_thread.input(self.ui, self.instruments, curves, curveWidgets, go_on, inputted_data, array_1, device_state, count, dsave, input_data) else: self.ui.label_condition.setText('Enter user name for dynamic saving.') else: self.ui.label_condition.setText('Enter file name for dynamic saving.') else: self.ui.label_condition.setText('Choose valid directory for dynamic saving.') else: self.ui.label_condition.setText('Choose dynamic saving.') else: self.ui.label_condition.setText('Make sure enough devices are connected.') else: # if self.Device1_state: # self.setup_plot_2(self.curve_2_b, self.curve_2_r, array_1) self.setup_plot(self.curve_1, array_1) self.ui.tabWidget.setCurrentIndex(0) self.start_font("S") def Check_ready(self, count): if count == 1: self.instruments = [self.visa1, self.visa2] return True return False def setup_plot(self, curve, data): x = [] for i in range(0, len(data)): x.append(i) curve.set_data(x, data) self.ui.curvewidget_1.plot.do_autoscale() self.ui.curvewidget_2.plot.do_autoscale() self.ui.curvewidget_3.plot.do_autoscale() curve.plot().replot() def setup_plot_2(self, curve_b, curve_r, data): x1 = [] y1 = [] x2 = [] y2 = [] num = 0 for i in range(0, len(data)): x1.append(num) y1.append(data[i]) num += 1 num -= 1 curve_b.set_data(x1, y1) #curve_r.set_data(x2, y2) curve_b.plot().replot() #curve_r.plot().replot() def curvePlots_update(self, curveInfo): curveWidget = curveInfo[0] curve = curveInfo[1] curveWidget.plot.do_autoscale() curve.plot().replot() def Print_data(self, device, text): font = QFont() font.setPointSize(10) self.ui.textEditDisplay.setFont(font) self.out0_1 = str(format(text[0], '.3f')) self.out0_2 = str(format(text[1], '.3f')) lockin_params = text[7] # print lockin_params # print lockin_params[1][0] # print lockin_params[0][0] # print lockin_params[1][1] # print lockin_params[0][1] display_text = "" display_text = display_text + "Time: " + self.out0_1 + " s\n" display_text = display_text + "Time Step: " + self.out0_2 + " s\n" out1_1 = float(text[2]) self.scale1_1 = self.Switch_scale(out1_1) self.out1_1 = str(format(out1_1 * self.scale1_1[0], '.3f')) out1_2 = float(text[3]) self.scale1_2 = self.Switch_scale(out1_2) self.out1_2 = str(format(out1_2 * self.scale1_2[0], '.3f')) out1_3 = float(text[4]) self.scale1_3 = self.Switch_scale(out1_3) self.out1_3 = str(format(out1_3 * self.scale1_3[0], '.3f')) out1_4 = float(text[5]) self.scale1_4 = self.Switch_scale(out1_4) self.out1_4 = str(format(out1_4 * self.scale1_4[0], '.3f')) self.out1_5 = float(text[6]) # self.scale1_5 = self.Switch_scale(out1_5) # self.out1_5 = str(format(out1_5 * self.scale1_5[0], '.3f')) if self.Device1_state: display_text = display_text + "Output Voltage: " + str(self.out1_1) + " " + str(self.scale1_1[1]) + "Volts\n" display_text = display_text + "Output Current: " + str(self.out1_2) + " " + str(self.scale1_2[1])+ "Amps\n" display_text = display_text + "X: " + str(self.out1_3) + " " + str(self.scale1_3[1])+ "Volts\n" display_text = display_text + "Y: " + str(self.out1_4) + " " + str(self.scale1_4[1])+ "Volts\n" display_text = display_text + "Phase: " + str(self.out1_5) + " " + "Radians\n" display_text = display_text + lockin_params[1][0] + ': ' + lockin_params[0][0] +'\n' display_text = display_text + lockin_params[1][1] + ': ' + lockin_params[0][1] +'\n' display_text = display_text + lockin_params[1][2] + ': ' + lockin_params[0][2] +'\n' display_text = display_text + lockin_params[1][3] + ': ' + lockin_params[0][3] +'\n' display_text = display_text + lockin_params[1][4] + ': ' + lockin_params[0][4] +'\n' display_text = display_text + lockin_params[1][5] + ': ' + lockin_params[0][5] +'\n' display_text = display_text + lockin_params[1][6] + ': ' + lockin_params[0][6] +'\n' display_text = display_text + lockin_params[1][7] + ': ' + lockin_params[0][7] +'\n' display_text = display_text + lockin_params[1][8] + ': ' + lockin_params[0][8] +'\n' display_text = display_text + lockin_params[1][9] + ': ' + lockin_params[0][9] +'\n' display_text = display_text + text[8]+ '\n' self.ui.textEditDisplay.setText(display_text) def Switch_scale(self, num): temp = abs(num) if temp >= 1E9: scale = [1E-9, "G"] elif temp >= 1E6 and temp < 1E9: scale = [1E-6, "M"] elif temp >= 1E3 and temp < 1E6: scale = [1E-3, "k"] elif temp >= 1 and temp < 1000: scale = [1, ""] elif temp >= 1E-3 and temp < 1: scale = [1E3, "m"] elif temp >= 1E-6 and temp < 1E-3: scale = [1E6, "u"] elif temp >= 1E-9 and temp < 1E-6: scale = [1E9, "n"] elif temp < 1E-9: scale = [1E12, "p"] return scale def Pre_dsave(self): if self.ui.checkBox_dsave.isChecked(): self.ui.label_dsave_directory.setEnabled(True) self.ui.lineEdit_dsave_directory.setEnabled(True) self.ui.pushButton_dsave_browse.setEnabled(True) self.ui.groupBox_dsave_filename.setEnabled(True) self.ui.radioButton_dsave_timename.setEnabled(True) self.ui.radioButton_dsave_custname.setEnabled(True) self.ui.lineEdit_dsave_custname.setEnabled(True) self.ui.groupBox_dsave_filetype.setEnabled(True) self.ui.radioButton_csv.setEnabled(True) self.ui.radioButton_txt.setEnabled(True) self.ui.label_dsave_username.setEnabled(True) self.ui.lineEdit_dsave_username.setEnabled(True) self.ui.label_dsave_comment.setEnabled(True) self.ui.textEdit_dsave_comment.setEnabled(True) self.ui.label_condition.setText("Dynamic saving opened.") else: self.ui.label_dsave_directory.setEnabled(False) self.ui.lineEdit_dsave_directory.setEnabled(False) self.ui.pushButton_dsave_browse.setEnabled(False) self.ui.groupBox_dsave_filename.setEnabled(False) self.ui.radioButton_dsave_timename.setEnabled(False) self.ui.radioButton_dsave_custname.setEnabled(False) self.ui.lineEdit_dsave_custname.setEnabled(False) self.ui.groupBox_dsave_filetype.setEnabled(False) self.ui.radioButton_csv.setEnabled(False) self.ui.radioButton_txt.setEnabled(False) self.ui.label_dsave_username.setEnabled(False) self.ui.lineEdit_dsave_username.setEnabled(False) self.ui.label_dsave_comment.setEnabled(False) self.ui.textEdit_dsave_comment.setEnabled(False) self.ui.label_condition.setText("Dynamic saving closed.") def Dsave_browse(self): self.dsave_directory = '' prev_dir = os.getcwd() fileDir = QFileDialog.getExistingDirectory(None, 'Select Folder to Save', prev_dir) if fileDir != '': open_dir = '' file_list = str(fileDir).split('/') for i in range(0, len(file_list) - 1): if i < len(file_list) - 1: open_dir += file_list[i] + '\\' elif i == len(file_list) - 1: open_dir += file_list[i] fileDir.replace('/', '\\') self.dsave_directory = fileDir self.ui.lineEdit_dsave_directory.setText(fileDir) self.ui.label_condition.setText("Dynamic saving directory selected.") else: self.ui.lineEdit_dsave_directory.setText('None') self.ui.label_condition.setText('Choose a directory for dynamic saving.') def Dsave_directory(self): self.dsave_dir_ok = True if self.ui.lineEdit_dsave_directory.text() == '' or self.ui.lineEdit_dsave_directory.text() == 'None': self.dsave_dir_ok = False def Dsave_filename(self): self.dsave_filename_ok = True self.date = '' self.dsave_filename = '' if self.ui.radioButton_dsave_timename.isChecked(): now = datetime.datetime.now() date = '%s-%s-%s' % (now.year, now.month, now.day) current_time = '%s.%s.%s' % (now.hour, now.minute, now.second) date_and_time = date + '_' + current_time self.date = date self.dsave_filename = str(date_and_time) elif self.ui.radioButton_dsave_custname.isChecked(): self.dsave_filename = str(self.ui.lineEdit_dsave_custname.text()) if self.dsave_filename == '': self.dsave_filename_ok = False def Dsave_filetype(self): if self.ui.radioButton_csv.isChecked(): self.dsave_filetype = '.csv' self.dsave_divide = ',' elif self.ui.radioButton_txt.isChecked(): self.dsave_filetype = '.txt' self.dsave_divide = '\t' def Dsave_username(self): self.dsave_username_ok = True self.dsave_username = '' self.dsave_username = str(self.ui.lineEdit_dsave_username.text()) if self.dsave_username == '': self.dsave_username_ok = False def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what is everything the user wants to be initialized when the class is called. # Here we shall define the trig functions to corresponding variables. # Note that the "self" variable means that the function is part of the class and can be called inside and outside the class.(Although __init__ is special.) def __init__(self, parent = None): self.collect_data_thread = Collect_data() # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to self.ui # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) self.connect(self.ui.pushButton_update_1, SIGNAL('clicked()'), lambda : self.Update("visa1", self.ui.comboBox_visa_1)) self.connect(self.ui.pushButton_update_2, SIGNAL('clicked()'), lambda : self.Update("visa2", self.ui.comboBox_visa_2)) self.connect(self.ui.pushButton_update_3, SIGNAL('clicked()'), lambda : self.Update("visa3", self.ui.comboBox_visa_3)) self.connect(self.ui.pushButton_update_4, SIGNAL('clicked()'), lambda : self.Update("visa4", self.ui.comboBox_visa_4)) self.connect(self.ui.pushButton_update_5, SIGNAL('clicked()'), lambda : self.Update("visa5", self.ui.comboBox_visa_5)) self.connect(self.ui.pushButton_select_1, SIGNAL('clicked()'), lambda : self.Select("visa1", self.visa1, self.ui.comboBox_visa_1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_select_2, SIGNAL('clicked()'), lambda : self.Select("visa2", self.visa2, self.ui.comboBox_visa_2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_select_3, SIGNAL('clicked()'), lambda : self.Select("visa3", self.visa3, self.ui.comboBox_visa_3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_select_4, SIGNAL('clicked()'), lambda : self.Select("visa4", self.visa4, self.ui.comboBox_visa_4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_select_5, SIGNAL('clicked()'), lambda : self.Select("visa5", self.visa5, self.ui.comboBox_visa_5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_close_1, SIGNAL('clicked()'), lambda : self.Close("visa1", self.visa1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_close_2, SIGNAL('clicked()'), lambda : self.Close("visa2", self.visa2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_close_3, SIGNAL('clicked()'), lambda : self.Close("visa3", self.visa3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_close_4, SIGNAL('clicked()'), lambda : self.Close("visa4", self.visa4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_close_5, SIGNAL('clicked()'), lambda : self.Close("visa5", self.visa5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_Start, SIGNAL('clicked()'), self.start) self.connect(self.ui.pushButton_Stop, SIGNAL('clicked()'), self.collect_data_thread.stop) self.connect(self.ui.pushButton_Pause, SIGNAL('clicked()'), self.collect_data_thread.pause) self.connect(self.collect_data_thread, SIGNAL("curve_plot"), self.curvePlots_update) self.connect(self.collect_data_thread, SIGNAL("print"), self.Print_data) self.connect(self.ui.textEdit, SIGNAL('textChanged ()'), lambda : self.start_font("C")) self.Update("visa1", self.ui.comboBox_visa_1) self.Update("visa2", self.ui.comboBox_visa_2) self.Update("visa3", self.ui.comboBox_visa_3) self.Update("visa4", self.ui.comboBox_visa_4) self.Update("visa5", self.ui.comboBox_visa_5) self.curve_1 = self.make_curveWidgets(self.ui.curvewidget_1, "black", "black", titles = ["Plot 1", "X (x)", "Y (y)"]) self.curve_2 = self.make_curveWidgets(self.ui.curvewidget_2, "r", "black", titles = ["Plot 2", "X (x)", "Y (y)"]) self.curve_3 = self.make_curveWidgets(self.ui.curvewidget_3, "g", "black", titles = ["Plot 3", "X (x)", "Y (y)"]) self.curve_4 = self.make_curveWidgets(self.ui.curvewidget_4, "o", "black", titles = ["Plot 4", "X (x)", "Y (y)"]) self.visa1 = None self.visa2 = None self.visa3 = None self.visa4 = None self.visa5 = None self.setWindowTitle("Keithley Gate Sweep with Current Bias Lock-in") font = QFont() font.setPointSize(10) self.ui.tabWidget_visa.setFont(font) self.ui.tabWidget_visa.setTabText(0, "Lock-in Curr") self.ui.tabWidget_visa.setTabText(1, "Keithley Gate") self.input_string = [] self.input_string.append("00 Run_Number: 01\n\n") self.input_string.append("01 Start Gate Voltage: 0\n") self.input_string.append("02 Step Gate Voltage: 0.1\n") self.input_string.append("03 End Gate Voltage: 10\n") self.input_string.append("04 Double Linear (y/n): y\n") self.input_string.append("05 Turn off Keithley (y/n): y\n\n") self.input_string.append("06 CurrBias Lock-in Sens: 5e-3\n") self.input_string.append("07 Current Bias Resistor: 1.015e6\n") self.input_string.append("08 Lock-in Output Voltage: 4e-3\n") self.input_string.append("09 Additional Lock-in Volt Gain: 1\n\n") self.input_string.append("10 User: Vannucci\n") self.input_string.append("11 Save Name: \n") self.input_string.append("12 TimeStamp (y/n): y\n") self.input_string.append("13 Comments: ") self.start_font("C") try: file_par = open("parameters.txt", "r") input_string_print = file_par.read() file_par.close() except: input_string_print = "" for st_i in self.input_string: input_string_print = input_string_print + st_i font = QFont() font.setPointSize(8) self.ui.textEdit.setFont(font) self.ui.textEdit.setText(input_string_print) self.inputted_data = [] self.array_sweep = [] def start_font(self, status): if status == "C": font = QFont() font.setPointSize(8) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Check Array") elif status == "S": font = QFont() font.setPointSize(12) self.ui.pushButton_Start.setFont(font) self.ui.pushButton_Start.setText("Start") def Update(self, signal, comboBoxVisa): rm = visa.ResourceManager() try: alls = rm.list_resources() except: alls = "No Visa Available." if signal == "visa1": self.ui.comboBox_visa_1.clear() elif signal == "visa2": self.ui.comboBox_visa_2.clear() elif signal == "visa3": self.ui.comboBox_visa_3.clear() elif signal == "visa4": self.ui.comboBox_visa_4.clear() elif signal == "visa5": self.ui.comboBox_visa_5.clear() for temp in alls: if signal == "visa1": self.ui.comboBox_visa_1.addItem(temp) elif signal == "visa2": self.ui.comboBox_visa_2.addItem(temp) elif signal == "visa3": self.ui.comboBox_visa_3.addItem(temp) elif signal == "visa4": self.ui.comboBox_visa_4.addItem(temp) elif signal == "visa5": self.ui.comboBox_visa_5.addItem(temp) def Select(self, signal, visa_chosen, comboBoxVisa, lineEditVisa, selectClose): visa_address = str(comboBoxVisa.currentText()) rm = visa.ResourceManager() rm.list_resources() inst = rm.open_resource(visa_address) #visa_check = self.Check(inst) visa_check = True if visa_check == True: self.ui.label_condition.setText("Visa is selected succefully!") if signal == "visa1": visa_name = inst.query("*IDN?") print visa_name name_list = visa_name.split(',') first_name = name_list[0] lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) #self.Enable(signal) self.visa1 = inst elif signal == "visa2": visa_name = inst.query("*IDN?\n") print visa_name name_list = visa_name.split(',') first_name = name_list[0] lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) #self.Enable(signal) self.visa2 = inst elif signal == "visa3": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) #self.Enable(signal) self.visa3 = inst elif signal == "visa4": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) #self.Enable(signal) self.visa4 = inst elif signal == "visa5": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) #self.Enable(signal) self.visa5 = inst elif visa_check == False: self.ui.label_condition.setText("Invalid visa address.") lineEditVisa.setText("None.") visa_chosen = False def Close(self, signal, visa_chosen, lineEditVisa, selectClose): self.ui.label_condition.setText('Visa address is closed') lineEditVisa.setText('') selectClose[0].setEnabled(True) selectClose[1].setEnabled(False) if signal == "visa1": visa_chosen.close() self.visa1 = None self.Disable(signal) elif signal == "visa2": visa_chosen.close() self.visa2 = None self.Disable(signal) elif signal == "visa3": visa_chosen.close() self.visa3 = None self.Disable(signal) elif signal == "visa4": visa_chosen.close() self.visa4 = None self.Disable(signal) elif signal == "visa5": visa_chosen.close() self.visa5 = None self.Disable(signal) def Check(self, inst): try: inst.ask("*IDN?") valid = True except: valid = False return valid def make_curveWidgets(self, curvewidget, color, markerColor, titles): curve_temp = make.curve([], [], color = color, marker = "o", markerfacecolor = markerColor, markersize = 5) curvewidget.plot.add_item(curve_temp) curvewidget.plot.set_antialiasing(True) curvewidget.plot.set_titles(titles[0], titles[1], titles[2]) return curve_temp def start(self): instruments = [self.visa1, self.visa2, self.visa3, self.visa4, self.visa5] curves = [self.curve_1, self.curve_2, self.curve_3, self.curve_4] curveWidgets =[self.ui.curvewidget_1, self.ui.curvewidget_2, self.ui.curvewidget_3, self.ui.curvewidget_4] go_on = True inputted_string = str(self.ui.textEdit.toPlainText()) input_data = inputted_string.split("Comments:") comments = input_data[1] input_data = input_data[0].split("\n") inputted_data = [] for i in range(0, len(input_data)): for j in range(0, len(self.input_string)): if len(input_data[i].split(self.input_string[j].split(":")[0])) > 1: inputted_data.append(input_data[i].split(self.input_string[j].split(":")[0])[1].replace(":", "").replace(" ", "")) print inputted_data #Make Array if float(inputted_data[1]) < float(inputted_data[3]): array_1 = numpy.arange(float(inputted_data[1]), float(inputted_data[3]) + float(inputted_data[2]), float(inputted_data[2])) elif float(inputted_data[1]) > float(inputted_data[3]): array_1 = numpy.arange(float(inputted_data[3]), float(inputted_data[1]) + float(inputted_data[2]), float(inputted_data[2]))[::-1] if inputted_data[4].upper() == "Y": array_2 = array_1[::-1] array_sweep = numpy.append(array_1, array_2) else: array_sweep = array_1 run_program = True for i in range(0, len(inputted_data)): try: if self.inputted_data[i] != inputted_data[i]: run_program = False self.start_font("C") except: run_program = False self.start_font("C") for i in range(0, len(array_sweep)): try: if self.array_sweep[i] != array_sweep[i]: run_program = False self.start_font("C") except: run_program = False self.start_font("C") if not run_program: self.inputted_data = inputted_data self.array_sweep = array_sweep self.ui.curvewidget_1.plot.set_titles("Gate Voltage Steps", "Steps", "Gate Voltage (V)") self.curve_1.set_data(range(0, len(self.array_sweep)), self.array_sweep) self.ui.curvewidget_1.plot.do_autoscale() self.curve_1.plot().replot() self.start_font("S") elif run_program: if str(self.ui.pushButton_Start.text()) == "Start": self.start_font("C") self.collect_data_thread.input(self.ui, instruments, curves, curveWidgets, go_on, inputted_data, comments, array_sweep, inputted_string, self.input_string) else: self.start_font("S") def curvePlots_update(self, curveInfo): curveWidget = curveInfo[0] curve = curveInfo[1] curveWidget.plot.do_autoscale() curve.plot().replot() def Print_data(self, display_text): font = QFont() font.setPointSize(8) self.ui.textEditDisplay.setFont(font) self.ui.textEditDisplay.setText(display_text) """self.ui.label_step.setText(step) self.ui.label_time.setText(time) self.ui.label_V1.setText(V1) self.ui.label_V2.setText(V2) self.ui.label_V3.setText(V3) self.ui.label_V4.setText(V4) self.ui.label_V5.setText(V5) self.ui.label_V6.setText(V6)""" def Switch_scale(self, num): temp = abs(num) if temp >= 1E9: scale = [1E-9, "G"] elif temp >= 1E6 and temp < 1E9: scale = [1E-6, "M"] elif temp >= 1E3 and temp < 1E6: scale = [1E-3, "k"] elif temp >= 1 and temp < 1000: scale = [1, ""] elif temp >= 1E-3 and temp < 1: scale = [1E3, "m"] elif temp >= 1E-6 and temp < 1E-3: scale = [1E6, "u"] elif temp >= 1E-9 and temp < 1E-6: scale = [1E9, "n"] elif temp < 1E-9: scale = [1E12, "p"] return scale def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas = FigureCanvas(self.ui.mplwidget.figure) self.canvas.setParent(self.ui.widget) # We need the toolbar widget for the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.ui.widget) # Create the QVBoxLayout object and add the widget into the layout vbox = QVBoxLayout() # The matplotlib canvas vbox.addWidget(self.canvas) # The matplotlib toolbar vbox.addWidget(self.mpl_toolbar) self.ui.widget.setLayout(vbox) # Connect the mplwidget with canvas self.ui.mplwidget = self.canvas self.connect(self.ui.pushButton_browse, SIGNAL('clicked()'), self.Browse) self.connect(self.ui.pushButton_plot, SIGNAL('clicked()'), self.Plot) self.connect(self.ui.pushButton_show, SIGNAL('clicked()'), self.Show) def Browse(self): self.prev_dir = 'C:\Users\QMDlab\Desktop' self.fileDir = QFileDialog.getOpenFileName(self, 'Select File to Open:', 'C:\Users\QMDlab\Desktop') if self.fileDir != '': self.fileDir.replace('/', '\\') self.ui.lineEdit_address.setText(self.fileDir) self.ui.lineEdit_condition1.setText('Open Source File') else: self.ui.lineEdit_address.setText('None') self.ui.lineEdit_condition1.setText('Failed to Read File') self.ui.groupBox_labels.setEnabled(True) def Show(self): labels = '' row = 1 raw_parameters = [] parameters = [] fp = open(self.fileDir) while True: line = fp.readline() #print 1, line linelist = line.split(',') if linelist[0] == 'Collected Data\n': break labels += linelist[0] row += 1 self.ui.textEdit_labels.setText(labels) #fp.close() #fp = open(self.fileDir) """ raw_parameters = lines[row].split(',') for i in range(0, len(raw_parameters) - 1): parameters.append(raw_parameters[i]) parameters.append(raw_parameters[len(raw_parameters) - 1].strip()) for i in range(0, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y.addItem(parameters[i]) #fp.close() list_bundle = [[] for i in range(0, len(parameters))] """ #Read Parameters parameters = fp.readline().replace("\n", '') #print 'parameters', parameters parameters = parameters.split(',') for i in range(0, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y.addItem(parameters[i]) #Read Units units = fp.readline().replace("\n", '') #print 'units', units units = units.split(",") self.data = [] for i in range(0, len(parameters)): new_data = [parameters[i], units[i], []] self.data.append(new_data) #fp = open(self.fileDir) while True: #parameters = [] #fp = open(self.fileDir) lines = fp.readline().replace("\n", "") #print "lines", lines if lines == '': break values = lines.split(',') for i in range(0, len(values)): self.data[i][2].append(values[i]) #row += 1 #print data ### #for i in range(0, len(raw_parameters) - 1): # parameters.append(raw_parameters[i]) #parameters.append(raw_parameters[len(raw_parameters) - 1].strip()) #for i in range(0, len(parameters)): # list_bundle[i].append(parameters[i]) ### #fp.close() self.ui.groupBox_plot.setEnabled(True) self.ui.lineEdit_condition2.setText('Ready to Plot.') def Plot(self): x_value = self.ui.comboBox_x.currentIndex() y_value = self.ui.comboBox_y.currentIndex() self.reset_plot() self.axes.plot(self.data[x_value][2], self.data[y_value][2], marker='.', linestyle=':') self.axes.set_title(self.data[x_value][0] + ' vs. ' + self.data[y_value][0]) self.axes.set_xlabel(self.data[x_value][0] + ' (' + self.data[x_value][1] + ')') self.axes.set_ylabel(self.data[y_value][0] + ' (' + self.data[y_value][1] + ')') self.ui.mplwidget.draw() self.ui.lineEdit_condition2.setText('Plot successfully.') def reset_plot(self): self.ui.mplwidget.figure.clear() self.axes = self.ui.mplwidget.figure.add_subplot(111) def closeEvent(self, question): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) # If your answer is "yes", then quit if reply == QMessageBox.Yes: question.accept() # If your answer is "no", then get back else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas_general = FigureCanvas(self.ui.mplwidget_general.figure) self.canvas_general.setParent(self.ui.widget_general) # We need the toolbar widget for the canvas self.mpl_toolbar_general = NavigationToolbar(self.canvas_general, self.ui.widget_general) self.canvas_import = FigureCanvas(self.ui.mplwidget_import.figure) self.canvas_import.setParent(self.ui.widget_import) # This is the toolbar widget for the import canvas self.mpl_toolbar_import = NavigationToolbar(self.canvas_import, self.ui.widget_import) # self.canvas_scan = FigureCanvas(self.ui.mplwidget_scan.figure) # self.canvas_scan.setParent(self.ui.widget_scan) # # This is the toolbar widget for the scan canvas # self.mpl_toolbar_scan = NavigationToolbar(self.canvas_scan, self.ui.widget_scan) # Create the QVBoxLayout object and add the widget into the layout vbox_general = QVBoxLayout() # The matplotlib canvas vbox_general.addWidget(self.canvas_general) # The matplotlib toolbar vbox_general.addWidget(self.mpl_toolbar_general) self.ui.widget_general.setLayout(vbox_general) # Create the QVBoxLayout object and add the widget into the Layout vbox_import = QVBoxLayout() # The matplotlib canvas vbox_import.addWidget(self.canvas_import) # The matplotlib toolbar vbox_import.addWidget(self.mpl_toolbar_import) self.ui.widget_import.setLayout(vbox_import) # # Create the QVBoxLayout object and add the widget into the Layout # vbox_scan = QVBoxLayout() # # The matplotlib canvas # vbox_scan.addWidget(self.canvas_scan) # # The matplotlib toolbar # vbox_scan.addWidget(self.mpl_toolbar_scan) # self.ui.widget_scan.setLayout(vbox_scan) # Connect the mplwidget with canvas self.ui.mplwidget_general = self.canvas_general self.ui.mplwidget_import = self.canvas_import # self.ui.mplwidget_scan = self.canvas_scan self.Array_Builder_programs = Array_Builder(self.ui) # Connect buttons in the General Array tab self.connect(self.ui.pushButton_plot, SIGNAL('clicked()'), self.Array_Builder_programs.Plot_general) self.connect(self.ui.pushButton_clear, SIGNAL('clicked()'), self.Array_Builder_programs.Clear) self.connect(self.ui.pushButton_save, SIGNAL('clicked()'), self.Array_Builder_programs.Save) self.connect(self.ui.pushButton_browse_save, SIGNAL('clicked()'), self.Array_Builder_programs.Browse_save) # Connect buttons in the Keithely tab self.Keithley_programs = Keithley(self.ui) self.Keithley_programs.Refresh_visa() self.connect(self.ui.pushButton_browse_keithley, SIGNAL('clicked()'), self.Keithley_programs.Browse_keithley) self.connect(self.ui.pushButton_import_keithley, SIGNAL('clicked()'), self.Keithley_programs.Import_keithley) self.connect(self.ui.pushButton_close_keithley, SIGNAL('clicked()'), self.Keithley_programs.Close_keithley) self.connect(self.ui.pushButton_select_keithley, SIGNAL('clicked()'), self.Keithley_programs.Select_keithley) self.connect(self.ui.pushButton_scan_keithley, SIGNAL('clicked()'), self.Keithley_programs.Scan_keithley) self.connect(self.ui.pushButton_pause_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.pause) self.connect(self.ui.pushButton_stop_keithley, SIGNAL('clicked()'), self.Keithley_programs.collect_data_thread.stop) self.connect(self.ui.pushButton_clear_keithley, SIGNAL('clicked()'), self.Keithley_programs.Clear_keithley) self.connect(self.ui.pushButton_copy_keithley, SIGNAL('clicked()'), self.CopyData) self.connect( self.ui.radioButton_voltage_keithley, SIGNAL("clicked()"), lambda: self.ui.tabWidget_scan_keithley.setCurrentIndex(0)) self.connect( self.ui.radioButton_current_keithley, SIGNAL("clicked()"), lambda: self.ui.tabWidget_scan_keithley.setCurrentIndex(1)) self.connect(self.Keithley_programs.collect_data_thread, SIGNAL("plot"), self.Keithley_programs.Plot_data) self.Values = [] self.Step = [] self.Peak = [] self.round = 0 self.new_start = 0 self.ui.lineEdit_directory_save.setText(os.getcwd()) self.canvas_import_ay = FigureCanvas( self.ui.mplwidget_import_ay.figure) self.canvas_import_ay.setParent(self.ui.widget_import_ay) # This is the toolbar widget for the import canvas self.mpl_toolbar_import_ay = NavigationToolbar( self.canvas_import_ay, self.ui.widget_import_ay) # Create the QVBoxLayout object and add the widget into the Layout vbox_import_ay = QVBoxLayout() # The matplotlib canvas vbox_import_ay.addWidget(self.canvas_import_ay) # The matplotlib toolbar vbox_import_ay.addWidget(self.mpl_toolbar_import_ay) self.ui.widget_import_ay.setLayout(vbox_import_ay) # Connect the mplwidget with canvas self.ui.mplwidget_import_ay = self.canvas_import_ay # self.ui.mplwidget_scan = self.canvas_scan # Connect buttons in the Agilent Yokogawa tab self.Agilent_Yokogawa_programs = Agilent_Yokogawa(self.ui) self.connect(self.ui.startButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.start) #self.connect(self.action_timer, SIGNAL("timeout()"), self.Agilent_Yokogawa_programs.action) self.connect(self.ui.pushButton_browse_ay, SIGNAL('clicked()'), self.Agilent_Yokogawa_programs.Browse_ay) self.connect(self.ui.pushButton_import_ay, SIGNAL('clicked()'), self.Agilent_Yokogawa_programs.Import_ay) self.connect(self.ui.pushButton_copy_ay, SIGNAL('clicked()'), self.Copy_ay) self.connect(self.ui.selectVisaButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.select_visa) self.connect(self.ui.updateVisaButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.update_visa) self.connect(self.ui.closeVisaButton0, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.close_visa0) self.connect(self.ui.closeVisaButton1, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.close_visa1) self.connect(self.ui.browseButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.browse) self.connect(self.ui.saveButton, SIGNAL("clicked()"), self.Agilent_Yokogawa_programs.save) def CopyData(self): if self.Array_Builder_programs.data_available == True: self.Keithley_programs.Copy_keithley( self.Array_Builder_programs.Values) self.ui.lineEdit_condition_keithley.setText( 'Array has been copied and plotted.') else: self.ui.lineEdit_condition_keithley.setText( 'No valid array to copy.') def Copy_ay(self): if self.Array_Builder_programs.data_available == True: self.Agilent_Yokogawa_programs.Copy_ay( self.Array_Builder_programs.Values) self.ui.output.setText('Array has been copied and plotted.') else: self.ui.output.setText('No valid array to copy.') # Make sure the user is going to quit the program def closeEvent(self, event): quit_msg = "DO you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent=None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas = FigureCanvas(self.ui.mplwidget.figure) self.canvas.setParent(self.ui.widget) # We need the toolbar widget for the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.ui.widget) # Create the QVBoxLayout object and add the widget into the layout vbox = QVBoxLayout() # The matplotlib canvas vbox.addWidget(self.canvas) # The matplotlib toolbar vbox.addWidget(self.mpl_toolbar) self.ui.widget.setLayout(vbox) # Connect the mplwidget with canvas self.ui.mplwidget = self.canvas self.reset_plot() self.connect(self.ui.pushButton_browse, SIGNAL('clicked()'), self.Browse) self.connect(self.ui.pushButton_change_name, SIGNAL('clicked()'), self.Change_name) self.connect(self.ui.pushButton_open, SIGNAL('clicked()'), self.Open) self.connect(self.ui.pushButton_Plot, SIGNAL('clicked()'), self.Plot_ready) self.connect(self.ui.pushButton_Next, SIGNAL('clicked()'), self.Next) self.connect(self.ui.pushButton_Previous, SIGNAL('clicked()'), self.Previous) self.connect(self.ui.pushButton_find, SIGNAL('clicked()'), self.Find) self.connect(self.ui.pushButton_modify, SIGNAL('clicked()'), self.Modify) self.connect(self.ui.pushButton_return, SIGNAL('clicked()'), self.Return) self.ui.pushButton_browse.setEnabled(True) self.modify = False self.first_round = True self.open_dir = '' self.open_files_number = 0 self.all_info = [] def Browse(self): self.Num = 0 self.Files = [] self.Names = [] prev_dir = os.getcwd() fileDir = QFileDialog.getOpenFileNames(self, 'Select Files to Open', self.ui.lineEdit_address.text()) if fileDir != '': self.comboBox_update = True self.Files = fileDir open_dir = '' file_list = str(fileDir[0]).split('\\') for i in range(0, len(file_list) - 1): if i < len(file_list) - 2: open_dir += file_list[i] + '\\' elif i == len(file_list) - 2: open_dir += file_list[i] self.ui.lineEdit_address.setText(open_dir) self.ui.pushButton_open.setEnabled(True) self.first_round = False filedir = str(fileDir).split('\\') for i in range(0, len(fileDir)): temp = fileDir[i].split('\\') name = temp[len(temp) - 1] self.Names.append(name) if len(fileDir) > 1: self.ui.label_condition.setText( str(len(fileDir)) + ' files selected, click Open') elif len(fileDir) == 1: self.ui.label_condition.setText( str(len(fileDir)) + ' file selected, click Open') else: self.ui.lineEdit_address.setText('None') self.ui.label_condition.setText('Failed to Read File') def Open(self): # Every you click the "Open File" button, the content in the plot combox is refreshed self.reset_plot() self.ui.mplwidget.draw() self.ui.lineEdit_x.setText('') self.ui.lineEdit_y.setText('') self.ui.lineEdit_name.setText('') self.ui.label_condition.setText('') self.ui.lineEdit_minute.setText('') self.ui.label_date.setText('') labels = '' raw_parameters = [] units = [] parameters = [] new_parameters = [] self.data = [] new_data = [] first_data = [] self.date_time = [] temp_parameters = [] item = 0 length = 0 # This count is the number of the reading loops for labels. If count is over 1000, that means there's something wrong with the divider line and it helps to stop the program count = 0 # It is false when program cannot find the line divider and runs the while loop 1000 times self.divider_found = True fp = open(self.Files[self.Num]) while True: if count > 1000: self.ui.label_condition.setText('Line divider is not found.') self.divider_found = False break line = fp.readline() linelist = line.split(',') if linelist[0].upper() == 'COLLECTED DATA\n': break for i in range(0, len(linelist)): labels += linelist[i] count += 1 if self.divider_found == True: self.ui.textEdit_labels.setText(labels) parameters = fp.readline().replace("\n", '') temp_parameters = parameters.split(',') if temp_parameters[0] == 'Date': parameters = temp_parameters[1:] else: parameters = temp_parameters # The following is for the units units = fp.readline().replace("\n", '') units = units.split(",") if temp_parameters[0] == 'Date': units = units[1:] if self.comboBox_update: self.ui.comboBox_x.clear() self.ui.comboBox_y1.clear() self.ui.comboBox_y2.clear() self.ui.comboBox_y3.clear() self.ui.comboBox_y4.clear() self.ui.comboBox_y5.clear() self.ui.comboBox_y6.clear() self.ui.comboBox_y2.addItem('None') self.ui.comboBox_y3.addItem('None') self.ui.comboBox_y4.addItem('None') self.ui.comboBox_y5.addItem('None') self.ui.comboBox_y6.addItem('None') for i in range(0, len(parameters)): self.ui.comboBox_x.addItem(parameters[i]) self.ui.comboBox_y1.addItem(parameters[i]) self.ui.comboBox_y2.addItem(parameters[i]) self.ui.comboBox_y3.addItem(parameters[i]) self.ui.comboBox_y4.addItem(parameters[i]) self.ui.comboBox_y5.addItem(parameters[i]) self.ui.comboBox_y6.addItem(parameters[i]) self.ui.comboBox_y1.setCurrentIndex(1) self.comboBox_update = False for i in range(0, len(parameters)): new_data = [parameters[i], units[i], [], []] self.data.append(new_data) while True: val = [] lines = fp.readline().replace("\n", "") if lines == '': break values = lines.split(',') for i in range(0, len(values)): if values[0] != 'Measurement was Aborted': if values[i] != '': val.append(values[i]) if temp_parameters[0] == 'Date': date_info = val[0].split(' ') if '/' not in date_info[0]: weekday = datetime.datetime.strptime( date_info[0], '%Y-%m-%d').strftime('%a') else: weekday = datetime.datetime.strptime( date_info[0], '%m/%d/%Y').strftime('%a') date = date_info[0] + ' ' + weekday + ' ' + date_info[1] self.date_time.append(date) start = 1 else: start = 0 for i in range(start, len(val)): self.data[i - start][2].append(val[i]) self.ui.pushButton_Plot.setEnabled(True) if self.Num == 0: self.ui.pushButton_Previous.setEnabled(False) if len(self.Files) == 1: self.ui.label_condition.setText( str(len(self.Files)) + ' file ready to Plot') else: self.ui.label_condition.setText( str(len(self.Files)) + ' files ready to Plot') def Find(self): try: time = float(self.ui.lineEdit_minute.text()) if time <= float(self.data[0][2][0]): self.ui.label_date.setText(self.date_time[0]) elif time >= float(self.data[0][2][len(self.data[0][2]) - 1]): self.ui.label_date.setText(self.date_time[len(self.date_time) - 1]) else: item = 0 while float(self.data[0][2][item]) - time < 0: item += 1 if abs(float(self.data[0][2][item - 1]) - time) <= abs(float(self.data[0][2][item]) - time): self.ui.label_date.setText(self.date_time[item - 1]) else: self.ui.label_date.setText(self.date_time[item]) except ValueError: self.ui.label_date.setText('') self.ui.label_condition.setText('Please enter valid time.') def Plot_ready(self): self.x_value = [] self.y1_value = [] self.y2_value = [] self.y3_value = [] self.y4_value = [] self.y5_value = [] self.y6_value = [] # The corresponding number of the comboBox self.x_num = 0 self.x_num = self.ui.comboBox_x.currentIndex() self.y1_num = 0 self.y1_num = self.ui.comboBox_y1.currentIndex() self.y2_num = 0 self.y2_num = self.ui.comboBox_y2.currentIndex() - 1 self.y3_num = 0 self.y3_num = self.ui.comboBox_y3.currentIndex() - 1 self.y4_num = 0 self.y4_num = self.ui.comboBox_y4.currentIndex() - 1 self.y5_num = 0 self.y5_num = self.ui.comboBox_y5.currentIndex() - 1 self.y6_num = 0 self.y6_num = self.ui.comboBox_y6.currentIndex() - 1 x_axis = self.data[self.x_num][0] x_unit = self.data[self.x_num][1] y1_axis = self.data[self.y1_num][0] y1_unit = self.data[self.y1_num][1] y2_axis = self.data[self.y2_num][0] y2_unit = self.data[self.y2_num][1] y3_axis = self.data[self.y3_num][0] y3_unit = self.data[self.y3_num][1] y4_axis = self.data[self.y4_num][0] y4_unit = self.data[self.y4_num][1] y5_axis = self.data[self.y5_num][0] y5_unit = self.data[self.y5_num][1] y6_axis = self.data[self.y6_num][0] y6_unit = self.data[self.y6_num][1] self.y1_color_num = 0 self.y1_color_num = self.ui.comboBox_color_y1.currentIndex() self.y1_color = self.Color(self.y1_color_num) self.y2_color_num = 0 self.y2_color_num = self.ui.comboBox_color_y2.currentIndex() self.y2_color = self.Color(self.y2_color_num) self.y3_color_num = 0 self.y3_color_num = self.ui.comboBox_color_y3.currentIndex() self.y3_color = self.Color(self.y3_color_num) self.y4_color_num = 0 self.y4_color_num = self.ui.comboBox_color_y4.currentIndex() self.y4_color = self.Color(self.y4_color_num) self.y5_color_num = 0 self.y5_color_num = self.ui.comboBox_color_y5.currentIndex() self.y5_color = self.Color(self.y5_color_num) self.y6_color_num = 0 self.y6_color_num = self.ui.comboBox_color_y6.currentIndex() self.y6_color = self.Color(self.y6_color_num) self.y1_legend = self.ui.comboBox_y1.currentText() self.y2_legend = self.ui.comboBox_y2.currentText() self.y3_legend = self.ui.comboBox_y3.currentText() self.y4_legend = self.ui.comboBox_y4.currentText() self.y5_legend = self.ui.comboBox_y5.currentText() self.y6_legend = self.ui.comboBox_y6.currentText() self.x_value = self.data[self.x_num][2] self.y1_value = self.data[self.y1_num][2] if self.y2_num != -1: self.y2_value = self.data[self.y2_num][2] if self.y3_num != -1: self.y3_value = self.data[self.y3_num][2] if self.y4_num != -1: self.y4_value = self.data[self.y4_num][2] if self.y5_num != -1: self.y5_value = self.data[self.y5_num][2] if self.y6_num != -1: self.y6_value = self.data[self.y6_num][2] self.ui.lineEdit_x.setText(x_axis + ' (' + x_unit + ')') self.ui.lineEdit_y.setText(y1_axis + ' (' + y1_unit + ')') self.ui.lineEdit_name.setText(self.Names[self.Num]) self.ui.pushButton_change_name.setEnabled(True) if len(self.Files) > 1: self.ui.pushButton_Next.setEnabled(True) self.Pre_plot() def Color(self, num): if num == 0: return 'b' elif num == 1: return 'g' elif num == 2: return 'r' elif num == 3: return 'y' elif num == 4: return 'k' elif num == 5: return 'm' def Pre_plot(self): self.reset_plot() self.axes.grid() self.x_value = numpy.array(self.x_value, dtype='float') self.y1_value = numpy.array(self.y1_value, dtype='float') self.Plot(self.x_value, self.y1_value, self.y1_color, self.y1_legend) if self.y2_num != -1: self.y2_value = numpy.array(self.y2_value, dtype='float') self.Plot(self.x_value, self.y2_value, self.y2_color, self.y2_legend) if self.y3_num != -1: self.y3_value = numpy.array(self.y3_value, dtype='float') self.Plot(self.x_value, self.y3_value, self.y3_color, self.y3_legend) if self.y4_num != -1: self.y4_value = numpy.array(self.y4_value, dtype='float') self.Plot(self.x_value, self.y4_value, self.y4_color, self.y4_legend) if self.y5_num != -1: self.y5_value = numpy.array(self.y5_value, dtype='float') self.Plot(self.x_value, self.y5_value, self.y5_color, self.y5_legend) if self.y6_num != -1: self.y6_value = numpy.array(self.y6_value, dtype='float') self.Plot(self.x_value, self.y6_value, self.y6_color, self.y6_legend) self.ui.label_condition.setText('File' + ' (' + str(self.Num + 1) + '/' + str(len(self.Files)) + ')' + ': ' + self.Names[self.Num]) self.Draw() def Next(self): self.Num = self.Num + 1 self.Open() self.Plot_ready() if self.Num == len(self.Files) - 1: self.ui.pushButton_Next.setEnabled(False) self.ui.pushButton_Previous.setEnabled(True) def Previous(self): self.Num = self.Num - 1 self.Open() self.Plot_ready() if self.Num == -1: self.ui.pushButton_Previous.setEnabled(False) self.ui.pushButton_Next.setEnabled(True) def Modify(self): try: self.modify = True if self.ui.lineEdit_x_range.text() != '': self.modify_x = True self.x_min = float( self.ui.lineEdit_x_range.text().split(',')[0]) self.x_max = float( self.ui.lineEdit_x_range.text().split(',')[1]) else: self.modify_x = False if self.ui.lineEdit_y_range.text() != '': self.modify_y = True self.y_min = float( self.ui.lineEdit_y_range.text().split(',')[0]) self.y_max = float( self.ui.lineEdit_y_range.text().split(',')[1]) else: self.modify_y = False if self.ui.checkBox_logx.isChecked(): self.log_x = True else: self.log_x = False if self.ui.checkBox_logx.isChecked(): self.log_y = True else: self.log_y = False self.Plot_ready() except ValueError: self.ui.label_condition.setText('Please enter valid Min and Max.') def Return(self): self.modify = False self.ui.lineEdit_x_range.setText('') self.ui.lineEdit_y_range.setText('') self.ui.checkBox_logx.setCheckState(False) self.ui.checkBox_logx.setCheckState(False) self.ui.pushButton_return.setEnabled(False) self.Plot_ready() def Change_name(self): self.axes.set_title(self.ui.lineEdit_name.text()) self.axes.set_xlabel(self.ui.lineEdit_x.text()) self.axes.set_ylabel(self.ui.lineEdit_y.text()) self.Draw() def Plot(self, x, y, c, l): self.axes.plot(x, y, color=c, marker='.', linestyle=':', label=l) self.axes.set_title(self.ui.lineEdit_name.text()) self.axes.set_xlabel(self.ui.lineEdit_x.text()) self.axes.set_ylabel(self.ui.lineEdit_y.text()) self.axes.legend() if self.modify: if self.modify_x: self.axes.set_xlim(self.x_min, self.x_max) if self.modify_y: self.axes.set_ylim(self.y_min, self.y_max) if self.log_x: self.axes.set_xscale('log') if self.log_y: self.axes.set_yscale('log') self.ui.label_condition.setText('Plot successfully.') def Draw(self): self.ui.mplwidget.draw() def reset_plot(self): self.ui.mplwidget.figure.clear() self.axes = self.ui.mplwidget.figure.add_subplot(111) self.ui.mplwidget.figure.subplots_adjust(left=0.06, right=0.94, top=0.92, bottom=0.08) def convert_time(self, d): date, times = d.split(" ") year, month, day = date.split("-") hour, minute, second = times.split(":") t = datetime.datetime(int(year), int(month), int(day), int(hour), int(minute), int(second)) t_sec = time.mktime(t.timetuple()) return t_sec def closeEvent(self, question): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No) # If your answer is "yes", then quit if reply == QMessageBox.Yes: question.accept() # If your answer is "no", then get back else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what everything the user wants to be initialized when the class is called. # Here we shall define the tring functions to corresponding variables. # The 'self' variable means that the function is part of the class and can be called inside and outside the class. def __init__(self, parent = None): # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to "self.ui" # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) # For the canvas. self.canvas_general = FigureCanvas(self.ui.mplwidget_general.figure) self.canvas_general.setParent(self.ui.widget_general) # We need the toolbar widget for the canvas self.mpl_toolbar_general = NavigationToolbar(self.canvas_general, self.ui.widget_general) self.canvas_import = FigureCanvas(self.ui.mplwidget_import.figure) self.canvas_import.setParent(self.ui.widget_import) # This is the toolbar widget for the import canvas self.mpl_toolbar_import = NavigationToolbar(self.canvas_import, self.ui.widget_import) self.canvas_scan = FigureCanvas(self.ui.mplwidget_scan.figure) self.canvas_scan.setParent(self.ui.widget_scan) # This is the toolbar widget for the scan canvas self.mpl_toolbar_scan = NavigationToolbar(self.canvas_scan, self.ui.widget_scan) # Create the QVBoxLayout object and add the widget into the layout vbox_general = QVBoxLayout() # The matplotlib canvas vbox_general.addWidget(self.canvas_general) # The matplotlib toolbar vbox_general.addWidget(self.mpl_toolbar_general) self.ui.widget_general.setLayout(vbox_general) # Create the QVBoxLayout object and add the widget into the Layout vbox_import = QVBoxLayout() # The matplotlib canvas vbox_import.addWidget(self.canvas_import) # The matplotlib toolbar vbox_import.addWidget(self.mpl_toolbar_import) self.ui.widget_import.setLayout(vbox_import) # Create the QVBoxLayout object and add the widget into the Layout vbox_scan = QVBoxLayout() # The matplotlib canvas vbox_scan.addWidget(self.canvas_scan) # The matplotlib toolbar vbox_scan.addWidget(self.mpl_toolbar_scan) self.ui.widget_scan.setLayout(vbox_scan) # Connect the mplwidget with canvas self.ui.mplwidget_general = self.canvas_general self.ui.mplwidget_import = self.canvas_import self.ui.mplwidget_scan = self.canvas_scan self.General_programs = General(self.ui) # Connect buttons in the General Array tab self.connect(self.ui.pushButton_plot, SIGNAL('clicked()'), self.General_programs.Plot_general) self.connect(self.ui.pushButton_clear, SIGNAL('clicked()'), self.General_programs.Clear) self.connect(self.ui.pushButton_save, SIGNAL('clicked()'), self.General_programs.Save) self.connect(self.ui.pushButton_browse_save, SIGNAL('clicked()'), self.General_programs.Browse_save) self.Keithley_programs = Keithley(self.ui) self.Keithley_programs.Refresh_visa() # Connect buttons in the Keithely tab self.connect(self.ui.pushButton_browse_keithley, SIGNAL('clicked()'), self.Keithley_programs.Browse_keithley) self.connect(self.ui.pushButton_import_keithley, SIGNAL('clicked()'), self.Keithley_programs.Import_keithley) self.connect(self.ui.pushButton_close_keithley, SIGNAL('clicked()'), self.Keithley_programs.Close_keithley) self.connect(self.ui.pushButton_select_keithley, SIGNAL('clicked()'), self.Keithley_programs.Select_keithley) self.connect(self.ui.pushButton_scan_keithley, SIGNAL('clicked()'), self.Keithley_programs.Scan_keithley) self.connect(self.ui.pushButton_stop_keithley, SIGNAL('clicked()'), self.Keithley_programs.Stop_keithley) self.connect(self.ui.pushButton_clear_keithley, SIGNAL('clicked()'), self.Keithley_programs.Clear_keithley) self.Values = [] self.Step = [] self.Peak = [] self.round = 0 self.new_start = 0 self.ui.lineEdit_directory_save.setText(os.getcwd()) # Make sure the user is going to quit the program def closeEvent(self, event): quit_msg = "DO you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: question.accept() else: question.ignore()
class MyForm(QMainWindow): # The __init__ function is what is everything the user wants to be initialized when the class is called. # Here we shall define the trig functions to corresponding variables. # Note that the "self" variable means that the function is part of the class and can be called inside and outside the class.(Although __init__ is special.) def __init__(self, parent = None): self.collect_data_thread = Collect_data() # Standard GUI code QWidget.__init__(self, parent) # All the GUI data and widgets in the Ui_MainWindow() class is defined to self.ui # Thus to do anything on the GUI, the commands must go through this variable self.ui = Ui_MainWindow() self.ui.setupUi(self) self.connect(self.ui.pushButton_update_1, SIGNAL('clicked()'), lambda : self.Update("visa1", self.ui.comboBox_visa_1)) self.connect(self.ui.pushButton_update_2, SIGNAL('clicked()'), lambda : self.Update("visa2", self.ui.comboBox_visa_2)) self.connect(self.ui.pushButton_update_3, SIGNAL('clicked()'), lambda : self.Update("visa3", self.ui.comboBox_visa_3)) self.connect(self.ui.pushButton_update_4, SIGNAL('clicked()'), lambda : self.Update("visa4", self.ui.comboBox_visa_4)) self.connect(self.ui.pushButton_update_5, SIGNAL('clicked()'), lambda : self.Update("visa5", self.ui.comboBox_visa_5)) self.connect(self.ui.pushButton_select_1, SIGNAL('clicked()'), lambda : self.Select("visa1", self.visa1, self.ui.comboBox_visa_1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_select_2, SIGNAL('clicked()'), lambda : self.Select("visa2", self.visa2, self.ui.comboBox_visa_2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_select_3, SIGNAL('clicked()'), lambda : self.Select("visa3", self.visa3, self.ui.comboBox_visa_3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_select_4, SIGNAL('clicked()'), lambda : self.Select("visa4", self.visa4, self.ui.comboBox_visa_4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_select_5, SIGNAL('clicked()'), lambda : self.Select("visa5", self.visa5, self.ui.comboBox_visa_5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_close_1, SIGNAL('clicked()'), lambda : self.Close("visa1", self.visa1, self.ui.label_visa_1, [self.ui.pushButton_select_1, self.ui.pushButton_close_1])) self.connect(self.ui.pushButton_close_2, SIGNAL('clicked()'), lambda : self.Close("visa2", self.visa2, self.ui.label_visa_2, [self.ui.pushButton_select_2, self.ui.pushButton_close_2])) self.connect(self.ui.pushButton_close_3, SIGNAL('clicked()'), lambda : self.Close("visa3", self.visa3, self.ui.label_visa_3, [self.ui.pushButton_select_3, self.ui.pushButton_close_3])) self.connect(self.ui.pushButton_close_4, SIGNAL('clicked()'), lambda : self.Close("visa4", self.visa4, self.ui.label_visa_4, [self.ui.pushButton_select_4, self.ui.pushButton_close_4])) self.connect(self.ui.pushButton_close_5, SIGNAL('clicked()'), lambda : self.Close("visa5", self.visa5, self.ui.label_visa_5, [self.ui.pushButton_select_5, self.ui.pushButton_close_5])) self.connect(self.ui.pushButton_Start, SIGNAL('clicked()'), self.start) self.connect(self.ui.pushButton_Stop, SIGNAL('clicked()'), self.collect_data_thread.stop) self.connect(self.ui.pushButton_Pause, SIGNAL('clicked()'), self.collect_data_thread.pause) self.connect(self.collect_data_thread, SIGNAL("curve_plot"), self.curvePlots_update) self.connect(self.collect_data_thread, SIGNAL("print"), self.Print_data) self.Update("visa1", self.ui.comboBox_visa_1) self.Update("visa2", self.ui.comboBox_visa_2) self.Update("visa3", self.ui.comboBox_visa_3) self.Update("visa4", self.ui.comboBox_visa_4) self.Update("visa5", self.ui.comboBox_visa_5) self.curve_1 = self.make_curveWidgets(self.ui.curvewidget_1, "b", titles = ["Plot 1", "X (x)", "Y (y)"]) self.curve_2 = self.make_curveWidgets(self.ui.curvewidget_2, "b", titles = ["Plot 2", "X (x)", "Y (y)"]) self.curve_3 = self.make_curveWidgets(self.ui.curvewidget_3, "b", titles = ["Plot 3", "X (x)", "Y (y)"]) self.curve_4 = self.make_curveWidgets(self.ui.curvewidget_4, "b", titles = ["Plot 4", "X (x)", "Y (y)"]) self.visa1 = None self.visa2 = None self.visa3 = None self.visa4 = None self.visa5 = None def Update(self, signal, comboBoxVisa): rm = visa.ResourceManager() try: alls = rm.list_resources() except: alls = "No Visa Available." if signal == "visa1": self.ui.comboBox_visa_1.clear() elif signal == "visa2": self.ui.comboBox_visa_2.clear() elif signal == "visa3": self.ui.comboBox_visa_3.clear() elif signal == "visa4": self.ui.comboBox_visa_4.clear() elif signal == "visa5": self.ui.comboBox_visa_5.clear() for temp in alls: if signal == "visa1": self.ui.comboBox_visa_1.addItem(temp) elif signal == "visa2": self.ui.comboBox_visa_2.addItem(temp) elif signal == "visa3": self.ui.comboBox_visa_3.addItem(temp) elif signal == "visa4": self.ui.comboBox_visa_4.addItem(temp) elif signal == "visa5": self.ui.comboBox_visa_5.addItem(temp) def Select(self, signal, visa_chosen, comboBoxVisa, lineEditVisa, selectClose): visa_address = str(comboBoxVisa.currentText()) rm = visa.ResourceManager() rm.list_resources() inst = rm.open_resource(visa_address) visa_check = self.Check(inst) if visa_check == True: self.ui.label_condition.setText("Visa is selected succefully!") visa_name = inst.query("*IDN?") name_list = visa_name.split(',') first_name = name_list[0] if signal == "visa1": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.Enable(signal) self.visa1 = inst elif signal == "visa2": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.Enable(signal) self.visa2 = inst elif signal == "visa3": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.Enable(signal) self.visa3 = inst elif signal == "visa4": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.Enable(signal) self.visa4 = inst elif signal == "visa5": lineEditVisa.setText(visa_name) selectClose[0].setEnabled(False) selectClose[1].setEnabled(True) self.Enable(signal) self.visa5 = inst elif visa_check == False: self.ui.label_condition.setText("Invalid visa address.") lineEditVisa.setText("None.") visa_chosen = False def Close(self, signal, visa_chosen, lineEditVisa, selectClose): self.ui.label_condition.setText('Visa address is closed') lineEditVisa.setText('') selectClose[0].setEnabled(True) selectClose[1].setEnabled(False) if signal == "visa1": visa_chosen.close() self.visa1 = None self.Disable(signal) elif signal == "visa2": visa_chosen.close() self.visa2 = None self.Disable(signal) elif signal == "visa3": visa_chosen.close() self.visa3 = None self.Disable(signal) elif signal == "visa4": visa_chosen.close() self.visa4 = None self.Disable(signal) elif signal == "visa5": visa_chosen.close() self.visa5 = None self.Disable(signal) def Check(self, inst): try: inst.ask("*IDN?") valid = True except: valid = False return valid def make_curveWidgets(self, curvewidget, color, titles): curve_temp = make.curve([], [], color = 'b', marker = "o") curvewidget.plot.add_item(curve_temp) curvewidget.plot.set_antialiasing(True) curvewidget.plot.set_titles(titles[0], titles[1], titles[2]) return curve_temp def start(self): instruments = [self.visa1, self.visa2, self.visa3, self.visa4, self.visa5] curves = [self.curve_1, self.curve_2, self.curve_3, self.curve_4] curveWidgets =[self.ui.curvewidget_1, self.ui.curvewidget_2, self.ui.curvewidget_3, self.ui.curvewidget_4] go_on = None self.collect_data_thread.input(self.ui, instruments, curves, curveWidgets, go_on) def curvePlots_update(self, curveInfo): curveWidget = curveInfo[0] curve = curveInfo[1] curveWidget.plot.do_autoscale() curve.plot().replot() def Print_data(self, step, time, V1, V2, V3, V4, V5, V6): self.ui.label_step.setText(step) self.ui.label_time.setText(time) self.ui.label_V1.setText(V1) self.ui.label_V2.setText(V2) self.ui.label_V3.setText(V3) self.ui.label_V4.setText(V4) self.ui.label_V5.setText(V5) self.ui.label_V6.setText(V6) def Switch_scale(self, num): temp = abs(num) if temp >= 1E9: scale = [1E-9, "G"] elif temp >= 1E6 and temp < 1E9: scale = [1E-6, "M"] elif temp >= 1E3 and temp < 1E6: scale = [1E-3, "k"] elif temp >= 1 and temp < 1000: scale = [1, ""] elif temp >= 1E-3 and temp < 1: scale = [1E3, "m"] elif temp >= 1E-6 and temp < 1E-3: scale = [1E6, "u"] elif temp >= 1E-9 and temp < 1E-6: scale = [1E9, "n"] elif temp < 1E-9: scale = [1E12, "p"] return scale def closeEvent(self, event): quit_msg = "Do you want to quit the program?" reply = QMessageBox.question(self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()