1515
1616from breadboard import Breadboard
1717
18- from dataCDLT import INPUT , OUTPUT
18+ from dataCDLT import INPUT , OUTPUT , CLOCK
1919
2020if os .name == "darwin" :
2121 from tkinter import messagebox , filedialog , ttk
22- from tkmacosx import Button # type: ignore
22+ from tkmacosx import Button # type: ignore
2323else :
2424 from tkinter import Button , messagebox , filedialog , ttk
2525
@@ -83,7 +83,6 @@ class Menus:
8383 parent (tk.Tk | tk.Frame): The main window or parent frame.
8484 canvas (tk.Canvas): The canvas widget for drawing circuits.
8585 board (Breadboard): The Breadboard instance.
86- model (list): The model data for the circuit.
8786 current_dict_circuit (dict): The current circuit data.
8887 com_port (str | None): The selected COM port.
8988 """
@@ -126,10 +125,7 @@ def __init__(
126125 menus = {
127126 "Fichier" : ["Nouveau" , "Ouvrir" , "Enregistrer" , "Quitter" ],
128127 "Microcontrôleur" : ["Choisir un microcontrôleur" , "Table de correspondance" , "Configurer le port série" ],
129- "Exporter" : [
130- "Vérifier" ,
131- "Téléverser" ,
132- ],
128+ "Exporter" : ["Vérifier" , "Téléverser" ],
133129 "Aide" : ["Documentation" , "À propos" ],
134130 }
135131
@@ -148,6 +144,16 @@ def __init__(
148144 for menu_name , options in menus .items ():
149145 self .create_menu (menu_name , options , menu_commands )
150146
147+ # Display selected microcontroller label
148+ self .microcontroller_label = tk .Label (
149+ self .menu_bar ,
150+ text = "(Aucun microcontrôleur n'est choisi)" ,
151+ bg = "#333333" ,
152+ fg = "white" ,
153+ font = ("FiraCode-Bold" , 12 ),
154+ )
155+ self .microcontroller_label .pack (side = "right" , padx = 10 )
156+
151157 # Bind to parent to close dropdowns when clicking outside
152158 self .parent .bind ("<Button-1>" , self .close_dropdown , add = "+" )
153159 self .canvas .bind ("<Button-1>" , self .close_dropdown , add = "+" )
@@ -175,20 +181,24 @@ def confirm_selection():
175181 print (f"Selected option: { selected_option } " )
176182 self .selected_microcontroller = selected_option
177183 print (f"{ selected_option } selected." )
184+ # Update the label text
185+ self .microcontroller_label .config (text = self .selected_microcontroller )
178186 dialog .destroy ()
179187
180- confirm_button = Button (dialog , text = "Confirm " , command = confirm_selection )
188+ confirm_button = Button (dialog , text = "Confirmer " , command = confirm_selection )
181189 confirm_button .pack (pady = 10 )
182190
183191 def show_correspondence_table (self ):
184192 """Displays the correspondence table between pin_io objects and microcontroller pins in a table format."""
185193 if self .selected_microcontroller is None :
186- messagebox .showwarning ("No Microcontroller Selected" , "Please select a microcontroller first." )
194+ messagebox .showwarning (
195+ "Aucun microcontrôleur sélectionné" , "Veuillez d'abord sélectionner un microcontrôleur."
196+ )
187197 return
188198
189199 pin_mappings = MICROCONTROLLER_PINS .get (self .selected_microcontroller )
190200 if not pin_mappings :
191- messagebox .showerror ("Error " , f"No pin mappings found for { self .selected_microcontroller } ." )
201+ messagebox .showerror ("Erreur " , f"Aucun mappage de broches trouvé pour { self .selected_microcontroller } ." )
192202 return
193203
194204 input_pins = pin_mappings ["input_pins" ]
@@ -197,44 +207,50 @@ def show_correspondence_table(self):
197207 # Gather pin_io objects from current_dict_circuit
198208 pin_ios = [value for key , value in self .current_dict_circuit .items () if key .startswith ("_io_" )]
199209
200- # Separate pin_ios into inputs and outputs
210+ # Separate pin_ios into inputs, outputs, and clocks
201211 input_pin_ios = [pin for pin in pin_ios if pin ["type" ] == INPUT ]
202212 output_pin_ios = [pin for pin in pin_ios if pin ["type" ] == OUTPUT ]
213+ clock_pin_ios = [pin for pin in pin_ios if pin ["type" ] == CLOCK ]
214+
215+ # Ensure only one CLOCK type
216+ if len (clock_pin_ios ) > 1 :
217+ messagebox .showerror ("Erreur d'horloge" , "Une seule HORLOGE est autorisée." )
218+ return
203219
204- # Check if we have more pin_ios than available pins
220+ # Check pin counts
205221 if len (input_pin_ios ) > len (input_pins ):
206222 messagebox .showerror (
207- "Too Many Inputs " ,
208- f"You have { len (input_pin_ios )} input pin_ios but only "
209- f"{ len (input_pins )} available input pins on the microcontroller ." ,
223+ "Trop d'entrées " ,
224+ f"Vous avez { len (input_pin_ios )} broches d'entrée, mais seulement "
225+ f"{ len (input_pins )} broches d'entrée disponibles sur le microcontrôleur ." ,
210226 )
211227 return
212228 if len (output_pin_ios ) > len (output_pins ):
213229 messagebox .showerror (
214- "Too Many Outputs " ,
215- f"You have { len (output_pin_ios )} output pin_ios but only "
216- f"{ len (output_pins )} available output pins on the microcontroller ." ,
230+ "Trop de sorties " ,
231+ f"Vous avez { len (output_pin_ios )} broches de sortie, mais seulement "
232+ f"{ len (output_pins )} broches de sortie disponibles sur le microcontrôleur ." ,
217233 )
218234 return
219235
220236 # Create a new window for the correspondence table
221237 table_window = tk .Toplevel (self .parent )
222238 table_window .title ("Correspondence Table" )
223- table_window .geometry ("400x300 " )
239+ table_window .geometry ("500x350 " )
224240
225241 # Create a Treeview widget for the table
226- tree = ttk .Treeview (table_window , columns = ("ID" , "Type" , "MCU Pin" ), show = "headings" , height = 10 )
242+ tree = ttk .Treeview (table_window , columns = ("ID" , "Type" , "MCU Pin" ), show = "headings" , height = 15 )
227243 tree .pack (expand = True , fill = "both" , padx = 10 , pady = 10 )
228244
229245 # Define columns and headings
230246 tree .column ("ID" , anchor = "center" , width = 120 )
231- tree .column ("Type" , anchor = "center" , width = 80 )
247+ tree .column ("Type" , anchor = "center" , width = 120 )
232248 tree .column ("MCU Pin" , anchor = "center" , width = 120 )
233249 tree .heading ("ID" , text = "Pin IO ID" )
234250 tree .heading ("Type" , text = "Type" )
235251 tree .heading ("MCU Pin" , text = "MCU Pin" )
236252
237- # Populate the table with input and output pin mappings
253+ # Populate the table with input, output, and clock pin mappings
238254 for idx , pin_io in enumerate (input_pin_ios ):
239255 mcu_pin = input_pins [idx ]
240256 pin_number = pin_io ["id" ].split ("_" )[- 1 ]
@@ -245,6 +261,11 @@ def show_correspondence_table(self):
245261 pin_number = pin_io ["id" ].split ("_" )[- 1 ]
246262 tree .insert ("" , "end" , values = (pin_number , "Output" , mcu_pin ))
247263
264+ if clock_pin_ios :
265+ clock_pin = pin_mappings ["clock_pin" ]
266+ pin_number = clock_pin_ios [0 ]["id" ].split ("_" )[- 1 ]
267+ tree .insert ("" , "end" , values = (pin_number , "clk input" , clock_pin ))
268+
248269 # Add a scrollbar if the list gets too long
249270 scrollbar = ttk .Scrollbar (table_window , orient = "vertical" , command = tree .yview )
250271 tree .configure (yscroll = scrollbar .set )
@@ -388,7 +409,7 @@ def new_file(self):
388409 self .board .draw_blank_board_model ()
389410
390411 print ("New file created." )
391- messagebox .showinfo ("New File " , "A new circuit has been created ." )
412+ messagebox .showinfo ("Nouveau fichier " , "Un nouveau circuit a été créé ." )
392413
393414 def open_file (self ):
394415 """Handler for the 'Open' menu item."""
@@ -409,9 +430,9 @@ def open_file(self):
409430
410431 for key , val in circuit_data .items ():
411432 if key == "_battery_pos_wire" :
412- battery_pos_wire_end = val [' end' ]
433+ battery_pos_wire_end = val [" end" ]
413434 elif key == "_battery_neg_wire" :
414- battery_neg_wire_end = val [' end' ]
435+ battery_neg_wire_end = val [" end" ]
415436
416437 self .board .draw_blank_board_model (
417438 x_o ,
@@ -433,10 +454,12 @@ def open_file(self):
433454 else :
434455
435456 print (f"Unspecified component: { key } " )
436- messagebox .showinfo ("Open File " , f"Circuit loaded from { file_path } " )
457+ messagebox .showinfo ("Ouvrir un fichier " , f"Circuit chargé depuis { file_path } " )
437458 except Exception as e :
438459 print (f"Error loading file: { e } " )
439- messagebox .showerror ("Open Error" , f"An error occurred while opening the file:\n { e } " )
460+ messagebox .showerror (
461+ "Erreur d'ouverture" , f"Une erreur s'est produite lors de l'ouverture du fichier:\n { e } "
462+ )
440463 raise e
441464 else :
442465 print ("Open file cancelled." )
@@ -514,17 +537,19 @@ def save_file(self):
514537 if "label" in comp_data :
515538 comp_data ["label" ] = comp_data ["type" ]
516539 if "wire" in key :
517- comp_data .pop ("XY" , None ) # Remove XY, will be recalculated anyway
540+ comp_data .pop ("XY" , None ) # Remove XY, will be recalculated anyway
518541 if key == "_battery" :
519542 comp_data .pop ("battery_rect" , None )
520543 # Save the data to a JSON file
521544 with open (file_path , "w" , encoding = "utf-8" ) as file :
522545 json .dump (circuit_data , file , indent = 4 )
523546 print (f"Circuit saved to { file_path } " )
524- messagebox .showinfo ("Save Successful " , f"Circuit saved to { file_path } " )
547+ messagebox .showinfo ("Sauvegarde réussie " , f"Circuit sauvegardé dans { file_path } " )
525548 except (TypeError , KeyError ) as e :
526549 print (f"Error saving file: { e } " )
527- messagebox .showerror ("Save Error" , f"An error occurred while saving the file:\n { e } " )
550+ messagebox .showerror (
551+ "Erreur de sauvegarde" , f"Une erreur s'est produite lors de la sauvegarde du fichier:\n { e } "
552+ )
528553 else :
529554 print ("Save file cancelled." )
530555
@@ -535,7 +560,7 @@ def configure_ports(self):
535560 if len (options ) == 0 :
536561 message = "No COM ports available. Please connect a device and try again."
537562 print (message )
538- messagebox .showwarning ("No COM Ports " , message )
563+ messagebox .showwarning ("Pas de ports COM " , message )
539564 else :
540565 dialog = tk .Toplevel (self .parent )
541566 dialog .title ("Configure Ports" )
@@ -569,7 +594,7 @@ def open_documentation(self):
569594 def about (self ):
570595 """Handler for the 'About' menu item."""
571596 print ("About this software" )
572- messagebox .showinfo ("About " , "ArduinoLogique v1.0\n Simulateur de circuits logiques" )
597+ messagebox .showinfo ("À propos " , "ArduinoLogique v1.0\n Simulateur de circuits logiques" )
573598
574599 def open_port (self ):
575600 """Handler for the 'Open Port' menu item."""
0 commit comments