Skip to content

Commit

Permalink
feat: add a progress bar in the window
Browse files Browse the repository at this point in the history
  • Loading branch information
fuegans4213 committed Aug 20, 2024
1 parent c1611a1 commit 49d6599
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
54 changes: 33 additions & 21 deletions HeicToJpg.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
#HEIC to JPG en batch

import os
import subprocess
from tkinter import filedialog
from tkinter import *
from tkinter.ttk import Progressbar
import sys

# Fonction pour obtenir le chemin des ressources, même après conversion en .exe
def resource_path(relative_path):
"""Obtain the absolute path to a resource in the bundled app."""
if getattr(sys, 'frozen', False):
# If the app is frozen (running as an executable)
base_path = sys._MEIPASS
else:
# If the app is running as a script
base_path = os.path.dirname(__file__)
return os.path.join(base_path, relative_path)

# Code pour sélectionner le dossier
root = Tk()
root.withdraw()
folder_selected = filedialog.askdirectory()
# Configuration de la fenêtre
window = Tk()
# Définir la taille de la fenêtre à 400x400
window.geometry("400x60")
window.title("HEIC to JPG Converter")

# Dossier des ressources
resources_folder = resource_path('ImageMagick-6.9.13-14-portable-Q16-HDRI-x64')
progress_bar = Progressbar(window, orient="horizontal", length=200, mode="determinate")
progress_bar.pack(pady=20)

folder_selected = filedialog.askdirectory()

for dirpat, _, filenames in os.walk(folder_selected):
# Compter le nombre total de fichiers HEIC
heic_files = []
for dirpath, _, filenames in os.walk(folder_selected):
for filename in filenames:
if filename.lower().endswith(".heic"):
print('Converting %s...' % os.path.join(dirpat, filename))
# Chemin vers convert.exe dans le dossier de ressources
convert_path = resource_path('ImageMagick-6.9.13-14-portable-Q16-HDRI-x64\\convert.exe')
subprocess.run([convert_path, os.path.join(dirpat, filename), os.path.join(dirpat, filename[0:-5] + '.jpg')])
try:
os.remove(os.path.join(dirpat, filename))
except OSError:
pass
continue
heic_files.append(os.path.join(dirpath, filename))

total_files = len(heic_files)
progress_bar["maximum"] = total_files

# Conversion des fichiers HEIC en JPG
for i, filepath in enumerate(heic_files):
progress_bar["value"] = i + 1
window.update_idletasks()

print(f'Converting {filepath}...')
convert_path = resource_path('ImageMagick-6.9.13-14-portable-Q16-HDRI-x64\\convert.exe')
subprocess.run([convert_path, filepath, filepath[0:-5] + '.jpg'])

try:
os.remove(filepath)
except OSError:
pass

window.destroy()
4 changes: 2 additions & 2 deletions HeicToJpg.spec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- mode: python ; coding: utf-8 -*-
#pyinstaller --onefile --windowed --add-data "ImageMagick-6.9.13-14-portable-Q16-HDRI-x64;ImageMagick-6.9.13-14-portable-Q16-HDRI-x64" HeicToJpg.py


a = Analysis(
['HeicToJpg.py'],
pathex=[],
binaries=[],
datas=[('ImageMagick-6.9.13-14-portable-Q16-HDRI-x64', 'ImageMagick-6.9.13-14-portable-Q16-HDRI-x64')],
hiddenimports=['tk'],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down

0 comments on commit 49d6599

Please sign in to comment.