import sys 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, 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 from matplotlib.colors import LogNorm, BoundaryNorm import datetime import settings as stg from Translation.constant_string import HORIZONTAL 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") 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())): exec("self.tab_" + str(t_index) + "= QWidget()") eval("self.tab.addTab(self.tab_" + str(t_index) + ", '" + str(t_value) + "')") exec("self.verticalLayout_tab_" + str(t_index) + "= QVBoxLayout(self.tab_" + str(t_index) + ")") exec("self.scrollarea_tab_" + str(t_index) + " = QScrollArea(self.tab_" + str(t_index) + ")") eval("self.scrollarea_tab_" + str(t_index) + ".setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)") eval("self.scrollarea_tab_" + str(t_index) + ".setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)") eval("self.scrollarea_tab_" + str(t_index) + ".setWidgetResizable(True)") 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) + ")") 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)") 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()") # 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.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()