diff options
Diffstat (limited to 'Redim/ui.py')
| -rw-r--r-- | Redim/ui.py | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/Redim/ui.py b/Redim/ui.py index a5c5fc4..593ee81 100644 --- a/Redim/ui.py +++ b/Redim/ui.py @@ -1,8 +1,11 @@ +"""Contient toute la partie 'TUI' de Redim""" + from os import system from sys import platform class Ui: + """Gestion de l'interaction avec l'utilisateur""" def __init__(self, configuration): self.banner = ( "\n ____ _ ____ ____ \n", @@ -15,7 +18,7 @@ class Ui: ", ".join(map( str, ["x".join(map(str, configuration["dimensions"][i])) - for i in range(len(configuration["dimensions"]))] + for i in range(len(configuration["dimensions"]))] )) ), "\n[-] rgb background:", configuration["background"], @@ -34,36 +37,48 @@ class Ui: ) def affichage_banner(self): + """Reset de l'écran + affichage de la 'banner'""" + self.reset_screen() print(*self.banner) def affichage_menu(self): + """Affichage du menu principal""" print(*self.menu) - def question_taille(self, configuration): + @staticmethod + def question_taille(configuration): + """Récupère largeur & hauteur pour chaques tailles + enregistrées dans la configuration initiale + """ texte = [ - " [>] Largeur : ", - " [>] Hauteur : " + " [>] Largeur: ", + " [>] Hauteur: " ] tailles = [] for i in range(len(configuration)): print("\n[-] Taille {0!s}:".format(i + 1)) dimensions = [] - for j in range(len(texte)): + for j in texte: while True: - reponse = input(texte[j]) + reponse = input(j) try: reponse = int(reponse.strip()) - if reponse > 0: + if 5 < reponse < 5000: dimensions.append(reponse) break - else: - print(" >>>ERREUR<<< Valeur incorrecte.") - except: - print(" >>>ERREUR<<< Valeur incorrecte.") + print(" [ERREUR] La valeur trop petite" + " ou trop grande.") + except ValueError: + print(" [ERREUR] La valeur entree" + " n'est pas un chiffre.") tailles.append(dimensions) return tailles - def question_background(self, configuration): + @staticmethod + def question_background(configuration): + """Récupère 3 valeurs entre 0 & 255 pour la couleur qui servira + en remplissage si les photos sont redimensionnées ou avec alpha + """ texte = [ " [>] Valeur Rouge: ", " [>] Valeur Vert: ", @@ -79,18 +94,23 @@ class Ui: reponse = input(texte[i]) try: reponse = int(reponse.strip()) - if reponse >= 0 and reponse < 256: + if 0 <= reponse < 256: background.append(reponse) break - else: - print(" >>>ERREUR<<< Valeur incorrecte.") - except: - print(" >>>ERREUR<<< Valeur incorrecte.") + print(" [ERREUR] La valeur trop petite" + " ou trop grande.") + except ValueError: + print(" [ERREUR] La valeur entree" + " n'est pas un chiffre.") return background - def question_format_final(self, configuration): + @staticmethod + def question_format_final(configuration): + """Récupère le choix de sortie en fonction des formats + acceptés dans la configuration initiale + """ print("\n[-] Modification du format de sortie:\n") - for pos, i in enumerate(configuration): + for pos, i in enumerate(configuration[1:]): print( " (" + str(pos + 1) @@ -101,18 +121,21 @@ class Ui: reponse = input("\n[>] Choix (numero) : ") try: reponse = int(reponse.strip()) - if reponse > 0: - format_final = "." + configuration[reponse - 1] + if 0 < reponse <= len(configuration[1:]): + format_final = "." + configuration[reponse] return format_final - else: - print(">>>ERREUR<<< Choix invalide.") - except: - print(">>>ERREUR<<< Choix invalide.") + print("[ERREUR] Choix en dehors des possibilites.") + except ValueError: + print("[ERREUR] La valeur entree n'est pas un chiffre.") - def affichage_fin(self): + @staticmethod + def affichage_fin(): + """Bête appuye sur entrer pour continuer""" input("\n[-] fin, appuyer sur \'entrer\' pour continuer.") - def reset_screen(self): + @staticmethod + def reset_screen(): + """Reset de l'écran, cls pour CMD windows""" if platform != "linux": system("cls") else: |
