Python Forum
What do you think of this procedure to create a path to a folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What do you think of this procedure to create a path to a folder
#1
Hi; here is a sample of the code of my application being created:

import os
from os import path
import pathlib
import sys

scriptDirectory=os.path.dirname(os.path.realpath(__file__)) 
path_directory=scriptDirectory + '\\data_base' 
os.makedirs(path_directory, exist_ok=True) 

connexion = sqlite3.connect(path_directory + '\\ils35R.db')

curseur = connexion.cursor()

curseur.execute('''CREATE TABLE IF NOT EXISTS loc35R (date_loc35R text, time_loc35R text,mon_loc35R text )  ''') 
               
curseur.execute('''INSERT INTO loc35R VALUES (?,?,?) ''', (lecture_date_loc35R,lecture_time_loc35R, lecture_mon_loc35R))           
            
connexion.commit()

curseur.close()

connexion.close()
the code works well, but during the conversion of the python file to an executable file: there is a path error with pyinstaller
Reply
#2
Did you read and understand that part of the docs?
https://pyinstaller.readthedocs.io/en/st...ation.html

especially the part about using __file__
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
this sentence from the beginning of the link content:
" Your app should run in a bundle exactly as it does when run from source"
indicates that the application should work in a virtual environment with pyinstaller in the same way with the source code
I think I have somme problems to understand well this concept
for information , I proceeded to create the executable via the file file.spec :

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['index.py'],
             pathex=['test\\Lib\\site-packages\\PyQt5\\Qt\\bin'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='index',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='index')
Reply
#4
For your benefit I copy the relevant section here (I make the bold parts for emphasis)

--- EXTRACT FROM PYINSTALER DOCS---

Using __file__

When your program is not bundled, the Python variable __file__ refers to the current path of the module it is contained in. When importing a module from a bundled script, the PyInstaller bootloader will set the module’s __file__ attribute to the correct path relative to the bundle folder.

For example, if you import mypackage.mymodule from a bundled script, then the __file__ attribute of that module will be sys._MEIPASS + 'mypackage/mymodule.pyc'. So if you have a data file at mypackage/file.dat that you added to the bundle at mypackage/file.dat, the following code will get its path (in both the non-bundled and the bundled case):

from os import path
path_to_dat = path.join(path.dirname(__file__), 'file.dat')
In the bundled main script itself the above might not work, as it is unclear where it resides in the package hierarchy. So in when trying to find data files relative to the main script, sys._MEIPASS can be used. The following will get the path to a file other-file.dat next to the main script if not bundled and in the bundle folder if it is bundled:

from os import path
import sys
bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_dat = path.join(bundle_dir, 'other-file.dat')
---- END OF EXTRACT ---

The last snippet show what/how you need to change your code (not the spc file).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
to create database file, I proceeded with this sample code :

scriptDirectory=os.path.dirname(os.path.realpath(__file__)) 
path_directory=scriptDirectory + '\\data_base' 
os.makedirs(path_directory, exist_ok=True) 
connexion = sqlite3.connect(path_directory + '\\ils35R.db')
I can't find how to use the code below to create my database file:
bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_dat = path.join(bundle_dir, 'other-file.dat')
I need help to do that
thanks
Reply
#6
I modified my code about the creation of the database, and the creation of the text file which contains the information stored in a data base

last code to create dbb:

scriptDirectory=os.path.dirname(os.path.realpath(__file__)) 
path_directory=scriptDirectory + '\\data_base' 
os.makedirs(path_directory, exist_ok=True) 
connexion = sqlite3.connect(path_directory + '\\ils35R.db')
last code to create text file :

script_path_filesave_loc35R = os.path.dirname(os.path.realpath(__file__))
new_path_filesave_loc35R=script_path_filesave_loc35R + '\\filesave'  
os.makedirs(new_path_filesave_loc35R, exist_ok=True)

local_dir = os.path.dirname(__file__)
with open(os.path.join(local_dir, "filesave/loc35R.txt"), "w",encoding="utf-8") as file_loc35R:
    file_loc35R.write(contenu_txt_file_from_loc35R)   
the new code to create dbb:

bundle_dir_data_base = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_data_base = path.join(bundle_dir_data_base, 'data_base')
os.makedirs(path_to_data_base, exist_ok=True)
connexion = sqlite3.connect(path_to_data_base + '\\ils35R.db')
new code to create text file :


       
bundle_dir_text_file_loc35R = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_text_file_loc35R = path.join(bundle_dir_text_file_loc35R, 'filesave')
os.makedirs(path_to_text_file_loc35R, exist_ok=True)
with open(path_to_text_file +'\\loc35R.txt', "w",encoding="utf-8") as file_loc35R:
    file_loc35R.write(contenu_txt_file_from_loc35R)
during the execution of the index.py file with visual studio code, it works correctly without any problem: creation of the folders for the backup of the database and text files.
during the conversion of this python file (index.py) to plugir executable (index.exe) with pyinstaller, I get the build and dist files. By executing the index.exe file contained in the dist folder I get this error :

[Image: 5fvk.jpg]

and finnaly there is the information in CMD during conversion index.py to index.exe :

Quote:C:\Users\hamada\Desktop\ddm_test>pyinstaller index.spec
162 INFO: PyInstaller: 3.5
162 INFO: Python: 3.6.0
162 INFO: Platform: Windows-10-10.0.17763-SP0
162 INFO: UPX is not available.
162 INFO: Extending PYTHONPATH with paths
['C:\\Users\\hamada\\Desktop\\ddm_test',
'C:\\Users\\hamada\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\PyQt5\\Qt\\bin',
'C:\\Users\\hamada\\Desktop\\ddm_test']
162 INFO: checking Analysis
162 INFO: Building Analysis because Analysis-00.toc is non existent
162 INFO: Initializing module dependency graph...
162 INFO: Initializing module graph hooks...
178 INFO: Analyzing base_library.zip ...
6146 INFO: running Analysis Analysis-00.toc
6154 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\hamada\appdata\local\programs\python\python36\python.exe
7083 INFO: Caching module hooks...
7099 INFO: Analyzing index_copy.py
7482 INFO: Processing pre-find module path hook PyQt5.uic.port_v3
7522 INFO: Processing pre-find module path hook PyQt5.uic.port_v2
8546 INFO: Loading module hooks...
8546 INFO: Loading module hook "hook-encodings.py"...
8731 INFO: Loading module hook "hook-pydoc.py"...
8731 INFO: Loading module hook "hook-PyQt5.py"...
8963 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
9471 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
10247 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
12018 INFO: Loading module hook "hook-PyQt5.uic.py"...
12018 INFO: Loading module hook "hook-sqlite3.py"...
12199 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
12199 INFO: Loading module hook "hook-xml.py"...
12692 INFO: Looking for ctypes DLLs
12692 INFO: Analyzing run-time hooks ...
12700 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
12710 INFO: Looking for dynamic libraries
24150 INFO: Looking for eggs
24150 INFO: Using Python library c:\users\hamada\appdata\local\programs\python\python36\python36.dll
24150 INFO: Found binding redirects:
[]
24166 INFO: Warnings written to C:\Users\hamada\Desktop\ddm_test\build\index\warn-index.txt
24266 INFO: Graph cross-reference written to C:\Users\hamada\Desktop\ddm_test\build\index\xref-index.html
24273 INFO: Appending 'datas' from .spec
24288 INFO: checking PYZ
24288 INFO: Building PYZ because PYZ-00.toc is non existent
24288 INFO: Building PYZ (ZlibArchive) C:\Users\hamada\Desktop\ddm_test\build\index\PYZ-00.pyz
25930 INFO: Building PYZ (ZlibArchive) C:\Users\hamada\Desktop\ddm_test\build\index\PYZ-00.pyz completed successfully.
25945 INFO: checking PKG
25945 INFO: Building PKG because PKG-00.toc is non existent
25945 INFO: Building PKG (CArchive) PKG-00.pkg
26014 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
26014 INFO: Bootloader c:\users\hamada\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
26014 INFO: checking EXE
26014 INFO: Building EXE because EXE-00.toc is non existent
26014 INFO: Building EXE from EXE-00.toc
26014 INFO: Appending archive to EXE C:\Users\hamada\Desktop\ddm_test\build\index\index.exe
26030 INFO: Building EXE from EXE-00.toc completed successfully.
26030 INFO: checking COLLECT
26030 INFO: Building COLLECT because COLLECT-00.toc is non existent
WARNING: The output directory "C:\Users\hamada\Desktop\ddm_test\dist\index_copy" and ALL ITS CONTENTS will be REMOVED! Continue? (y/N)y
82890 INFO: Removing dir C:\Users\hamada\Desktop\ddm_test\dist\index_copy
82974 INFO: Building COLLECT COLLECT-00.toc
83910 INFO: Building COLLECT COLLECT-00.toc completed successfully.

C:\Users\hamada\Desktop\ddm_test>
Reply
#7
what is index_copy script and how it is used in rest of your code? Do you have other external packages (I see PyQT)

It may happen that pyinstaller cannot find all imported modules and you need to specify them as hidden imports. From the output it looks like it found PyQT
check https://pyinstaller.readthedocs.io/en/st...wrong.html
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
going back to the question of the paths (it has nothing to do with latest error) for db and text files
where do you want to create the database? I may have mislead you when refer to _MEIPASS and I apologise if that is the case

look at the sample script that is provided in the pyinstaller docs
import sys, os
frozen = 'not'
if getattr(sys, 'frozen', False):
        # we are running in a bundle
        frozen = 'ever so'
        bundle_dir = sys._MEIPASS
else:
        # we are running in a normal Python environment
        bundle_dir = os.path.dirname(os.path.abspath(__file__))
print( 'we are',frozen,'frozen')
print('__file__ is', __file__)
print('__file__ abspath is', os.path.abspath(__file__))
print( 'bundle dir is', bundle_dir )
print( 'sys.argv[0] is', sys.argv[0] )
print( 'sys.executable is', sys.executable )
print( 'os.getcwd is', os.getcwd() )
input()
I have it as pypaths.py in c:\sandbox\pypaths.py

Output:
we are not frozen __file__ is c:/sandbox/pypaths.py __file__ abspath is c:\sandbox\pypaths.py bundle dir is c:\sandbox sys.argv[0] is c:/sandbox/pypaths.py sys.executable is C:\Program Files (x86)\Python37-32\python.exe os.getcwd is C:\sandbox
if I freeze it and run the exe from C:\sandbox\pypaths.exe

the output is
Output:
we are ever so frozen __file__ is pypaths.py __file__ abspath is C:\sandbox\pypaths.py bundle dir is C:\Users\***\AppData\Local\Temp\_MEI124082 sys.argv[0] is C:\sandbox\pypaths.exe sys.executable is C:\sandbox\pypaths.exe os.getcwd is C:\sandbox
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
index_copy.py is a copy of index.py (I want to test with the copy ) and the total script is a desktop apllication created with the Qt Designer and PyQt5.

index.py:

[python]
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import os :
import os
from os import path
import sys

from pathlib import Path
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()



from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType



###########################################################################
import time
import datetime

##########################################################################
# import du module math pour travailler avec la methode log10 :
import math

##########################################################################
# import du module sqlite3 pour travailler avec table et bdd :
import sqlite3

#################################################################################
#import du module Prettytable pour avoir contenu du fichier texte bien organise :
from prettytable import from_db_cursor

################################################################################
# appel aux contenus des fichiers externes (info.py,raccourcis_clavier.py) :
#################################################################################
from app_ddm import Ui_MainWindow
# import contenu du fichier info.py :
from info import *
#####################################
# import contenu du fichier raccourcis_clavier.py :
from raccourcis_clavier import *
############################################################################

# import UI_File :
FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__),"app_ddm.ui"))

#Initiate UI_File :
class MainApp(QMainWindow,FORM_CLASS) :
def __init__(self,parent=None) :
super(MainApp,self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)

self.window_UI()

###############################################################
#Fonction pour afficher la fenetre d'information sur l'application
def window_a_propos_de_l_application(self):
self.window=QtWidgets.QMainWindow()
self.ui=info_Window()
self.ui.setup_info(self.window)
self.window.show()

def window_raccourcis_clavier(self):
self.window=QtWidgets.QMainWindow()
self.ui=raccourci_clavier_Window()
self.ui.setup_raccourci_clavier(self.window)
self.window.show()

def resource_path(self,relative_path):
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
print(base_path)
except Exception:

base_path = os.path.abspath(".")
print(base_path)
return os.path.join(base_path, relative_path)

################################################################################

def window_UI(self):

#root = QFileInfo(__file__).absolutePath() #for absolute path of the icons
self.setWindowTitle("correction ddm faisceau")
self.setFixedWidth(836)
self.setFixedHeight(510)

#####################################################
# appel de la fonction d'action sur les boutons :
#####################################################
self.actions_sur_les_boutons()

########################################################
# appel des fonctions d'affichage des unites de mesure :
########################################################
self.afficher_unite_de_mesure_loc35R()
self.afficher_unite_de_mesure_gp35R()
self.afficher_unite_de_mesure_loc35L()
self.afficher_unite_de_mesure_gp35L()

########################################################
# appel de la fonction d'affichage de la date :
########################################################
self.afficher_date_ils35R()
self.afficher_date_ils35L()

#########################################################
# appel de la fonction d'affichage de l'heure :
########################################################
self.timer = QTimer(self)
self.timer.timeout.connect(self.afficher_time_ils35L)
self.timer.timeout.connect(self.afficher_time_ils35R)
self.timer.start(1000)

######################################################
# appel des fonctions d'etats des checkbuttons :
######################################################
self.etat_checkbutton_valeur_de_correction_loc35R()
self.etat_checkbutton_valeur_de_correction_gp35R()
self.etat_checkbutton_valeur_de_correction_loc35L()
self.etat_checkbutton_valeur_de_correction_gp35L()

#############################################################
#option pour rendre lineEdit_declaration_OK_or_NO invisibe :
#############################################################
self.lineEdit_declaration_OK_or_NO_cev_loc35R.setVisible(False)
self.lineEdit_declaration_OK_or_NO_cev_gp35R.setVisible(False)
self.lineEdit_declaration_OK_or_NO_cev_loc35L.setVisible(False)
self.lineEdit_declaration_OK_or_NO_cev_gp35L.setVisible(False)


###########################################################
#pour renommer les tabs du QTabwidget partie cev (ILS 35R):
###########################################################
self.tabWidget_tabs_cev_ils35R.setTabText(0, "loc 35R")
self.tabWidget_tabs_cev_ils35R.setTabText(1, "gp 35R")

###########################################################
#pour renommer les tabs du QTabwidget partie cev (ILS 35L):
###########################################################
self.tabWidget_tabs_cev_ils35L.setTabText(0, "loc 35L")
self.tabWidget_tabs_cev_ils35L.setTabText(1, "gp 35L")


############################################################
# appel de la fonction d'animation de la page d'aceuil :
############################################################
self.animationImage()


###############################################################################################################################################

##################################################################################
# Fonction conceernant les commandes effectuees par les boutons et sous menus #
# ################################################################################


#Fonction pour les commandes effectuees par les boutons et sous menus :
def actions_sur_les_boutons(self):

#actions sur les boutons du menu :

########################################################
#pour ouvrir l'image d'acceuil :
#########################################################
self.actionhome.triggered.connect(self.Click_Acceuil_On_menu_Acceuil)

###########################################################
#pour ouvrir la page du container ILS 35R :
###########################################################
self.actionILS_35R.triggered.connect(self.Click_On_menu_Fichier_ILS35R)

###########################################################
#pour ouvrir la page du container ILS 35R :
###########################################################
self.actionILS_35L.triggered.connect(self.Click_On_menu_Fichier_ILS35L)

###########################################################
#pour ouvrir la fenetre Toplevel Information :
###########################################################
self.actionA_propos_de_l_application.triggered.connect(self.window_a_propos_de_l_application)

###########################################################
# pur ouvrir la fenetre Toplevel Raccourcis clavier :
###########################################################
self.actionRaccourcis_clavier.triggered.connect(self.window_raccourcis_clavier)

###########################################################
#pour effectuer la commande de fermeture de l'application :
###########################################################
self.actionQuitter_2.triggered.connect(self.fermer_application)

###########################################################
##p pour rendre les Tab associees au meu invisible
###########################################################
self.tabWidget_Acceuil.tabBar().setVisible(False)

#######################################################################
#actions effectuees par les boutons du bloc lateral gauche (ILS 35R) :
#######################################################################
self.pushButton_ils35R.clicked.connect(self.Click_On_Button_home_ils35R)
self.pushButton_loc35R.clicked.connect(self.Click_On_Button_loc35R)
self.pushButton_gp35R.clicked.connect(self.Click_On_Button_gp35R)
self.pushButton_ils35R_archives_cev.clicked.connect(self.click_On_Button_archives_cev_ils35R)
self.tabWidget_bloc_ILS35R.tabBar().setVisible(False)

########################################################################
#actions effectuees par les boutons du bloc lateral gauche (ILS 35L)
########################################################################
self.pushButton_ils35L.clicked.connect(self.Click_On_Button_home_ils35L)
self.pushButton_loc35L.clicked.connect(self.Click_On_Button_loc35L)
self.pushButton_gp35L.clicked.connect(self.Click_On_Button_gp35L)
self.pushButton_ils35L_archives_cev.clicked.connect(self.click_On_Button_archives_cev_ils35L)
self.tabWidget_bloc_ILS35L.tabBar().setVisible(False)

########################################################################
#afficher unite de mesure selon la valeur choisie (ILS 35R) :
########################################################################
#signal fin edition pour linedit entraine event (afficher_unite_de_mesure_loc35R)
self.lineEdit_ddm_voulue_au_sol_cev_loc35R.editingFinished.connect(self.afficher_unite_de_mesure_loc35R)
self.lineEdit_ddm_voulue_au_sol_cev_gp35R.editingFinished.connect(self.afficher_unite_de_mesure_gp35R)

########################################################################
#afficher unite de mesure selon la valeur choisie e (ILS 35L) :
########################################################################
self.lineEdit_ddm_voulue_au_sol_cev_loc35L.editingFinished.connect(self.afficher_unite_de_mesure_loc35L)
self.lineEdit_ddm_voulue_au_sol_cev_gp35L.editingFinished.connect(self.afficher_unite_de_mesure_gp35L)

########################################################################
#pour valider la correction et l'afficher (ILS 35R) :
########################################################################
#loc 35R:
self.pushButton_valider_cev_loc35R.clicked.connect(self.calcul_de_la_correction_ddm_faisceau_loc35R)
#gp 35R:
self.pushButton_valider_cev_gp35R.clicked.connect(self.calcul_de_la_correction_ddm_faisceau_gp35R)

#########################################################################
#pour valider la correction et l'afficher (ILS 35L) :
##########################################################################
#loc 35L:
self.pushButton_valider_cev_loc35L.clicked.connect(self.calcul_de_la_correction_ddm_faisceau_loc35L)
#gp 35L:
self.pushButton_valider_cev_gp35L.clicked.connect(self.calcul_de_la_correction_ddm_faisceau_gp35L)

############################################################################
#pour initialiser le contenu des champs (ILS 35R) :
#############################################################################
#loc35R
self.pushButton_initialiser_cev_loc35R.clicked.connect(self.initialiser_inputs_loc35R)
#gp35R
self.pushButton_initialiser_cev_gp35R.clicked.connect(self.initialiser_inputs_gp35R)

################################################################################
#pour initialiser le contenu des champs (ILS 35L) :
################################################################################
#loc35L
self.pushButton_initialiser_cev_loc35L.clicked.connect(self.initialiser_inputs_loc35L)
#gp35L
self.pushButton_initialiser_cev_gp35L.clicked.connect(self.initialiser_inputs_gp35L)

################################################################################
# pour controler l'etat du checkbutton loc 35R :
################################################################################
self.checkBox_cev_loc35R.stateChanged.connect(self.etat_checkbutton_valeur_de_correction_loc35R)

################################################################################
# pour controler l'etat du checkbutton loc 35L :
################################################################################
self.checkBox_cev_loc35L.clicked.connect(self.etat_checkbutton_valeur_de_correction_loc35L)

################################################################################
# pour controler l'etat du checkbutton gp 35R :
################################################################################
self.checkBox_cev_gp35R.clicked.connect(self.etat_checkbutton_valeur_de_correction_gp35R)

################################################################################
# pour controler l'etat du checkbutton gp 35L :
################################################################################
self.checkBox_cev_gp35L.clicked.connect(self.etat_checkbutton_valeur_de_correction_gp35L)

################################################################################
#Pour archiver dans la bdd loc35R :
################################################################################
self.pushButton_archiver_cev_loc35R.clicked.connect(self.create_database_ils35R_and_table_loc35R)

###############################################################################
#Pour afficher contenu de la bdd loc 35R :
###############################################################################
self.pushButton_rafraichir_data_table_cev_loc35R.clicked.connect(self.afficher_contenu_table_loc35R)

################################################################################
# pour afficher les corrections confirmees loc 35R :
################################################################################
self.pushButton_correction_confirmee_loc35R.clicked.connect(self.selectionner_correction_confirmee_loc35R)

##############################################################################
#pour sauvegarder contenu de la table loc 35R dans un fichier texte :
##############################################################################

self.pushButton_enregistrer_data_dans_fichier_cev_loc35R.clicked.connect(self.create_file_from_loc35R)

################################################################################
#Pour archiver dans la bdd gp 35R :
################################################################################
self.pushButton_archiver_cev_gp35R.clicked.connect(self.create_database_ils35R_and_table_gp35R)

###############################################################################
#Pour afficher contenu de la bdd gp 35R :
###############################################################################
self.pushButton_rafraichir_data_table_cev_gp35R.clicked.connect(self.afficher_contenu_table_gp35R)

################################################################################
#apres click sur bouton "correction confirmee" gp 35R :
################################################################################
self.pushButton_correction_confirmee_gp35R.clicked.connect(self.selectionner_correction_confirmee_gp35R)

################################################################################
#pour sauvegarder contenu de la table gp 35R dans un fichier texte :
################################################################################
self.pushButton_enregistrer_data_dans_fichier_cev_gp35R.clicked.connect(self.create_file_from_gp35R)

################################################################################
#Pour archiver dans la bdd loc35L :
################################################################################
self.pushButton_archiver_cev_loc35L.clicked.connect(self.create_database_ils35L_and_table_loc35L)

###############################################################################
#Pour afficher contenu de la bdd loc 35L :
###############################################################################
self.pushButton_rafraichir_data_table_cev_loc35L.clicked.connect(self.afficher_contenu_table_loc35L)

################################################################################
# pour afficher les corrections confirmees loc 35L :
################################################################################
self.pushButton_correction_confirmee_loc35L.clicked.connect(self.selectionner_correction_confirmee_loc35L)

##############################################################################
#pour sauvegarder contenu de la table loc 35L dans un fichier texte :
##############################################################################

self.pushButton_enregistrer_data_dans_fichier_cev_loc35L.clicked.connect(self.create_file_from_loc35L)

################################################################################
#Pour archiver dans la bdd gp 35L :
################################################################################
self.pushButton_archiver_cev_gp35L.clicked.connect(self.create_database_ils35L_and_table_gp35L)

###############################################################################
#Pour afficher contenu de la bdd gp 35L :
###############################################################################
self.pushButton_rafraichir_data_table_cev_gp35L.clicked.connect(self.afficher_contenu_table_gp35L)

################################################################################
#apres click sur bouton "correction confirmee" gp 35L :
################################################################################
self.pushButton_correction_confirmee_gp35L.clicked.connect(self.selectionner_correction_confirmee_gp35L)

################################################################################
#pour sauvegarder contenu de la table gp 35L dans un fichier texte :
################################################################################
self.pushButton_enregistrer_data_dans_fichier_cev_gp35L.clicked.connect(self.create_file_from_gp35L)



#######################################################################################################################################

###########################################################################
# fonction pour afficher l'animation durant l'execution de l'application :
###########################################################################
def animationImage(self):
box_animation=QPropertyAnimation(self.label_Acceuil,b"geometry")
box_animation.setDuration(2500)
box_animation.setStartValue(QRect(0,0,0,0))
box_animation.setEndValue(QRect(0,-20 ,845 ,550 ))
box_animation.start()
self.box_animation=box_animation

####################################################
#Fonctions d'affichage de la date et de l'heure :
####################################################

##############################
#### pour le bloc ILS 35R :
##############################

# fonction date :
def afficher_date_ils35R(self):

our_date_ils35R=time.strftime(" %d / %m / %Y")
self.label_date_ils35R.setText('%s ' % our_date_ils35R)

# fonction heure :
def afficher_time_ils35R(self):

our_time_ils35R=time.strftime(" %H : %M : %S")
self.label_time_ils35R.setText(' %s' % our_time_ils35R)

##############################
#### pour le bloc ILS 35L :
##############################

# fonction date :
def afficher_date_ils35L(self):

our_date_ils35L=time.strftime(" %d / %m / %Y")
self.label_date_ils35L.setText('%s ' % our_date_ils35L)

# fonction heure :
def afficher_time_ils35L(self):

our_time_ils35L=time.strftime(" %H : %M : %S")
self.label_time_ils35L.setText(' %s' % our_time_ils35L)

#################################################
#Fonction pour fermer l'application :
#################################################
def fermer_application(self) :

sys.exit()

############################################################################################################

################################################################
# Fonctions d'affichage unite de mesure #
################################################################


#################################################
# affichage unite de mesure pour loc 35R :
#################################################

def afficher_unite_de_mesure_loc35R(self):

#fonction pour convertir les points en virgules :
def convertire_loc35R(nombre) :

caractere_loc35R=[',',';',':','.','-','_']
for loop in caractere_loc35R :
nombre= str(nombre).replace(loop,'.')
return nombre


ddm_voulue_au_sol_loc35R=self.lineEdit_ddm_voulue_au_sol_cev_loc35R.text()
ddm_voulue_au_sol_loc35R=convertire_loc35R(ddm_voulue_au_sol_loc35R)
#print(ddm_voulue_au_sol_loc35R)

if ddm_voulue_au_sol_loc35R =='' :
ddm_voulue_au_sol_loc35R='0'

self.lineEdit_ddm_voulue_au_sol_cev_loc35R.setText('')
self.label_lineEdit_ddm_avion_labo_loc35R.setText('')
self.label_unite_mesure_ddm_voulue_cev_loc35R.setText('')
self.label_mon1_avant_cev_loc35R.setText('')
self.label_mon2_avant_cev_loc35R.setText('')
self.label_mon1_apres_cev_loc35R.setText('')
self.label_mon2_apres_cev_loc35R.setText('')
self.label_dB_cev_loc35R.setText('')

else :

if (0<float(ddm_voulue_au_sol_loc35R) <1) :

self.label_unite_mesure_ddm_voulue_cev_loc35R.setText('ddm')
self.label_lineEdit_ddm_avion_labo_loc35R.setText('ddm')
self.label_mon1_avant_cev_loc35R.setText('ddm')
self.label_mon2_avant_cev_loc35R.setText('ddm')
self.label_mon1_apres_cev_loc35R.setText('ddm')
self.label_mon2_apres_cev_loc35R.setText('ddm')
self.label_dB_cev_loc35R.setText('dB')

elif(float(ddm_voulue_au_sol_loc35R) >100 ) :

self.label_unite_mesure_ddm_voulue_cev_loc35R.setText('μA')
self.label_lineEdit_ddm_avion_labo_loc35R.setText('μA')
self.label_mon1_avant_cev_loc35R.setText('μA')
self.label_mon2_avant_cev_loc35R.setText('μA')
self.label_mon1_apres_cev_loc35R.setText('μA')
self.label_mon2_apres_cev_loc35R.setText('μA')
self.label_dB_cev_loc35R.setText('dB')

else :

self.lineEdit_ddm_voulue_au_sol_cev_loc35R.setText('')
self.label_lineEdit_ddm_avion_labo_loc35R.setText('')
self.label_unite_mesure_ddm_voulue_cev_loc35R.setText('')
self.label_mon1_avant_cev_loc35R.setText('')
self.label_mon2_avant_cev_loc35R.setText('')
self.label_mon1_apres_cev_loc35R.setText('')
self.label_mon2_apres_cev_loc35R.setText('')
self.label_dB_cev_loc35R.setText('')

##################################################
# affichage unite de mesure pour loc 35L :
##################################################

def afficher_unite_de_mesure_loc35L(self):

#fonction pour convertir les points en virgules :
def convertire_loc35L(nombre) :

caractere_loc35L=[',',';',':','.','-','_']
for loop in caractere_loc35L :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_loc35L=self.lineEdit_ddm_voulue_au_sol_cev_loc35L.text()
ddm_voulue_au_sol_loc35L=convertire_loc35L(ddm_voulue_au_sol_loc35L)

if ddm_voulue_au_sol_loc35L =='' :
ddm_voulue_au_sol_loc35L='0'

self.lineEdit_ddm_voulue_au_sol_cev_loc35L.setText('')
self.label_lineEdit_ddm_avion_labo_loc35L.setText('')
self.label_unite_mesure_ddm_voulue_cev_loc35L.setText('')
self.label_mon1_avant_cev_loc35L.setText('')
self.label_mon2_avant_cev_loc35L.setText('')
self.label_mon1_apres_cev_loc35L.setText('')
self.label_mon2_apres_cev_loc35L.setText('')
self.label_dB_cev_loc35L.setText('')

else :

if (0<float(ddm_voulue_au_sol_loc35L) <1) :

self.label_unite_mesure_ddm_voulue_cev_loc35L.setText('ddm')
self.label_lineEdit_ddm_avion_labo_loc35L.setText('ddm')
self.label_mon1_avant_cev_loc35L.setText('ddm')
self.label_mon2_avant_cev_loc35L.setText('ddm')
self.label_mon1_apres_cev_loc35L.setText('ddm')
self.label_mon2_apres_cev_loc35L.setText('ddm')
self.label_dB_cev_loc35L.setText('dB')

elif(float(ddm_voulue_au_sol_loc35L) >100 ) :

self.label_unite_mesure_ddm_voulue_cev_loc35L.setText('μA')
self.label_lineEdit_ddm_avion_labo_loc35L.setText('μA')
self.label_mon1_avant_cev_loc35L.setText('μA')
self.label_mon2_avant_cev_loc35L.setText('μA')
self.label_mon1_apres_cev_loc35L.setText('μA')
self.label_mon2_apres_cev_loc35L.setText('μA')
self.label_dB_cev_loc35L.setText('dB')

else :

self.lineEdit_ddm_voulue_au_sol_cev_loc35L.setText('')
self.label_lineEdit_ddm_avion_labo_loc35L.setText('')
self.label_unite_mesure_ddm_voulue_cev_loc35L.setText('')
self.label_mon1_avant_cev_loc35L.setText('')
self.label_mon2_avant_cev_loc35L.setText('')
self.label_mon1_apres_cev_loc35L.setText('')
self.label_mon2_apres_cev_loc35L.setText('')
self.label_dB_cev_loc35L.setText('')

####################################################
# affichage de l'unite de mesure pour gp 35R :
####################################################

def afficher_unite_de_mesure_gp35R(self):

#fonction pour convertir les points en virgules :
def convertire_gp35R(nombre) :

caractere_gp35R=[',',';',':','.','-','_']
for loop in caractere_gp35R :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_gp35R=self.lineEdit_ddm_voulue_au_sol_cev_gp35R.text()
ddm_voulue_au_sol_gp35R=convertire_gp35R(ddm_voulue_au_sol_gp35R)

if ddm_voulue_au_sol_gp35R =='' :
ddm_voulue_au_sol_gp35R='0'

self.lineEdit_ddm_voulue_au_sol_cev_gp35R.setText('')
self.label_lineEdit_ddm_avion_labo_gp35R.setText('')
self.label_unite_mesure_ddm_voulue_cev_gp35R.setText('')
self.label_mon1_avant_cev_gp35R.setText('')
self.label_mon2_avant_cev_gp35R.setText('')
self.label_mon1_apres_cev_gp35R.setText('')
self.label_mon2_apres_cev_gp35R.setText('')
self.label_dB_cev_gp35R.setText('')

else :

if (0<float(ddm_voulue_au_sol_gp35R) <1) :

self.label_unite_mesure_ddm_voulue_cev_gp35R.setText('ddm')
self.label_lineEdit_ddm_avion_labo_gp35R.setText('ddm')
self.label_mon1_avant_cev_gp35R.setText('ddm')
self.label_mon2_avant_cev_gp35R.setText('ddm')
self.label_mon1_apres_cev_gp35R.setText('ddm')
self.label_mon2_apres_cev_gp35R.setText('ddm')
self.label_dB_cev_gp35R.setText('dB')

elif(float(ddm_voulue_au_sol_gp35R) >=75) :

self.label_unite_mesure_ddm_voulue_cev_gp35R.setText('μA')
self.label_lineEdit_ddm_avion_labo_gp35R.setText('μA')
self.label_mon1_avant_cev_gp35R.setText('μA')
self.label_mon2_avant_cev_gp35R.setText('μA')
self.label_mon1_apres_cev_gp35R.setText('μA')
self.label_mon2_apres_cev_gp35R.setText('μA')
self.label_dB_cev_gp35R.setText('dB')

else :

self.lineEdit_ddm_voulue_au_sol_cev_gp35R.setText('')
self.label_lineEdit_ddm_avion_labo_gp35R.setText('')
self.label_unite_mesure_ddm_voulue_cev_gp35R.setText('')
self.label_mon1_avant_cev_gp35R.setText('')
self.label_mon2_avant_cev_gp35R.setText('')
self.label_mon1_apres_cev_gp35R.setText('')
self.label_mon2_apres_cev_gp35R.setText('')
self.label_dB_cev_gp35R.setText('')


################################################
# affichage unite de mesure pour gp 35L :
###############################################

def afficher_unite_de_mesure_gp35L(self):

#fonction pour convertir les points en virgules :
def convertire_gp35L(nombre) :

caractere_gp35L=[',',';',':','.','-','_']
for loop in caractere_gp35L :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_gp35L=self.lineEdit_ddm_voulue_au_sol_cev_gp35L.text()
ddm_voulue_au_sol_gp35L=convertire_gp35L(ddm_voulue_au_sol_gp35L)
#print(ddm_voulue_au_sol_gp35L)

if ddm_voulue_au_sol_gp35L =='' :
ddm_voulue_au_sol_gp35L='0'

self.lineEdit_ddm_voulue_au_sol_cev_gp35L.setText('')
self.label_lineEdit_ddm_avion_labo_gp35L.setText('')
self.label_unite_mesure_ddm_voulue_cev_gp35L.setText('')
self.label_mon1_avant_cev_gp35L.setText('')
self.label_mon2_avant_cev_gp35L.setText('')
self.label_mon1_apres_cev_gp35L.setText('')
self.label_mon2_apres_cev_gp35L.setText('')
self.label_dB_cev_gp35L.setText('')

else :

if (0<float(ddm_voulue_au_sol_gp35L) <1) :

self.label_unite_mesure_ddm_voulue_cev_gp35L.setText('ddm')
self.label_lineEdit_ddm_avion_labo_gp35L.setText('ddm')
self.label_mon1_avant_cev_gp35L.setText('ddm')
self.label_mon2_avant_cev_gp35L.setText('ddm')
self.label_mon1_apres_cev_gp35L.setText('ddm')
self.label_mon2_apres_cev_gp35L.setText('ddm')
self.label_dB_cev_gp35L.setText('dB')

elif(float(ddm_voulue_au_sol_gp35L) >=75) :

self.label_unite_mesure_ddm_voulue_cev_gp35L.setText('μA')
self.label_lineEdit_ddm_avion_labo_gp35L.setText('μA')
self.label_mon1_avant_cev_gp35L.setText('μA')
self.label_mon2_avant_cev_gp35L.setText('μA')
self.label_mon1_apres_cev_gp35L.setText('μA')
self.label_mon2_apres_cev_gp35L.setText('μA')
self.label_dB_cev_gp35L.setText('dB')

else :

self.lineEdit_ddm_voulue_au_sol_cev_gp35L.setText('')
self.label_lineEdit_ddm_avion_labo_gp35L.setText('')
self.label_unite_mesure_ddm_voulue_cev_gp35L.setText('')
self.label_mon1_avant_cev_gp35L.setText('')
self.label_mon2_avant_cev_gp35L.setText('')
self.label_mon1_apres_cev_gp35L.setText('')
self.label_mon2_apres_cev_gp35L.setText('')
self.label_dB_cev_gp35L.setText('')


############################################################################################################


######################################################
# Fonctions d'affichage de l'etat du checkbutton #
# ####################################################


################################################################################
# etat checkbutton de confirmation de la bonne valeur de correction loc35R :
################################################################################

def etat_checkbutton_valeur_de_correction_loc35R(self):

if self.checkBox_cev_loc35R.isChecked()==True :

self.textEdit_affichage_erreurs_cev_loc35R.setText('<center><h2 style=" color:#00aa00;">Confirmation</h2></center><span style=" color:#00aa00;font-weight:bold;">La dernière valeur introduite pour la correction de la ddm faisceau a été confirmée par les operateurs en vol.</span>')

self.lineEdit_declaration_OK_or_NO_cev_loc35R.setText("OK")

else:
self.textEdit_affichage_erreurs_cev_loc35R.setText("")
self.lineEdit_declaration_OK_or_NO_cev_loc35R.setText("NO")
#self.lineEdit_declaration_OK_or_NO_cev_loc35R.setStyleSheet(
#"""QLineEdit {color: red }""")

############################################################################
#etat checkbutton de confirmation de la bonne valeur de correction gp 35R :
############################################################################
def etat_checkbutton_valeur_de_correction_gp35R(self):

if self.checkBox_cev_gp35R.isChecked()==True :

self.textEdit_affichage_erreurs_cev_gp35R.setText('<center><h2 style=" color:#00aa00;">Confirmation</h2></center><span style=" color:#00aa00;font-weight:bold;">La dernière valeur introduite pour la correction de la ddm faisceau a été confirmée par les operateurs en vol.</span>')

self.lineEdit_declaration_OK_or_NO_cev_gp35R.setText("OK")

else:
self.textEdit_affichage_erreurs_cev_gp35R.setText(" ")
self.lineEdit_declaration_OK_or_NO_cev_gp35R.setText("NO")

###########################################################################
#etat checkbutton de confirmation de la bonne valeur de correction loc35L :
###########################################################################
def etat_checkbutton_valeur_de_correction_loc35L(self):

if self.checkBox_cev_loc35L.isChecked()==True :

self.textEdit_affichage_erreurs_cev_loc35L.setText('<center><h2 style=" color:#00aa00;">Confirmation</h2></center><span style=" color:#00aa00;font-weight:bold;">La dernière valeur introduite pour la correction de la ddm faisceau a été confirmée par les operateurs en vol.</span>')

self.lineEdit_declaration_OK_or_NO_cev_loc35L.setText("OK")

else:
self.textEdit_affichage_erreurs_cev_loc35L.setText(" ")
self.lineEdit_declaration_OK_or_NO_cev_loc35L.setText("NO")

###########################################################################
#etat checkbutton de confirmation de la bonne valeur de correction gp 35L:
###########################################################################
def etat_checkbutton_valeur_de_correction_gp35L(self):

if self.checkBox_cev_gp35L.isChecked()==True :

self.textEdit_affichage_erreurs_cev_gp35L.setText('<center><h2 style=" color:#00aa00;">Confirmation</h2></center><span style=" color:#00aa00;font-weight:bold;">La dernière valeur introduite pour la correction de la ddm faisceau a été confirmée par les operateurs en vol.</span>')

self.lineEdit_declaration_OK_or_NO_cev_gp35L.setText("OK")

else:
self.textEdit_affichage_erreurs_cev_gp35L.setText(" ")
self.lineEdit_declaration_OK_or_NO_cev_gp35L.setText("NO")


################################################################################################################################################

################################################################
# Fonctions de calcul de la correction de la ddm faisceaaau #
# ##############################################################

#######################################################
# correction de la ddm faisceaaau pour loc 35R :
#######################################################

def calcul_de_la_correction_ddm_faisceau_loc35R (self):

#fonction convertir point virgules :
def convertir_loc35R(nombre) :

caractere_loc35R=[',',';',':','.','-','_']
for loop in caractere_loc35R :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_loc35R=self.lineEdit_ddm_voulue_au_sol_cev_loc35R.text()
ddm_voulue_au_sol_loc35R=convertir_loc35R(ddm_voulue_au_sol_loc35R)
ddm_voulue_au_sol_loc35R=float(ddm_voulue_au_sol_loc35R)

ddm_lue_avion_labo_loc35R=self.lineEdit_ddm_avion_labo_cev_loc35R.text()
ddm_lue_par_avion_labo_loc35R=convertir_loc35R(ddm_lue_avion_labo_loc35R)
ddm_lue_par_avion_labo_loc35R=float(ddm_lue_par_avion_labo_loc35R)

try:

correction_loc35R= 20*(math.log10(ddm_lue_par_avion_labo_loc35R/ddm_voulue_au_sol_loc35R))
correction_loc35R=round(correction_loc35R,3)
correction_loc35R =str(correction_loc35R)
self.lineEdit_correction_cev_loc35R.setText(correction_loc35R)
self.textEdit_affichage_erreurs_cev_loc35R.setText("")

except:
self.textEdit_affichage_erreurs_cev_loc35R.setText('<center><h2 style="color:#FF0000">Erreur</h2></center><span style="font-weight:bold;font-size:15px;color:#FF0000">Un des champs est nul ou invalide. Remplir tous les champs, puis refaire l\'operation de calcul.</span>')

###########################################################
# correction de la ddm faisceaaau pour gp 35R :
###########################################################

def calcul_de_la_correction_ddm_faisceau_gp35R (self):

#fonction convertir point virgules :
def convertir_gp35R(nombre) :

caractere_gp35R=[',',';',':','.','-','_']
for loop in caractere_gp35R :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_gp35R=self.lineEdit_ddm_voulue_au_sol_cev_gp35R.text()
ddm_voulue_au_sol_gp35R=convertir_gp35R(ddm_voulue_au_sol_gp35R)
ddm_voulue_au_sol_gp35R=float(ddm_voulue_au_sol_gp35R)


ddm_lue_avion_labo_gp35R=self.lineEdit_ddm_avion_labo_cev_gp35R.text()
ddm_lue_par_avion_labo_gp35R=convertir_gp35R(ddm_lue_avion_labo_gp35R)
ddm_lue_par_avion_labo_gp35R=float(ddm_lue_par_avion_labo_gp35R)


try:

correction_gp35R= 20*(math.log10(ddm_lue_par_avion_labo_gp35R/ddm_voulue_au_sol_gp35R))
correction_gp35R=round(correction_gp35R,3)
correction_gp35R =str(correction_gp35R)
self.lineEdit_correction_cev_gp35R.setText(correction_gp35R)
self.textEdit_affichage_erreurs_cev_gp35R.setText("")

except:
self.textEdit_affichage_erreurs_cev_gp35R.setText('<center><h2 style="color:#FF0000">Erreur</h2></center><span style="font-weight:bold;font-size:15px;color:#FF0000">Un des champs est nul ou invalide. Remplir tous les champs, puis refaire l\'operation de calcul.</span>')

#############################################################
# correction de la ddm faisceaaau pour loc 35L :
#############################################################

def calcul_de_la_correction_ddm_faisceau_loc35L (self):

#fonction convertir point virgules :
def convertir_loc35L(nombre) :

caractere_loc35L=[',',';',':','.','-','_']
for loop in caractere_loc35L :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_loc35L=self.lineEdit_ddm_voulue_au_sol_cev_loc35L.text()
ddm_voulue_au_sol_loc35L=convertir_loc35L(ddm_voulue_au_sol_loc35L)
ddm_voulue_au_sol_loc35L=float(ddm_voulue_au_sol_loc35L)

ddm_lue_avion_labo_loc35L=self.lineEdit_ddm_avion_labo_cev_loc35L.text()
ddm_lue_par_avion_labo_loc35L=convertir_loc35L(ddm_lue_avion_labo_loc35L)
ddm_lue_par_avion_labo_loc35L=float(ddm_lue_par_avion_labo_loc35L)

try:

correction_loc35L= 20*(math.log10(ddm_lue_par_avion_labo_loc35L/ddm_voulue_au_sol_loc35L))
correction_loc35L=round(correction_loc35L,3)
correction_loc35L=str(correction_loc35L)
self.lineEdit_correction_cev_loc35L.setText(correction_loc35L)
self.textEdit_affichage_erreurs_cev_loc35L.setText("")
except:
self.textEdit_affichage_erreurs_cev_loc35L.setText('<center><h2 style="color:#FF0000">Erreur</h2></center><span style="font-weight:bold;font-size:15px;color:#FF0000">Un des champs est nul ou invalide. Remplir tous les champs, puis refaire l\'operation de calcul.</span>')

#########################################################
# correction de la ddm faisceaaau pour gp 35L
#########################################################

def calcul_de_la_correction_ddm_faisceau_gp35L (self):

#fonction convertir point virgules :
def convertir_gp35L(nombre) :

caractere_gp35L=[',',';',':','.','-','_']
for loop in caractere_gp35L :
nombre= str(nombre).replace(loop,'.')
return nombre

ddm_voulue_au_sol_gp35L=self.lineEdit_ddm_voulue_au_sol_cev_gp35L.text()
ddm_voulue_au_sol_gp35L=convertir_gp35L(ddm_voulue_au_sol_gp35L)
ddm_voulue_au_sol_gp35L=float(ddm_voulue_au_sol_gp35L)

ddm_lue_avion_labo_gp35L=self.lineEdit_ddm_avion_labo_cev_gp35L.text()
ddm_lue_par_avion_labo_gp35L=convertir_gp35L(ddm_lue_avion_labo_gp35L)
ddm_lue_par_avion_labo_gp35L=float(ddm_lue_par_avion_labo_gp35L)

try:

correction_gp35L= 20*(math.log10(ddm_lue_par_avion_labo_gp35L/ddm_voulue_au_sol_gp35L))
correction_gp35L=round(correction_gp35L,3)
correction_gp35L=str(correction_gp35L)
self.lineEdit_correction_cev_gp35L.setText(correction_gp35L)
self.textEdit_affichage_erreurs_cev_gp35L.setText("")
except:
self.textEdit_affichage_erreurs_cev_gp35L.setText('<center><h2 style="color:#FF0000">Erreur</h2></center><span style="font-weight:bold;font-size:15px;color:#FF0000">Un des champs est nul ou invalide. Remplir tous les champs, puis refaire l\'operation de calcul.</span>')

##############################################################
#fonctions d'initialisation pour loc 3R des lineEdit :
##############################################################

def initialiser_inputs_loc35R(self):
self.lineEdit_ddm_avion_labo_cev_loc35R.setText("")
self.lineEdit_correction_cev_loc35R.setText("")
self.lineEdit_ddm_voulue_au_sol_cev_loc35R.setText("")
self.textEdit_affichage_erreurs_cev_loc35R.setText("")
self.lineEdit_mon1_avant_cev_loc35R.setText("")
self.lineEdit_mon2_avant_cev_loc35R.setText("")
self.lineEdit_mon1_apres_cev_loc35R.setText("")
self.lineEdit_mon2_apres_cev_loc35R.setText("")
self.label_mon1_avant_cev_loc35R.setText("")
self.label_mon2_avant_cev_loc35R.setText("")
self.label_mon1_apres_cev_loc35R.setText("")
self.label_mon2_apres_cev_loc35R.setText("")
self.label_unite_mesure_ddm_voulue_cev_loc35R.setText("")
self.label_lineEdit_ddm_avion_labo_loc35R.setText("")
self.lineEdit_declaration_OK_or_NO_cev_loc35R.setText("")
self.label_dB_cev_loc35R.setText("")
self.checkBox_cev_loc35R.setCheckState(Qt.Unchecked)

################################################################
#fonctions d'initialisation pour gp 3R des lineEdit :
################################################################

def initialiser_inputs_gp35R(self):
self.lineEdit_ddm_avion_labo_cev_gp35R.setText("")
self.lineEdit_correction_cev_gp35R.setText("")
self.lineEdit_ddm_voulue_au_sol_cev_gp35R.setText("")
self.textEdit_affichage_erreurs_cev_gp35R.setText("")
self.lineEdit_mon1_avant_cev_gp35R.setText("")
self.lineEdit_mon2_avant_cev_gp35R.setText("")
self.lineEdit_mon1_apres_cev_gp35R.setText("")
self.lineEdit_mon2_apres_cev_gp35R.setText("")
self.label_mon1_avant_cev_gp35R.setText("")
self.label_mon2_avant_cev_gp35R.setText("")
self.label_mon1_apres_cev_gp35R.setText("")
self.label_mon2_apres_cev_gp35R.setText("")
self.label_unite_mesure_ddm_voulue_cev_gp35R.setText("")
self.label_lineEdit_ddm_avion_labo_gp35R.setText("")
self.lineEdit_declaration_OK_or_NO_cev_gp35R.setText("")
self.label_dB_cev_gp35R.setText("")
self.checkBox_cev_gp35R.setCheckState(Qt.Unchecked)

#################################################################
#fonctions d'initialisation pour loc 35L des lineEdit :
#################################################################

def initialiser_inputs_loc35L(self):
self.lineEdit_ddm_avion_labo_cev_loc35L.setText("")
self.lineEdit_correction_cev_loc35L.setText("")
self.lineEdit_ddm_voulue_au_sol_cev_loc35L.setText("")
self.textEdit_affichage_erreurs_cev_loc35L.setText("")
self.lineEdit_mon1_avant_cev_loc35L.setText("")
self.lineEdit_mon2_avant_cev_loc35L.setText("")
self.lineEdit_mon1_apres_cev_loc35L.setText("")
self.lineEdit_mon2_apres_cev_loc35L.setText("")
self.label_mon1_avant_cev_loc35L.setText("")
self.label_mon2_avant_cev_loc35L.setText("")
self.label_mon1_apres_cev_loc35L.setText("")
self.label_mon2_apres_cev_loc35L.setText("")
self.label_unite_mesure_ddm_voulue_cev_loc35L.setText("")
self.label_lineEdit_ddm_avion_labo_loc35L.setText("")
self.lineEdit_declaration_OK_or_NO_cev_loc35L.setText("")
self.label_dB_cev_loc35L.setText("")
self.checkBox_cev_loc35L.setCheckState(Qt.Unchecked)

###############################################################
# fonctions d'initialisation pour gp 35L des lineEdit :
###############################################################

def initialiser_inputs_gp35L(self):
self.lineEdit_ddm_avion_labo_cev_gp35L.setText("")
self.lineEdit_correction_cev_gp35L.setText("")
self.lineEdit_ddm_voulue_au_sol_cev_gp35L.setText("")
self.textEdit_affichage_erreurs_cev_gp35L.setText("")
self.lineEdit_mon1_avant_cev_gp35L.setText("")
self.lineEdit_mon2_avant_cev_gp35L.setText("")
self.lineEdit_mon1_apres_cev_gp35L.setText("")
self.lineEdit_mon2_apres_cev_gp35L.setText("")
self.label_mon1_avant_cev_gp35L.setText("")
self.label_mon2_avant_cev_gp35L.setText("")
self.label_mon1_apres_cev_gp35L.setText("")
self.label_mon2_apres_cev_gp35L.setText("")
self.label_unite_mesure_ddm_voulue_cev_gp35L.setText("")
self.label_lineEdit_ddm_avion_labo_gp35L.setText("")
self.lineEdit_declaration_OK_or_NO_cev_gp35L.setText("")
self.label_dB_cev_gp35L.setText("")
self.checkBox_cev_gp35L.setCheckState(Qt.Unchecked)

######################################################################################################################################

################################################
# database LOC 35R #
################################################




########################################################
#Fonctions archivage pour loc 35R :
########################################################

def create_database_ils35R_and_table_loc35R(self):

#fonction convertir point virgules :
def convertir_database_ils35R(nombre) :

caractere_loc35R=[',',';',':','.','-','_']
for loop in caractere_loc35R :
nombre= str(nombre).replace(loop,'.')
return nombre

#scriptDirectory=os.path.dirname(os.path.realpath(__file__)) #chemin vers le dossier contenant le script index.py
#path_directory=scriptDirectory + '\\data_base' #creation du chemin vers le dossier data_base
#os.makedirs(path_directory, exist_ok=True) # creation du dossier data_base

bundle_dir_data_base = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_data_base = path.join(bundle_dir_data_base, 'data_base')
os.makedirs(path_to_data_base, exist_ok=True)

#les valeurs qui vont etre introduites dans les champs de la table
# apres chaque operation de stockage " click sur le bouton archiver de l'application"

mon1_avant_cev_loc35R=self.lineEdit_mon1_avant_cev_loc35R.text()
ddm_mon1_avant_cev_loc35R=convertir_database_ils35R(mon1_avant_cev_loc35R)+' '+self.label_mon1_avant_cev_loc35R.text()

mon2_avant_cev_loc35R=self.lineEdit_mon2_avant_cev_loc35R.text()
ddm_mon2_avant_cev_loc35R=convertir_database_ils35R(mon2_avant_cev_loc35R)+' '+self.label_mon2_avant_cev_loc35R.text()

mon1_apres_cev_loc35R=self.lineEdit_mon1_apres_cev_loc35R.text()
ddm_mon1_apres_cev_loc35R=convertir_database_ils35R(mon1_apres_cev_loc35R)+' '+self.label_mon2_apres_cev_loc35R.text()

mon2_apres_cev_loc35R=self.lineEdit_mon2_apres_cev_loc35R.text()
ddm_mon2_apres_cev_loc35R=convertir_database_ils35R(mon2_apres_cev_loc35R)+' ' +self.label_mon2_apres_cev_loc35R.text()

ddm_avion_labo_cev_loc35R=self.lineEdit_ddm_avion_labo_cev_loc35R.text()
ddm_lue_avion_labo_cev_loc35R=convertir_database_ils35R(ddm_avion_labo_cev_loc35R)+' '+self.label_lineEdit_ddm_avion_labo_loc35R.text()

date_lecture_cev_loc35R =str(time.strftime("%d-%m-%Y"))
time_lecture_cev_loc35R = str(time.strftime('%H:%M:%S'))

ddm_correction_cev_loc35R = self.lineEdit_correction_cev_loc35R.text() +' ' + 'dB'

ddm_voulue_au_sol_cev_loc35R = self.lineEdit_ddm_voulue_au_sol_cev_loc35R.text()
ddm_voulue_au_sol_cev_loc35R=convertir_database_ils35R(ddm_voulue_au_sol_cev_loc35R)+' ' +self.label_unite_mesure_ddm_voulue_cev_loc35R.text()

ddm_confirmation_avion_labo_cev_loc35R=self.lineEdit_declaration_OK_or_NO_cev_loc35R.text()

connexion = sqlite3.connect(path_to_data_base + '\\ils35R.db')

# Get a cursor object
curseur = connexion.cursor()

# Check if table loc35R does not exist and create it
curseur.execute('''CREATE TABLE IF NOT EXISTS loc35R
(date_cev_loc35R text, time_cev_loc35R text,lecture_ddm_mon1_avant_cev_loc35R text, lecture_ddm_mon2_avant_cev_loc35R text,
lecture_ddm_mon1_apres_cev_loc35R text , lecture_ddm_mon2_apres_cev_loc35R text, lecture_ddm_voulue_au_sol_cev_loc35R text,
lecture_ddm_avion_labo_cev_loc35R text, correction_cev_loc35R text, declaration_avion_labo_cev_loc35R text ) ''')

#affichage Rappel pas d'enregistrement actuellement avec l'etat des champs vides :
if (self.lineEdit_mon1_avant_cev_loc35R.text()=="") or (self.lineEdit_mon2_avant_cev_loc35R.text()=="") or (self.lineEdit_mon1_apres_cev_loc35R.text()=="") or (self.lineEdit_mon2_apres_cev_loc35R.text()=="") or (self.lineEdit_correction_cev_loc35R.text()=="") or (self.lineEdit_ddm_avion_labo_cev_loc35R.text()=="") :
self.textEdit_affichage_erreurs_cev_loc35R.setText('<center><h2 style=" color:#FF0000;">Rappel</h2></center><span style="color:#FF0000; font-weight: bold;font-size:15px;">Il n\'ya pas eu d\'enregistrement dans la base de données puisqu\'un des champs est invalide.</span>')

else:

#insertion des donnees de la bdd à partir de la table cree "loc35R" :
curseur.execute('''INSERT INTO loc35R VALUES (?,?,?,?,?,?,?,?,?,?) ''',
(date_lecture_cev_loc35R,time_lecture_cev_loc35R, ddm_mon1_avant_cev_loc35R, ddm_mon2_avant_cev_loc35R, ddm_mon1_apres_cev_loc35R, ddm_mon2_apres_cev_loc35R, ddm_voulue_au_sol_cev_loc35R, ddm_lue_avion_labo_cev_loc35R, ddm_correction_cev_loc35R, ddm_confirmation_avion_labo_cev_loc35R))

# Commit the change
connexion.commit()
#affichage Felecitation:succes d'enregistrement dans la bdd :
self.textEdit_affichage_erreurs_cev_loc35R.setText('<center><h2 style=" color:#00aa00;">Félicitation</h2></center>''<span style=" color:#00aa00;font-size:15px;font-weight: bold;">L\'enregistrement dans la base de données a été effectué avec succès.</span>')

#fermeture du cursor
curseur.close()
#fermeture de la connexion à la bdd
connexion.close()

###################################################################
#affichage du contenu de la table "loc35R" :
###################################################################

def messageInfo(self):

msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("<center><h1 style='color:#AD4F09;'>Information</h1></center>")
msg.setInformativeText("<span style='color:#FF0000; font-weight: bold;font-size:15px;'>pas d’informations enregistrées dans la base de données à afficher</span>")
msg.setWindowTitle("Sauvegarde dans la base de données")
msg.exec_()


def afficher_contenu_table_loc35R(self):

#script_path_ils35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
#new_path_ils35R=script_path_ils35R + '\\data_base' #concaténer au path ci-dessus le path du dossier data_base
#os.makedirs(new_path_ils35R, exist_ok=True) #creer le dossier data_base au nouveau path
bundle_dir_data_base_loc35R = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_data_base_loc35R = path.join(bundle_dir_data_base_loc35R, 'data_base')
os.makedirs(path_to_data_base, exist_ok=True)

conn = sqlite3.connect(path_to_data_base_loc35R + '\\ils35R.db')
curseur=conn.cursor()

try:

c=curseur.execute("SELECT * FROM loc35R")

liste_for_table_cev_loc35R=c.fetchall()
# set row count
self.tableWidget_cev_loc35R.setRowCount(len(liste_for_table_cev_loc35R))
#insertion des donnees de la bdd dans la Qtablewidget:
for nb_lignes in range(len(liste_for_table_cev_loc35R)):
for nombre_colonnes in range(10):
self.tableWidget_cev_loc35R.setItem(nb_lignes,nombre_colonnes, QTableWidgetItem(liste_for_table_cev_loc35R[nb_lignes][nombre_colonnes]))
#mettre la couleur verte pour la ligne contenant la confirmation 'OK'
if (self.tableWidget_cev_loc35R.item(nb_lignes,nombre_colonnes).text())=='OK' :
for j in range(nombre_colonnes+1):
self.tableWidget_cev_loc35R.item(nb_lignes,j).setBackground(QtGui.QColor(0, 204, 0))

self.tableWidget_cev_loc35R.resizeRowsToContents()
self.tableWidget_cev_loc35R.resizeColumnsToContents()

#fermeture du cursor
curseur.close()

#fermeture de la connexion à la bdd
conn.close()

except :
self.messageInfo()


###################################################################
# fonction afficher la selection des corrections confirmer :
###################################################################

def selectionner_correction_confirmee_loc35R (self):

#script_path_ils35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
#new_path_ils35R=script_path_ils35R + '\\data_base' #concaténer au path ci-dessus le path du dossier data_base
#os.makedirs(new_path_ils35R, exist_ok=True) #creer le dossier data_base au nouveau path

bundle_dir_data_base = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_data_base = path.join(bundle_dir_data_base, 'data_base')
os.makedirs(path_to_data_base, exist_ok=True)

conn = sqlite3.connect(path_to_data_base + '\\ils35R.db')
curseur=conn.cursor()

try :

c=curseur.execute("SELECT * FROM loc35R WHERE declaration_avion_labo_cev_loc35R='OK' ")

#nbre de ligne de la table dont la colonne confirmation='OK'
liste_selectionner_correction_confirmee=c.fetchall()
nbr_rows=len(liste_selectionner_correction_confirmee)

# set row count
self.tableWidget_cev_loc35R.setRowCount(nbr_rows)

for nb in range(nbr_rows):
for nombre in range(10):
self.tableWidget_cev_loc35R.setItem(nb,nombre, QTableWidgetItem(liste_selectionner_correction_confirmee[nb][nombre]))

#Adjust size of rows and columns of the Table
self.tableWidget_cev_loc35R.resizeRowsToContents()
self.tableWidget_cev_loc35R.resizeColumnsToContents()

# Commit the change
conn.commit()

#fermeture du cursor
curseur.close()

#fermeture de la connexion à la bdd
conn.close()

except :
self.messageInfo()


###############################################################################################
#Fonction d'alerte quand on veut enregistrer des donnees qui n0exite encore dans la bdd :
###############################################################################################

def messageInfo_filesave(self):

msg_filesave_loc35R = QMessageBox()
msg_filesave_loc35R.setIcon(QMessageBox.Information)
msg_filesave_loc35R.setText("<center><h1 style='color:#AD4F09;'>Rappel</h1></center>")
msg_filesave_loc35R.setInformativeText("<span style='color:#FF0000; font-weight: bold;font-size:15px;'>Il n'ya pas actuellement d’informations enregistrées dans la base de données, afin de pouvoir les sauvegarder dans un fichier texte.</span>")
msg_filesave_loc35R.setWindowTitle("Sauvegarde dans un fichier texte")
msg_filesave_loc35R.exec_()

############################################################################################
#Fonction pour creer un fichier texte et sauvegarder dedans le contenu de la bdd :
############################################################################################

def create_file_from_loc35R(self):

#script_path_ils35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
#new_path_ils35R=script_path_ils35R + '\\data_base' #concaténer au path ci-dessus le path du dossier data_base
#os.makedirs(new_path_ils35R, exist_ok=True) #creer le dossier data_base au nouveau path

#script_path_filesave_loc35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
#new_path_filesave_loc35R=script_path_filesave_loc35R + '\\filesave' #concaténer au path ci-dessus le path du dossier data_base
#os.makedirs(new_path_filesave_loc35R, exist_ok=True) #creer le dossier data_base au nouveau path
bundle_dir_data_base_loc35R = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_data_base_loc35R = path.join(bundle_dir_data_base, 'data_base')
os.makedirs(path_to_data_base_loc35R, exist_ok=True)


bundle_dir_text_file_loc35R = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
path_to_text_file_loc35R = path.join(bundle_dir_text_file_loc35R, 'filesave')
os.makedirs(path_to_text_file_loc35R, exist_ok=True)
try:

conn_file_from_loc35R = sqlite3.connect(path_to_data_base_loc35R + '\\ils35R.db')
curseur_file_from_loc35R=conn_file_from_loc35R.cursor()
c_file_from_loc35R=curseur_file_from_loc
Reply
#10
This code is huge and I think it exceed max number of chars for post. In any case I don't want to dive into 1250+ lines of code and I don't think anyone here would do
Once again - check my post about _MEIPASS and possible confusion that I caused with my advice. If you create your database in _MEIPASS it will be some random temp folder and you will not preserve info between runs.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create dual folder on different path/drive based on the date agmoraojr 2 431 Jan-21-2024, 10:02 AM
Last Post: snippsat
  python script is hanging while calling a procedure in database prasanthi417 4 504 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 536 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  create a default path with idle to a specific directory greybill 0 875 Apr-23-2023, 04:32 AM
Last Post: greybill
  python call stored procedure mg24 2 1,074 Oct-18-2022, 02:19 AM
Last Post: mg24
  python call stored procedure with two parameter mg24 4 1,498 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,475 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,204 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,471 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Python Cut/Copy paste file from folder to another folder rdDrp 4 5,046 Aug-19-2020, 12:40 PM
Last Post: rdDrp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020