1+ import tkinter as tk
2+ import tkinter .messagebox as messagebox
3+ import os
4+ import yaml
5+ import webbrowser
6+ from datetime import date
7+
8+ ver = "0.1"
9+
10+ def afficher_matiere (matiere ):
11+ folder_name = matiere .lower ()
12+ folder_path = os .path .join (os .getcwd (), folder_name )
13+
14+ # Check if the folder exists, if not, create it
15+ if not os .path .exists (folder_path ):
16+ os .makedirs (folder_path )
17+
18+ # Create the "Ancien" folder if it doesn't exist
19+ ancien_folder_path = os .path .join (folder_path , "ancien" )
20+ if not os .path .exists (ancien_folder_path ):
21+ os .makedirs (ancien_folder_path )
22+
23+ files = [file for file in os .listdir (folder_path ) if os .path .isfile (os .path .join (folder_path , file ))]
24+
25+ if len (files ) == 1 :
26+ file_path = os .path .join (folder_path , files [0 ])
27+ os .startfile (file_path ) # Open the file in the default file editor
28+ else :
29+ if len (files ) == 0 :
30+ result = messagebox .askquestion ("Dossier vide" , f"Le dossier { folder_name } est vide. Voulez-vous ouvrir le dossier ?" )
31+ if result == 'yes' :
32+ os .startfile (folder_path )
33+ else :
34+ # Ask if the folder should be opened
35+ result = messagebox .askquestion ("Fichiers multiples" , f"Le dossier { folder_name } contient plusieurs fichiers. Voulez-vous ouvrir le dossier ?" )
36+ if result == 'yes' :
37+ os .startfile (folder_path )
38+ def ouvrir_dossier (matiere ):
39+ folder_name = matiere .lower ()
40+ folder_path = os .path .join (os .getcwd (), folder_name )
41+ os .startfile (folder_path )
42+
43+ def creer_interface ():
44+ fenetre = tk .Tk ()
45+ fenetre .title ("Remember V" + ver )
46+ fenetre .resizable (False , False ) # Disable window resizing
47+
48+ # Change the background color
49+ fenetre .configure (bg = "lightgray" )
50+
51+ with open ("config.yml" , "r" , encoding = "utf-8" ) as config_file :
52+ config = yaml .safe_load (config_file )
53+
54+ images = {} # Store PhotoImage objects
55+
56+ # Add the logo image
57+ icon = tk .PhotoImage (file = "icon.png" )
58+ logo_image = tk .PhotoImage (file = "ban.png" )
59+ fenetre .iconphoto (True , icon ) # Set the window icon
60+ logo_label = tk .Label (fenetre , image = logo_image )
61+ logo_label .pack () # Set the logo width to fill the window horizontally
62+ # Function to handle logo click event
63+ def logo_click ():
64+ result = messagebox .askquestion ("À propos" , f"Remember V{ ver } by little Aywen rewrited in Python by Margouta. Souaithez-vous ouvrir la configuration ?" )
65+ if result == 'yes' :
66+ config = os .path .join (os .getcwd (), "config.yml" )
67+ os .startfile (config )
68+
69+ # Bind the logo click event to the logo label
70+ logo_label .bind ("<Button-1>" , lambda event : logo_click ())
71+
72+ # Add the date label
73+ today = date .today ()
74+ date_label = tk .Label (fenetre , text = "Nous sommes le " + today .strftime ("%d/%m/%Y" ), bg = "lightgray" )
75+ date_label .pack ()
76+
77+ for matiere , image_path in config .items ():
78+ bouton = tk .Button (fenetre , text = matiere .capitalize (), command = lambda matiere = matiere : afficher_matiere (matiere ), width = 200 )
79+ bouton .pack ()
80+
81+ image = tk .PhotoImage (file = "icons/" + image_path )
82+ image = image .subsample (int (image .height ()/ 32 ))
83+ bouton .config (image = image , compound = tk .LEFT )
84+
85+ # Change the button color
86+ bouton .config (bg = "gray" , fg = "white" )
87+
88+ images [matiere ] = image # Store PhotoImage object
89+
90+ # Add context menu for right-click
91+ context_menu = tk .Menu (fenetre , tearoff = 0 )
92+ context_menu .add_command (label = "Déplacer vers Ancien" , command = lambda matiere = matiere : deplacer_vers_ancien (matiere ))
93+ context_menu .add_command (label = "Ouvrir le dossier" , command = lambda matiere = matiere : ouvrir_dossier (matiere ))
94+ bouton .bind ("<Button-3>" , lambda event , context_menu = context_menu : context_menu .post (event .x_root , event .y_root ))
95+
96+ fenetre .bind ("<KeyPress>" , lambda event : check_easter_egg (event , fenetre ))
97+ fenetre .mainloop ()
98+
99+ def check_easter_egg (event , fenetre ):
100+ sequence = "haut haut bas bas gauche droite gauche droite"
101+ keys = ["Up" , "Up" , "Down" , "Down" , "Left" , "Right" , "Left" , "Right" ]
102+ current_sequence = getattr (fenetre , "easter_egg_sequence" , [])
103+ current_sequence .append (event .keysym )
104+ if current_sequence [- len (sequence ):] == keys :
105+ fenetre .easter_egg_sequence = []
106+ video_path = "https://glor.cc/bestmusiceasteregg"
107+ webbrowser .open (video_path )
108+ messagebox .showinfo ("Easter Egg" , "Vous avez trouvé l'easter egg ! C'est parti pour la musique !!!" )
109+ else :
110+ fenetre .easter_egg_sequence = current_sequence [- len (sequence ):]
111+
112+ def deplacer_vers_ancien (matiere ):
113+ folder_name = matiere .lower ()
114+ folder_path = os .path .join (os .getcwd (), folder_name )
115+ ancien_folder_path = os .path .join (folder_path , "ancien" )
116+
117+ files = [file for file in os .listdir (folder_path ) if os .path .isfile (os .path .join (folder_path , file ))]
118+
119+ if len (files ) == 0 :
120+ messagebox .showerror ("Erreur" , f"Le dossier { matiere } est vide." )
121+ return
122+
123+ for file in files :
124+ file_path = os .path .join (folder_path , file )
125+ new_file_path = os .path .join (ancien_folder_path , file )
126+ os .rename (file_path , new_file_path )
127+
128+ messagebox .showinfo ("Déplacement terminé" , f"Les fichiers de la matière { matiere } ont été déplacés vers le dossier 'ancien'." )
129+
130+ creer_interface ()
0 commit comments