code of index.py :
here is the download link for the main.py file :
fichier main.py attached to index.py
#!/usr/bin/python3 # -*- coding: utf-8 -*- ############################################################### # import os : import os, errno from os import path import pathlib import sys import logging ############################################################### # Fix qt import error : Include this file before import PyQt5 def _append_run_path(): if getattr(sys, 'frozen', False): pathlist = [] # If the application is run as a bundle, the pyInstaller bootloader # extends the sys module by a flag frozen=True and sets the app # path into variable _MEIPASS'. pathlist.append(sys._MEIPASS) # the application exe path _main_app_path = os.path.dirname(sys.executable) pathlist.append(_main_app_path) # append to system path enviroment os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist) logging.error("current PATH: %s", os.environ['PATH']) _append_run_path() ############################################################### # PyQT5 : from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtGui import * #import date and time : import time import datetime import datetime as dt from datetime import datetime ############################################################### # import of the math module to work with the log10 method: import math ############################################################### # import of the sqlite3 module to work with table and database: import sqlite3 ############################################################### from main import Ui_MainWindow #####################################################à #Initiate UI_File : class MainApp(QMainWindow,Ui_MainWindow) : def __init__(self,parent=None) : super(MainApp,self).__init__(parent) QMainWindow.__init__(self) self.setupUi(self) self.win_UI() ########################################################################################################### #Function to configure the display dimensions of the application : def win_UI(self): self.setWindowTitle("ddm corrector") self.setGeometry(20,40,700,480) self.actions_on_buttons() ########################################################################################################## # function of the execution correction ddm : def calcul_of_correction (self): #function to convert somme characters to point : def convert(number) : character=[',',';',':','.','-','_'] for loop in character : number= str(number).replace(loop,'.') return number try: ground_ddm=self.lineEdit_ground_ddm.text() ground_ddm=convert(ground_ddm) ground_ddm=float(ground_ddm) flight_ddm=self.lineEdit_flight_ddm.text() flight_ddm=convert(flight_ddm) flight_ddm=float(flight_ddm) correction= 20*(math.log10(flight_ddm/ground_ddm)) correction=round(correction,3) correction =str(correction) self.lineEdit_ddm_correction_value.setText(correction) self.textEdit_display_info.setText("") except: self.textEdit_display_info.setText('<span style="font-weight:bold;font-size:14px;color:#FF0000">invalid entry.</span>') ######################################################################################################### #function for star day : def function_for_start_date(self): try: start_day = int(self.lineEdit_start_day.text()) start_month = int(self.lineEdit_start_month.text()) start_year = int(self.lineEdit_start_year.text()) start_date = dt.date(start_year, start_month, start_day) except ValueError: print('one of the tree champs of bloc start date is invalid') else: self.lineEdit_start_date.setText("{:%Y-%m-%d}".format(start_date)) print('<date for start date is created with ("year/month/day") form') ############################################################################################################ #function for end day : def function_for_end_date(self): try: end_day = int(self.lineEdit_end_day.text()) end_month = int(self.lineEdit_end_month.text()) end_year = int(self.lineEdit_end_year.text()) end_date = dt.date(end_year, end_month, end_day) except ValueError: print('one of the tree champs of bloc end date is invalid') else: self.lineEdit_end_date.setText("{:%Y-%m-%d}".format(end_date)) print('<date for end date is created with ("year/month/day") form') ########################################################################################################## ##Function to create database and store into it info : def create_database_correction(self): #fonction convertir point virgules : def convert(number) : character=[',',';',':','.','-','_'] for loop in character : number= str(number).replace(loop,'.') return number input_date =str(time.strftime("%Y-%m-%d")) input_time = str(time.strftime('%H:%M:%S')) ddm_mon1=self.lineEdit_reading_monitor1.text() input_ddm_mon1=convert(ddm_mon1)+" μA" ddm_mon2=self.lineEdit_reading_monitor2.text() input_ddm_mon2=convert(ddm_mon2) +" μA" ground_ddm=self.lineEdit_ground_ddm.text() input_ground_ddm=convert(ground_ddm) +" μA" flight_ddm = self.lineEdit_flight_ddm.text() input_flight_ddm=convert(flight_ddm) +" μA" input_ddm_correction_value = self.lineEdit_ddm_correction_value.text() +' dB' script_path_correction = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant new_path_correction=script_path_correction + '\\data_base' #concaténer au path ci-dessus le path du dossier data_base os.makedirs(new_path_correction, exist_ok=True) #creer le dossier data_base au nouveau path #create database connexion_correction = sqlite3.connect(new_path_correction+'\\correction.db') curseur_correction = connexion_correction.cursor() # Check if table loc35R does not exist and create it curseur_correction.execute('''CREATE TABLE IF NOT EXISTS correction_loc35R (reading_date_correction text, time_correction text,reading_ddm_mon1_correction text, reading_ddm_mon2_correction text, reading_ground_ddm_correction text,reading_flight_ddm_correction text, reading_ddm_correction_value text ) ''') if (self.lineEdit_reading_monitor1.text()=="") : self.textEdit_display_info.setText('<span style="color:#FF0000; font-weight: bold;font-size:15px;">invalid entry for monitor 1.</span>') elif (self.lineEdit_reading_monitor2.text()==""): self.textEdit_display_info.setText('<span style="color:#FF0000; font-weight: bold;font-size:15px;">invalid entry for monitor 2.</span>') elif (self.lineEdit_ddm_correction_value.text()=="") : self.textEdit_display_info.setText('<span style="color:#FF0000; font-weight: bold;font-size:15px;">invalid entry for value of correction ddm.</span>') elif (self.lineEdit_flight_ddm.text()=="") : self.textEdit_display_info.setText('<span style="color:#FF0000; font-weight: bold;font-size:15px;">invalid entry for flight ddm</span>') else: curseur_correction.execute('''INSERT INTO correction_loc35R VALUES (?,?,?,?,?,?,?) ''', (input_date,input_time, input_ddm_mon1, input_ddm_mon2, input_ground_ddm, input_flight_ddm, input_ddm_correction_value)) self.textEdit_display_info.setText('<span style=" color:#00aa00;font-size:15px;font-weight: bold;">storage of info into database with success.</span>') connexion_correction.commit() curseur_correction.close() connexion_correction.close() ########################################################################################################### #Fuction to dispaly content of database : def Display_flight_control_operations(self): script_path_dispaly = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant new_path_dispaly=script_path_dispaly + '\\data_base' #concaténer au path ci-dessus le path du dossier data_base os.makedirs(new_path_dispaly, exist_ok=True) #creer le dossier data_base au nouveau path try: conn_dispaly = sqlite3.connect (new_path_dispaly +'\\correction.db') curseur_dispaly =conn_dispaly .cursor() c_dispaly =curseur_dispaly .execute("SELECT * FROM correction_loc35R ORDER BY reading_date_correction DESC ") liste_dispaly=c_dispaly.fetchall() # set row count self.tableWidget_display.setRowCount(len(liste_dispaly)) #insertion des donnees de la bdd dans la Qtablewidget: pushButton_rafraichir_contenu_des_listes_releves_mesure_gp35L for nb_lignes_display in range(len(liste_dispaly)): for nombre_colonnes_display in range(7): self.tableWidget_display.setItem(nb_lignes_display,nombre_colonnes_display, QTableWidgetItem(liste_dispaly[nb_lignes_display][nombre_colonnes_display])) #mettre la couleur verte pour la ligne contenant la confirmation 'OK' if (self.tableWidget_display.item(nb_lignes_display,nombre_colonnes_display).text())=='OK' : for j in range(nombre_colonnes_display +1): self.tableWidget_display.item(nb_lignes_display,j).setBackground(QtGui.QColor(0, 204, 0)) self.tableWidget_display.resizeRowsToContents() self.tableWidget_display.resizeColumnsToContents() #fermeture du cursor curseur_dispaly.close() #fermeture de la connexion à la bdd conn_dispaly.close() except : print("eror") ########################################################################################################## # function to display selection of flight operations by dates : def select_by_dates (self): script_path_selection = os.path.dirname(os.path.realpath(__file__)) new_path_selection=script_path_selection + '\\data_base' os.makedirs(new_path_selection, exist_ok=True) try : start_date =self.lineEdit_start_date.text() end_date = self.lineEdit_end_date.text() conn = sqlite3.connect (new_path_selection+'\\correction.db') curseur=conn.cursor() strSQL = '' strSQL += "SELECT * " strSQL += "FROM correction_loc35R " strSQL += "WHERE reading_date_correction" strSQL += "BETWEEN " + start_date.strftime('%Y-%m-%d') strSQL += "AND " + end_date.strftime('%Y-%m-%d') c=curseur.execute(strSQL) liste_selection=c.fetchall() nbr_rows_loc35R=len(liste_selection) if nbr_rows_loc35R != 0 : # set row count self.tableWidget_selection.setRowCount(nbr_rows_loc35R) for nb in range(nbr_rows_loc35R): for nombre in range(7): self.tableWidget_selection.setItem(nb,nombre, QTableWidgetItem(liste_selection[nb][nombre])) self.tableWidget_selection.resizeRowsToContents() self.tableWidget_selection.resizeColumnsToContents() conn.commit() curseur.close() conn.close() else : print("OK") except : print("error") ######################################################################################################### #Function for commands carried out by buttons: def actions_on_buttons(self): self.pushButton_execute_correction.clicked.connect(self.calcul_of_correction) self.pushButton_store_in_database.clicked.connect(self.create_database_correction) self.pushButton_update_display_correction.clicked.connect(self.Display_flight_control_operations) self.pushButton_activate_start_date.clicked.connect(self.function_for_start_date) self.pushButton_activate_end_date.clicked.connect(self.function_for_end_date) self.pushButton_search_selection.clicked.connect(self.select_by_dates) ########################################################################################################## def main(): app=QApplication(sys.argv) win=MainApp() win.show() app.exec_()# infinite loop if __name__=='__main__' : main()The main.py file linked to the index.py file, is obtained from the main.ui file (by QtDesigner) :
here is the download link for the main.py file :
fichier main.py attached to index.py