Commit 6314372d authored by Thorfin89's avatar Thorfin89

Correction sur la génération du code WIFI

parent 955f2cc1
...@@ -25,7 +25,7 @@ voire quelques fonctions supplémentaires à ajouter. ...@@ -25,7 +25,7 @@ voire quelques fonctions supplémentaires à ajouter.
- tk-tools - tk-tools
## Codage d'un accès Wifi : ## Codage d'un accès Wifi :
WIFI:T:*cryptage(nopass, WEP, WAPA)*;S:ssid;P:*motdepasse*;H:*caché(true)* WIFI:T:*cryptage(nopass, WEP, WPA)*;S:ssid;P:*motdepasse*;H:*caché(true / false)*
#### Exemple 1: #### Exemple 1:
......
...@@ -22,17 +22,16 @@ current_file = "temp.png" ...@@ -22,17 +22,16 @@ current_file = "temp.png"
# ===== FONCTIONS ===== # ===== FONCTIONS =====
def init(): def init():
# Réinitialisation de la configuration du QRCode
global bg_color global bg_color
global fg_color global fg_color
# réinitialisation de la configuration du QRCode
bg_color = "#FFFFFF" bg_color = "#FFFFFF"
bg_color_btn.config(bg=bg_color) bg_color_btn.config(bg=bg_color)
fg_color = "#000000" fg_color = "#000000"
fg_color_btn.config(bg=fg_color) fg_color_btn.config(bg=fg_color)
# bg_color_btn.config(bg=bg_color)
boxe_size_scale.set(5) boxe_size_scale.set(5)
border_size_scale.set(2) border_size_scale.set(2)
# on vide toutes les zones de saisie # On vide toutes les zones de saisie
ssid_name.delete(0, 'end') ssid_name.delete(0, 'end')
password.delete(0, 'end') password.delete(0, 'end')
text.delete(0, 'end') text.delete(0, 'end')
...@@ -45,7 +44,7 @@ def new_file(): ...@@ -45,7 +44,7 @@ def new_file():
current_file = "temp.png" current_file = "temp.png"
# ouverture d'un fichier # Ouverture d'un fichier
def open_file(): def open_file():
global current_file global current_file
file = filedialog.askopenfilename(title="Ouvrir un QRCode au format PNG", file = filedialog.askopenfilename(title="Ouvrir un QRCode au format PNG",
...@@ -53,16 +52,16 @@ def open_file(): ...@@ -53,16 +52,16 @@ def open_file():
initialdir="./qrcodes") initialdir="./qrcodes")
if file != "": if file != "":
current_file = file current_file = file
# on vide les zones de saisie du WIFI # On vide les zones de saisie du WIFI
init() init()
# on insère le nouveau code dans les données à coder # On insère le nouveau code dans les données à coder
text.insert(0, decode(file)) text.insert(0, decode(file))
# on code puis on affiche # On code puis on affiche
code() code()
display_qrcode() display_qrcode()
# enregistrer un fichier sous # Enregistrer un fichier sous
def save_as(): def save_as():
global current_file global current_file
file = filedialog.asksaveasfilename(title="Enregistrer le QRCode au format PNG sous", file = filedialog.asksaveasfilename(title="Enregistrer le QRCode au format PNG sous",
...@@ -87,19 +86,19 @@ def save(): ...@@ -87,19 +86,19 @@ def save():
qr.add_data(text.get()) qr.add_data(text.get())
qr.make(fit='True') qr.make(fit='True')
# création et sauvegarde de l'image du QRCode # Création et sauvegarde de l'image du QRCode
img = qr.make_image(fill_color=fg_color, back_color=bg_color) img = qr.make_image(fill_color=fg_color, back_color=bg_color)
img.save(current_file) img.save(current_file)
# lit l'image au format PNG et renvoie le texte # Lit l'image au format PNG et renvoie le texte
def decode(file): def decode(file):
decoder = cv2.QRCodeDetector() decoder = cv2.QRCodeDetector()
data_text, points, data_code = decoder.detectAndDecode(cv2.imread(file)) data_text, points, data_code = decoder.detectAndDecode(cv2.imread(file))
return data_text return data_text
# choix de la couleur du fond # Choix de la couleur du fond
def set_bg_color(): def set_bg_color():
global bg_color global bg_color
(rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur' (rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur'
...@@ -110,14 +109,14 @@ def set_bg_color(): ...@@ -110,14 +109,14 @@ def set_bg_color():
code() code()
display_qrcode() display_qrcode()
# si la couleur du fond du code est identique à celle de la fenêtre # Si la couleur du fond du code est identique à celle de la fenêtre
if bg_color == "#808080": if bg_color == "#808080":
right_frame.config(bg="#FFFFFF") right_frame.config(bg="#FFFFFF")
else: else:
right_frame.config(bg="#808080") right_frame.config(bg="#808080")
# choix de la couleur du code # Choix de la couleur du code
def set_fg_color(): def set_fg_color():
global fg_color global fg_color
(rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur' (rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur'
...@@ -147,18 +146,18 @@ def transfert(): ...@@ -147,18 +146,18 @@ def transfert():
# SSID caché OUI/NON # SSID caché OUI/NON
if hide_choice.get() == "OUI": if hide_choice.get() == "OUI":
cache = "True" cache = "true"
else: else:
cache = "" cache = "false"
if (crypt != "Aucun" and pwd != "") or (crypt == "Aucun" and password.get() == ""): if (crypt != "Aucun" and pwd != "") or (crypt == "Aucun" and password.get() == ""):
# mise à jour du texte à coder # Mise à jour du texte à coder
text.delete(0, 'end') text.delete(0, 'end')
code_wifi = "WIFI:T:" + crypt + ";S:" + ssid + ";P:" + pwd + ";H:" + cache code_wifi = "WIFI:T:" + crypt + ";P:" + pwd + ";S:" + ssid + ";H:" + cache + ";"
text.insert(0, code_wifi) text.insert(0, code_wifi)
# création de l'image du qrcode et affichage # Création de l'image du qrcode et affichage
code() code()
display_qrcode() display_qrcode()
...@@ -191,7 +190,7 @@ def code(): ...@@ -191,7 +190,7 @@ def code():
qr.add_data(text.get()) qr.add_data(text.get())
qr.make(fit='True') qr.make(fit='True')
# création et sauvegarde de l'image du QRCode # Création et sauvegarde de l'image du QRCode
img = qr.make_image(fill_color=fg_color, back_color=bg_color) img = qr.make_image(fill_color=fg_color, back_color=bg_color)
img.save("temp.png") img.save("temp.png")
...@@ -199,11 +198,11 @@ def code(): ...@@ -199,11 +198,11 @@ def code():
def display_qrcode(): def display_qrcode():
global qrcode_img global qrcode_img
# calcul de la taille du QRCode pour le centrer dans la fenêtre # Calcul de la taille du QRCode pour le centrer dans la fenêtre
img = Image.open("temp.png") img = Image.open("temp.png")
size = img.size size = img.size
# affichage du QRCode # Affichage du QRCode
qrcode_img = PhotoImage(file="temp.png") qrcode_img = PhotoImage(file="temp.png")
qrcode_label.config(image=qrcode_img, bg="white") qrcode_label.config(image=qrcode_img, bg="white")
qrcode_label.place(x=198 - size[0] // 2, y=198 - size[1] // 2) # centrage qrcode_label.place(x=198 - size[0] // 2, y=198 - size[1] // 2) # centrage
...@@ -211,13 +210,15 @@ def display_qrcode(): ...@@ -211,13 +210,15 @@ def display_qrcode():
def info(): def info():
messagebox.showinfo(title="Informations", messagebox.showinfo(title="Informations",
message=" objQRCode est une interface graphique" message="objQRCode v 1.1"
"\n----------------------"
"\n\n\n objQRCode est une interface graphique"
"\n pour qrcode sous Python" "\n pour qrcode sous Python"
"\n " "\n "
"\n Daniel SAZERAT - 2023") "\n Daniel SAZERAT - 2023")
# création de la fenêtre principale # Création de la fenêtre principale
root = Tk() root = Tk()
root.geometry('800x480+100+100') root.geometry('800x480+100+100')
root.resizable(width=False, height=False) root.resizable(width=False, height=False)
...@@ -244,7 +245,7 @@ menu_aide = Menu(menu_general, tearoff=0) ...@@ -244,7 +245,7 @@ menu_aide = Menu(menu_general, tearoff=0)
menu_general.add_cascade(label="Aide", menu=menu_aide) menu_general.add_cascade(label="Aide", menu=menu_aide)
# Création des sous menus 'Aide' # Création des sous menus 'Aide'
menu_aide.add_command(label="Info", command=info) menu_aide.add_command(label="À propos", command=info)
# Configuration de la barre des menus # Configuration de la barre des menus
root.config(menu=menu_general) root.config(menu=menu_general)
...@@ -261,75 +262,78 @@ bottom_frame.place(x=0, y=421, width=800, height=220) ...@@ -261,75 +262,78 @@ bottom_frame.place(x=0, y=421, width=800, height=220)
# ===== WIDGETS ===== # ===== WIDGETS =====
qrcode_cfg_title = Label(left_frame, text="CONFIGURATION DU QRCODE :", bg="#CCCCCC")
qrcode_cfg_title.place(x=20, y=20)
# Choix des couleurs # Choix des couleurs
color_choice = Label(left_frame, text="Choix de couleurs :", bg="#CCCCCC") color_choice = Label(left_frame, text="Choix de couleurs :", bg="#CCCCCC")
color_choice.place(x=20, y=18) color_choice.place(x=30, y=45)
bg_color_btn = Button(left_frame, bg=bg_color, relief=SUNKEN, command=set_bg_color) bg_color_btn = Button(left_frame, bg=bg_color, relief=SUNKEN, command=set_bg_color)
bg_color_btn.place(x=82, y=62, width=20, height=20) bg_color_btn.place(x=82, y=87, width=20, height=20)
fg_color_btn = Button(left_frame, bg=fg_color, relief=SUNKEN, command=set_fg_color) fg_color_btn = Button(left_frame, bg=fg_color, relief=SUNKEN, command=set_fg_color)
fg_color_btn.place(x=70, y=50, width=20, height=20) fg_color_btn.place(x=70, y=75, width=20, height=20)
# choix de la BOXE_SIZE # Choix de la BOXE_SIZE
boxe_size = IntVar() boxe_size = IntVar()
boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=boxe_size, orient=HORIZONTAL) boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=boxe_size, orient=HORIZONTAL)
boxe_size_scale.config(bg="#CCCCCC", label="Taille des points :", length=180, highlightthickness=0) boxe_size_scale.config(bg="#CCCCCC", label="Taille des points :", length=180, highlightthickness=0)
boxe_size_scale.set(5) boxe_size_scale.set(5)
boxe_size_scale.place(x=180, y=18) boxe_size_scale.place(x=180, y=45)
# choix de la taille de la bordure # Choix de la taille de la bordure
border_size = IntVar() border_size = IntVar()
border_size_scale = Scale(left_frame, from_=1, to=10, variable=border_size, orient=HORIZONTAL) border_size_scale = Scale(left_frame, from_=1, to=10, variable=border_size, orient=HORIZONTAL)
border_size_scale.config(bg="#CCCCCC", label="Épaisseur de la bordure :", length=180, highlightthickness=0) border_size_scale.config(bg="#CCCCCC", label="Épaisseur de la bordure :", length=180, highlightthickness=0)
border_size_scale.set(2) border_size_scale.set(2)
border_size_scale.place(x=180, y=90) border_size_scale.place(x=180, y=110)
# ===== point d'accès WIFI ===== # ===== Point d'accès WIFI =====
wifi_title = Label(left_frame, text='CONFIGURATION DU WIFI :', bg="#CCCCCC") wifi_title = Label(left_frame, text='CONFIGURATION DU WIFI :', bg="#CCCCCC")
wifi_title.place(x=30, y=175) wifi_title.place(x=20, y=195)
# SSID # SSID
ssid_name_title = Label(left_frame, text='SSID :', bg="#CCCCCC") ssid_name_title = Label(left_frame, text='SSID :', bg="#CCCCCC")
ssid_name_title.place(x=30, y=200) ssid_name_title.place(x=30, y=220)
ssid_name = Entry(left_frame, width=40) ssid_name = Entry(left_frame, width=40)
ssid_name.place(x=30, y=225) ssid_name.place(x=30, y=245)
# Password # Password
password_title = Label(left_frame, text='Mot de passe :', bg="#CCCCCC") password_title = Label(left_frame, text='Mot de passe :', bg="#CCCCCC")
password_title.place(x=30, y=250) password_title.place(x=30, y=270)
password = Entry(left_frame, width=40) password = Entry(left_frame, width=40)
password.place(x=30, y=275) password.place(x=30, y=295)
# Cryptage # Cryptage
crypt_title = Label(left_frame, text='Cryptage :', bg="#CCCCCC") crypt_title = Label(left_frame, text='Cryptage :', bg="#CCCCCC")
crypt_title.place(x=300, y=200) crypt_title.place(x=300, y=220)
crypt_list = ["WPA", "WEP", "Aucun"] crypt_list = ["WPA", "WEP", "Aucun"]
crypt_choice = SmartSpinBox(root, entry_type='str', width=8, justify=CENTER, crypt_choice = SmartSpinBox(root, entry_type='str', width=8, justify=CENTER,
values=crypt_list, callback=no_password) values=crypt_list, callback=no_password)
crypt_choice.place(x=300, y=225) crypt_choice.place(x=300, y=245)
# Caché # Caché
hide_title = Label(left_frame, text='Caché :', bg="#CCCCCC") hide_title = Label(left_frame, text='SSID caché :', bg="#CCCCCC")
hide_title.place(x=300, y=250) hide_title.place(x=300, y=270)
hide_list = ["NON", "OUI"] hide_list = ["NON", "OUI"]
hide_choice = Spinbox(left_frame, values=hide_list, width=8, justify=CENTER) hide_choice = Spinbox(left_frame, values=hide_list, width=8, justify=CENTER)
hide_choice.place(x=300, y=275) hide_choice.place(x=300, y=295)
# Transfert du code dans les données à coder # Transfert du code dans les données à coder
transfert_btn = Button(left_frame, text="Transfert\nvers\ndonnées", transfert_btn = Button(left_frame, text="Transfert\nvers\ndonnées",
bg="#61AEF9", command=transfert) bg="#61AEF9", command=transfert)
transfert_btn.place(x=30, y=320, width=60, height=60) transfert_btn.place(x=30, y=340, width=60, height=60)
# bouton de création du QRCode # Bouton de création du QRCode
code_btn = Button(left_frame, text="Créer le Code", bg="#88FF88", command=verif_before_code) code_btn = Button(left_frame, text="Créer le Code", bg="#88FF88", command=verif_before_code)
code_btn.place(x=260, y=380, width=100, height=40) code_btn.place(x=260, y=380, width=100, height=40)
# texte à coder # Texte à coder
text_title = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC") text_title = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC")
text_title.place(x=30, y=0) text_title.place(x=30, y=0)
text = Entry(bottom_frame, width=122) text = Entry(bottom_frame, width=122)
text.place(x=30, y=25) text.place(x=30, y=25)
# affichage du QRcode # Affichage du QRcode
qrcode_img = "" qrcode_img = ""
qrcode_label = Label(right_frame) qrcode_label = Label(right_frame)
qrcode_label.config(image=qrcode_img, borderwidth=0) qrcode_label.config(image=qrcode_img, borderwidth=0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment