Skip to content
Snippets Groups Projects
climate-lab-gui.py 2.72 KiB
Newer Older
Martin Killenberg's avatar
Martin Killenberg committed
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QTextEdit
from PyQt5 import uic, QtCore, QtGui, QtWidgets
import sys
import prototype
import json
Martin Killenberg's avatar
Martin Killenberg committed

class TestStandMainWindow(QMainWindow):
    def __init__(self, qt_app, *args, **kwargs):
Martin Killenberg's avatar
Martin Killenberg committed
        super().__init__(*args, **kwargs)
        uic.loadUi('climate-lab-main.ui', self)
Martin Killenberg's avatar
Martin Killenberg committed

        self.startButton.clicked.connect(lambda: self.do_measurement())

    def do_measurement(self):
        if self.humSweepButton.isChecked():
            QtWidgets.QMessageBox.information(self, 'Information', 'Humidity sweep is not implemented yet!')
            return

        self.setEnabled(False)
        self.qt_app.processEvents();

        with open('test_stand_parameter.json', 'r') as f:
            config_data = json.load(f)

        if self.autoNameCheckbox.isChecked():
            output_basename = time.strftime("%Y_%m_%d-%H_%M_%S") + "_results"
        else:
            output_basename = self.baseName.text()
        meas = prototype.Measurements(config_data['chamber_ip'], config_data['vna_ip'], output_basename,
                                      False, config_data)
        try:
            if self.tempSweepButton.isChecked():
                temperatures = meas.perform_temperature_sweep(self.startParameter.value(), self.stopParameter.value(),
                                                              self.stepParameter.value(),
                                                              self.fixedParameter.value(), self.soakingTime.value(),
                                                              self.stableReads.value())
                temp_extensions = []
                for t in temperatures:
                    temp_extensions.append(str(t)+'deg_'+str(self.fixedParameter.value())+'rh')
                prototype.plot_output(output_basename, temp_extensions, True, output_basename +
                                      ': Temperature sweep ' + str(temperatures[0]) + '--' +
                                      str(temperatures[-1]) + ' degC @ '+ str(self.fixedParameter.value()) + ' % r.h.')

            elif self.measurementFileButton.isChecked():
                try:
                    n_measurements = meas.perform_measurements(self.measurementFile.text())
                    prototype.plot_output(output_basename, range(n_measurements), True, output_basename)
                except FileNotFoundError as e:
                    QtWidgets.QMessageBox.warning(self, 'Warning', str(e))


        finally:
            meas.chamber.close()
            self.setEnabled(True)

Martin Killenberg's avatar
Martin Killenberg committed

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = TestStandMainWindow(app)
    mainWindow.show()
    app.exec_()