1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#!/usr/bin/python
from os import system, listdir, environ, getenv
from os.path import join, isfile, isdir, getmtime
from sys import platform, exit
from time import time
from shutil import rmtree
from PyQt5.QtWidgets import QFileDialog, QApplication, QWidget
from config import Config
from convertisseur import Redim
def nettoyage_pyinstaller(self):
for i in listdir(environ["TMP"]):
if i.startswith("_MEI") and isdir(i) and (int(getmtime(join(environ["TMP"], i))) < (time() - 86400)):
rmtree(join(environ["TMP"], i))
def reset_screen(banner):
if platform != "linux":
system("cls")
else:
system("clear")
print(*banner)
def main():
largeur1 = 500
hauteur1 = 350
largeur2 = 900
hauteur2 = 900
background_color = [255, 255, 255]
format_final = ".webp"
formats_acceptes = ("jpg", "jpeg", "png", "bmp", "gif", "webp")
json_path = join(getenv("USERPROFILE"), "AppData", "Local", "Redim")
app = QApplication([])
widget = QWidget()
while True:
redim = Redim(formats_acceptes)
if not isfile(join(json_path, "config_redim")):
Config.sauvegarde(json_path, largeur1, hauteur1, largeur2, hauteur2, background_color, format_final)
else:
largeur1, hauteur1, largeur2, hauteur2, background_color, format_final = Config.lecture(json_path)
if platform != "linux":
redim.nettoyage_pyinstaller()
banner = (
"\n ____ _ ____ ____ \n",
"| _ \\ _ __ ___ _ __ (_)_ _ _ __ ___ | _ \\ / ___|\n",
"| |_) | '__/ _ \\ '_ \\| | | | | '_ ` _ \\| |_) | | \n",
"| __/| | | __/ | | | | |_| | | | | | | __/| |___ \n",
"|_| |_| \\___|_| |_|_|\\__,_|_| |_| |_|_| \\____|\n",
"\n######################################################\n",
"\n[-] taille 1:", largeur1, "x", hauteur1, ", taille 2:", largeur2, "x", hauteur2,
"\n[-] rgb background:", background_color,
"\n[-] formats acceptes:", formats_acceptes,
"\n[-] format de sortie:", format_final,
"\n\n######################################################"
)
menu = (
"\n[-] Que faire?\n",
"\n (1) -> Conversion (", largeur1, "x", hauteur1, "px et", largeur2, "x", hauteur2, "px)",
"\n (5) -> Modification des tailles",
"\n (6) -> Modification du RGB",
"\n (7) -> Modification du format de sortie",
"\n (8) -> Reset des parametres",
"\n (9) -> Quitter\n"
)
reset_screen(banner)
print(*menu)
choix = input("[>] Choix (numero) : ")
while True:
reset_screen(banner)
if choix.strip() == "1":
dossier = QFileDialog.getExistingDirectory(
widget,
"Dossier a travailler."
)
print("\n[-] travail pour", largeur1, "x", hauteur1, "px :")
redim.start(dossier, largeur1, hauteur1, tuple(background_color), format_final)
print("\n[-] travail pour", largeur2, "x", hauteur2, "px :")
redim.start(dossier, largeur2, hauteur2, tuple(background_color), format_final)
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
elif choix.strip() == "5":
reset_screen(banner)
dimensions = [0, 0, 0, 0]
for pos, i in enumerate(dimensions):
if pos == 0:
print("\n[-] Taille 1:")
elif pos == 2:
print("\n[-] Taille 2:")
while True:
texte = [" [>] Largeur : ", " [>] Hauteur : "]
dimensions[pos] = input(texte[pos % 2])
try:
dimensions[pos] = int(dimensions[pos].strip())
break
except:
print(" >>>ERREUR<<< Valeur incorrecte.")
largeur1 = dimensions[0]
hauteur1 = dimensions[1]
largeur2 = dimensions[2]
hauteur2 = dimensions[3]
Config.sauvegarde(json_path, largeur1, hauteur1, largeur2, hauteur2, background_color, format_final)
print("\n[-] Modification effectue.")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
elif choix.strip() == "6":
reset_screen(banner)
nouveau_background_color = [0, 0, 0]
print("\n[-] Modification de la couleur du background (Valeur RGB 0-255):\n")
for pos, i in enumerate(background_color):
while True:
texte = [" [>] Valeur Rouge: ", " [>] Valeur Vert: ", " [>] Valeur Bleu: "]
nouveau_background_color[pos] = input(texte[pos])
try:
nouveau_background_color[pos] = int(nouveau_background_color[pos].strip())
if nouveau_background_color[pos] >= 0 and nouveau_background_color[pos] < 256:
break
else:
print(" >>>ERREUR<<< Valeur incorrecte.")
except:
print(" >>>ERREUR<<< Valeur incorrecte.")
background_color = nouveau_background_color
Config.sauvegarde(json_path, largeur1, hauteur1, largeur2, hauteur2, background_color, format_final)
print("\n[-] Modification effectue.")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
elif choix.strip() == "7":
print("\n[-] Modification du format de sortie:\n")
nombre = 1
for i in formats_acceptes:
nombre_choix = "(" + str(nombre) + ") ->"
print(" ", nombre_choix, i)
nombre += 1
nouveau_format = input("\n[>] Choix (numero) : ")
try:
nouveau_format = int(nouveau_format.strip())
if nouveau_format > 0:
format_final = "." + formats_acceptes[nouveau_format - 1]
Config.sauvegarde(json_path, largeur1, hauteur1, largeur2, hauteur2, background_color, format_final)
print("\n[-] Modification effectue.")
else:
print(">>>ERREUR<<< Choix invalide.")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
except:
print(">>>ERREUR<<< Choix invalide.")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
elif choix.strip() == "8":
reset_screen(banner)
print("\n[-] Reset des parametres.")
largeur1 = 500
hauteur1 = 350
largeur2 = 900
hauteur2 = 900
background_color = [255, 255, 255]
format_final = ".webp"
Config.sauvegarde(json_path, largeur1, hauteur1, largeur2, hauteur2, background_color, format_final)
print("\n[-] Modification effectue.")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
elif choix.strip() == "9":
if platform != "linux":
system("cls")
else:
system("clear")
exit(0)
else:
print("\n[-] Reponse invalide .")
input("\n[-] fin, appuyer sur \'entrer\' pour recommencer .")
break
if __name__ == "__main__":
main()
|