From 6cba52f707224d5aca6382fe7df38963e70d4387 Mon Sep 17 00:00:00 2001 From: brahim Date: Mon, 4 Nov 2024 10:54:57 +0100 Subject: [PATCH] Calibration constant kt is read from a external excel file. This file has several sheet for different calibration. The user can add sheet. --- Model/calibration_constant_kt.py | 84 +++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/Model/calibration_constant_kt.py b/Model/calibration_constant_kt.py index 0f02ade..c1743e1 100644 --- a/Model/calibration_constant_kt.py +++ b/Model/calibration_constant_kt.py @@ -4,11 +4,14 @@ import os import pandas as pd from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtWidgets import (QWidget, QLabel, QHBoxLayout, QVBoxLayout, QApplication, QMainWindow, QGridLayout, - QDialog, QDialogButtonBox, QPushButton, QTextEdit, QFrame, QTabWidget, QScrollArea, QLineEdit) + QDialog, QDialogButtonBox, QPushButton, QTextEdit, QFrame, QTabWidget, QScrollArea, + QLineEdit, QFileDialog) from PyQt5.QtCore import Qt import numpy as np +from os import path + import matplotlib.pyplot as plt from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar @@ -24,10 +27,15 @@ from settings import depth_cross_section class CalibrationConstantKt(QDialog): + icon_folder = ( + "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/acoused/icons/folder.png") + def __init__(self, parent=None): super(CalibrationConstantKt, self).__init__(parent) + + self.setGeometry(400, 200, 300, 400) self.setWindowTitle("Calibration constant kt") @@ -35,13 +43,49 @@ class CalibrationConstantKt(QDialog): self.verticalLayout_Main = QVBoxLayout() self.setLayout(self.verticalLayout_Main) + self.horizontalLayout_file = QHBoxLayout() + self.verticalLayout_Main.addLayout(self.horizontalLayout_file) + + self.pushbutton_file = QPushButton() + self.pushbutton_file.setIcon(QIcon(CalibrationConstantKt.icon_folder)) + self.horizontalLayout_file.addWidget(self.pushbutton_file) + # self.pushbutton_file.clicked.connect(self.open_dialog_box) + + self.lineEdit_file = QLineEdit() + self.horizontalLayout_file.addWidget(self.lineEdit_file) + self.tab = QTabWidget() self.verticalLayout_Main.addWidget(self.tab) - + # "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/acoused/ self.data_ABS = pd.read_excel("ABS_calibration_constant_kt.xlsx", header=0, sheet_name=None) + self.lineEdit_file.setText("ABS_calibration_constant_kt.xlsx") + + print([*self.data_ABS.values()][0].columns[1]) + + self.load_freq_and_kt_values() + + def open_dialog_box(self): + filename = QFileDialog.getOpenFileNames(self, "Calibration file", "", "Calibration file (*.xlsx)", + options=QFileDialog.DontUseNativeDialog) + print(filename) + dir_name = path.dirname(filename[0][0]) + file_name = path.basename(filename[0][0]) + print(f"dir name : {dir_name} & file name : {file_name}") + + self.data_ABS = pd.read_excel(dir_name + "/" + file_name) + + self.lineEdit_file.setText(file_name) + + self.load_freq_and_kt_values() + + def load_freq_and_kt_values(self): + + for t in range(len(self.data_ABS.keys())): + self.tab.removeTab(t) + for t_index, t_value in enumerate(list(self.data_ABS.keys())): - print("t = ", t_index, t_value) + exec("self.tab_" + str(t_index) + "= QWidget()") eval("self.tab.addTab(self.tab_" + str(t_index) + ", '" + str(t_value) + "')") @@ -55,27 +99,33 @@ class CalibrationConstantKt(QDialog): eval("self.verticalLayout_tab_" + str(t_index) + ".addWidget(self.scrollarea_tab_" + str(t_index) + ")") exec("self.gridLayout_tab_" + str(t_index) + " = QGridLayout(self.scrollarea_tab_" + str(t_index) + ")") - - exec("self.label_freq_" + str(t_index) + " = QLabel('Frequency')") + if [*self.data_ABS.values()][t_index].columns.any(): + exec("self.label_freq_" + str(t_index) + " = QLabel('" + str([*self.data_ABS.values()][t_index].columns[0]) + " (MHz)')") + exec("self.label_kt_" + str(t_index) + " = QLabel('" + str([*self.data_ABS.values()][t_index].columns[1]) + " (V.m1.5)')") + else: + exec("self.label_freq_" + str(t_index) + " = QLabel('Frequency (MHz)')") + exec("self.label_kt_" + str(t_index) + " = QLabel('kt (V.m1.5)')") eval("self.gridLayout_tab_" + str(t_index) + ".addWidget(self.label_freq_" + str(t_index) + ", 0, 0, 1, 1, Qt.AlignCenter)") - exec("self.label_kt_" + str(t_index) + " = QLabel('kt')") eval("self.gridLayout_tab_" + str(t_index) + ".addWidget(self.label_kt_" + str(t_index) + ", 0, 1, 1, 1, Qt.AlignCenter)") for x in range(self.data_ABS[t_value].shape[0]): - exec("self.label_freq_" + str(x) + "_ABS_" + str(t_index) + " = QLabel('" + str(self.data_ABS[t_value].iloc[x][0]) + " MHz')") + exec("self.label_freq_" + str(x) + "_ABS_" + str(t_index) + " = QLabel()") + # print(eval("self.label_freq_" + str(x) + "_ABS_" + str(t_index) + ".setText('" + str(self.data_ABS[t_value].iloc[x][0]*1e-6) + " MHz')")) + eval("self.label_freq_" + str(x) + "_ABS_" + str(t_index) + ".setText('" + str(self.data_ABS[t_value].iloc[x][0]*1e-6) + " (MHz)')") + # eval("self.label_freq_" + str(x) + "_ABS_" + str(t_index) + ".setDisabled(True)") eval("self.gridLayout_tab_" + str(t_index) + ".addWidget(self.label_freq_" + str(x) + "_ABS_" + str(t_index) + ", " + str(x + 1) + ", 0, 1, 1,Qt.AlignCenter)") - exec("self.lineEdit_" + str(x) + "_ABS_" + str(t_index) + " = QLineEdit()") - exec("self.lineEdit_" + str(x) + "_ABS_" + str(t_index) + ".setText('" + str(self.data_ABS[t_value].iloc[x][1]) + "')") - exec("self.lineEdit_" + str(x) + "_ABS_" + str(t_index) + ".setMaximumWidth(" + str(100) + ")") - eval("self.gridLayout_tab_" + str(t_index) + ".addWidget(self.lineEdit_" + str(x) + "_ABS_" + str(t_index) + + exec("self.label_kt_" + str(x) + "_ABS_" + str(t_index) + " = QLabel()") + exec("self.label_kt_" + str(x) + "_ABS_" + str(t_index) + ".setText('" + str(self.data_ABS[t_value].iloc[x][1]) + "V.m1.5')") + eval("self.label_kt_" + str(x) + "_ABS_" + str(t_index) + ".setStyleSheet('border: 1px solid black;')") + eval("self.gridLayout_tab_" + str(t_index) + ".addWidget(self.label_kt_" + str(x) + "_ABS_" + str(t_index) + ", " + str(x+1) + ", 1, 1, 1, Qt.AlignCenter)") -# if __name__ == "__main__": -# app = QApplication(sys.argv) -# cal = CalibrationConstantKt() -# cal.show() -# # sys.exit(app.exec_()) -# app.exec() +if __name__ == "__main__": + app = QApplication(sys.argv) + cal = CalibrationConstantKt() + cal.show() + # sys.exit(app.exec_()) + app.exec()