-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a progress bar in the window
- Loading branch information
1 parent
c1611a1
commit 49d6599
Showing
2 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters