diff --git a/app/main_window.py b/app/main_window.py index 058265a..b6fc976 100644 --- a/app/main_window.py +++ b/app/main_window.py @@ -38,9 +38,10 @@ class MainWindow(QMainWindow): self.setMinimumSize(1000, 700) # Icone de la fenetre + import sys as _sys from PyQt6.QtGui import QIcon - icon_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "resources", "logo.png") + _base = _sys._MEIPASS if getattr(_sys, 'frozen', False) else os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + icon_path = os.path.join(_base, "resources", "logo.png") if os.path.exists(icon_path): self.setWindowIcon(QIcon(icon_path)) self._current_file = None @@ -349,8 +350,9 @@ class MainWindow(QMainWindow): # Logo logo_label = QLabel() - logo_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "resources", "logo.png") + import sys as _sys + _base = _sys._MEIPASS if getattr(_sys, 'frozen', False) else os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + logo_path = os.path.join(_base, "resources", "logo.png") if os.path.exists(logo_path): pixmap = QPixmap(logo_path).scaled(120, 120, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation) diff --git a/install.bat b/install.bat index fb6cd50..cdb8287 100644 --- a/install.bat +++ b/install.bat @@ -61,13 +61,15 @@ if exist "%INSTALL_DIR%\app\main.py" ( ) :: Creer le repertoire d'installation -echo [1/7] Creation du repertoire d'installation... +set "EXE_PATH=%INSTALL_DIR%\CopydevImposingTool.exe" + +echo [1/8] Creation du repertoire d'installation... if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%" if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp" :: ---- GIT ---- :INSTALL_GIT -echo [2/7] Verification de Git... +echo [2/8] Verification de Git... where git >nul 2>&1 if %ERRORLEVEL%==0 ( echo Git est deja installe. @@ -99,7 +101,7 @@ echo Git portable installe. :: ---- PYTHON ---- :INSTALL_PYTHON -echo [3/7] Verification de Python... +echo [3/8] Verification de Python... :: Verifier Python systeme where python >nul 2>&1 @@ -138,7 +140,7 @@ echo Python %PYTHON_VERSION% embarque installe. :: ---- PIP ---- :INSTALL_PIP -echo [4/7] Verification de pip... +echo [4/8] Verification de pip... "%PYTHON_CMD%" -m pip --version >nul 2>&1 if %ERRORLEVEL%==0 ( echo pip est deja installe. @@ -153,13 +155,13 @@ echo pip installe. :: ---- DEPENDANCES ---- :INSTALL_DEPS -echo [5/7] Installation des dependances Python... -"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 2>&1 | findstr /i "Successfully already" +echo [5/8] Installation des dependances Python... +"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 pyinstaller 2>&1 | findstr /i "Successfully already" echo Dependances installees. :: ---- CODE SOURCE ---- :INSTALL_CODE -echo [6/7] Telechargement du code source... +echo [6/8] Telechargement du code source... if exist "%APP_DIR%\.git" ( echo Mise a jour du code existant... pushd "%APP_DIR%" @@ -177,34 +179,60 @@ if not exist "%APP_DIR%\main.py" ( ) echo Code source telecharge. +:: ---- COMPILATION EXE ---- +:INSTALL_BUILD +echo [7/8] Compilation de l'executable... +echo (cette etape peut prendre quelques minutes) +pushd "%APP_DIR%" +"%PYTHON_CMD%" -m PyInstaller --onefile --noconsole --name CopydevImposingTool ^ + --icon "%APP_DIR%\resources\logo.png" ^ + --add-data "resources;resources" ^ + --hidden-import pypdf ^ + --hidden-import reportlab ^ + --hidden-import reportlab.pdfgen ^ + --hidden-import reportlab.pdfgen.canvas ^ + --hidden-import reportlab.lib ^ + --hidden-import reportlab.lib.pagesizes ^ + --hidden-import reportlab.lib.units ^ + --hidden-import reportlab.lib.colors ^ + --hidden-import pypdfium2 ^ + --hidden-import pypdfium2._helpers ^ + --distpath "%INSTALL_DIR%" ^ + --workpath "%INSTALL_DIR%\temp\build" ^ + --specpath "%INSTALL_DIR%\temp" ^ + main.py >nul 2>&1 +popd + +if not exist "%EXE_PATH%" ( + echo [!] La compilation a echoue. Utilisation du lanceur Python. + :: Fallback : lanceur .vbs + ( + echo Set WshShell = CreateObject^("WScript.Shell"^) + echo WshShell.CurrentDirectory = "%APP_DIR%" + echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False + ) > "%INSTALL_DIR%\lancer.vbs" + set "LAUNCH_TARGET=%INSTALL_DIR%\lancer.vbs" + set "LAUNCH_ICON=" +) else ( + echo Executable compile : CopydevImposingTool.exe + set "LAUNCH_TARGET=%EXE_PATH%" + set "LAUNCH_ICON=%EXE_PATH%" +) + :: ---- RACCOURCIS ---- :INSTALL_SHORTCUTS -echo [7/7] Creation des raccourcis... - -:: Creer le lanceur .bat -( - echo @echo off - echo cd /d "%APP_DIR%" - echo "%PYTHON_CMD%" main.py -) > "%INSTALL_DIR%\lancer.bat" - -:: Creer le lanceur .vbs (sans fenetre console) -( - echo Set WshShell = CreateObject^("WScript.Shell"^) - echo WshShell.CurrentDirectory = "%APP_DIR%" - echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False -) > "%INSTALL_DIR%\lancer.vbs" +echo [8/8] Creation des raccourcis... :: Raccourci Bureau -powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\lancer.vbs'; $Shortcut.WorkingDirectory = '%APP_DIR%'; $Shortcut.Description = '%APP_NAME%'; $Shortcut.Save() }" 2>nul +powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%LAUNCH_TARGET%'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.Description = '%APP_NAME%'; if ('%LAUNCH_ICON%' -ne '') { $Shortcut.IconLocation = '%LAUNCH_ICON%,0' }; $Shortcut.Save() }" 2>nul echo Raccourci Bureau cree. :: Raccourci Menu Demarrer set "START_MENU=%APPDATA%\Microsoft\Windows\Start Menu\Programs" -powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%START_MENU%\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\lancer.vbs'; $Shortcut.WorkingDirectory = '%APP_DIR%'; $Shortcut.Description = '%APP_NAME%'; $Shortcut.Save() }" 2>nul +powershell -Command "& { $WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%START_MENU%\%SHORTCUT_NAME%.lnk'); $Shortcut.TargetPath = '%LAUNCH_TARGET%'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.Description = '%APP_NAME%'; if ('%LAUNCH_ICON%' -ne '') { $Shortcut.IconLocation = '%LAUNCH_ICON%,0' }; $Shortcut.Save() }" 2>nul echo Raccourci Menu Demarrer cree. -:: Nettoyer temp +:: Nettoyer temp et fichiers de build rmdir /s /q "%INSTALL_DIR%\temp" 2>nul :: ---- FIN INSTALLATION ---- @@ -213,9 +241,12 @@ echo ============================================================ echo INSTALLATION TERMINEE echo ============================================================ echo. -echo Dossier : %INSTALL_DIR% -echo Lanceur : Double-cliquez sur le raccourci Bureau -echo "%SHORTCUT_NAME%" +echo Dossier : %INSTALL_DIR% +if exist "%EXE_PATH%" ( +echo Executable: CopydevImposingTool.exe +) +echo Lanceur : Raccourci Bureau ou Menu Demarrer +echo "%SHORTCUT_NAME%" echo. echo Mot de passe requis au lancement. echo. @@ -285,10 +316,36 @@ echo. popd echo Code mis a jour. -echo [2/3] Mise a jour des dependances... -"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 2>&1 | findstr /i "Successfully already" +echo [2/4] Mise a jour des dependances... +"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2 pyinstaller 2>&1 | findstr /i "Successfully already" -echo [3/3] Termine ! +echo [3/4] Recompilation de l'executable... +pushd "%APP_DIR%" +"%PYTHON_CMD%" -m PyInstaller --onefile --noconsole --name CopydevImposingTool ^ + --add-data "resources;resources" ^ + --hidden-import pypdf ^ + --hidden-import reportlab ^ + --hidden-import reportlab.pdfgen ^ + --hidden-import reportlab.pdfgen.canvas ^ + --hidden-import reportlab.lib ^ + --hidden-import reportlab.lib.pagesizes ^ + --hidden-import reportlab.lib.units ^ + --hidden-import reportlab.lib.colors ^ + --hidden-import pypdfium2 ^ + --hidden-import pypdfium2._helpers ^ + --distpath "%INSTALL_DIR%" ^ + --workpath "%INSTALL_DIR%\temp\build" ^ + --specpath "%INSTALL_DIR%\temp" ^ + main.py >nul 2>&1 +popd +rmdir /s /q "%INSTALL_DIR%\temp" 2>nul +if exist "%INSTALL_DIR%\CopydevImposingTool.exe" ( + echo Executable recompile. +) else ( + echo [!] Compilation echouee, l'ancienne version reste active. +) + +echo [4/4] Termine ! echo. echo ============================================================ echo MISE A JOUR TERMINEE diff --git a/main.py b/main.py index a21bd90..7832506 100644 --- a/main.py +++ b/main.py @@ -5,8 +5,15 @@ import sys import os import hashlib -# Ajouter le repertoire racine au path -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +# Support PyInstaller (chemin des resources) +if getattr(sys, 'frozen', False): + BASE_DIR = os.path.dirname(sys.executable) + BUNDLE_DIR = sys._MEIPASS +else: + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + BUNDLE_DIR = BASE_DIR + +sys.path.insert(0, BUNDLE_DIR) from PyQt6.QtWidgets import QApplication, QInputDialog, QMessageBox, QLineEdit @@ -44,7 +51,7 @@ def main(): # Icone application from PyQt6.QtGui import QIcon - icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "logo.png") + icon_path = os.path.join(BUNDLE_DIR, "resources", "logo.png") if os.path.exists(icon_path): app.setWindowIcon(QIcon(icon_path))