88from dataclasses import dataclass
99import os
1010import tkinter as tk
11- from tkinter import messagebox , filedialog , ttk
1211import json
1312import subprocess
1413import platform
15- from typing import Callable
1614import serial .tools .list_ports # type: ignore
1715
1816from breadboard import Breadboard
1917
20- from dataCDLT import INPUT , OUTPUT , USED , CLOCK
18+ from dataCDLT import INPUT , OUTPUT , CLOCK
19+
20+ if os .name == "darwin" :
21+ from tkinter import messagebox , filedialog , ttk
22+ from tkmacosx import Button # type: ignore
23+ else :
24+ from tkinter import Button , messagebox , filedialog , ttk
2125
2226MICROCONTROLLER_PINS = {
2327 "Arduino Mega" : {
@@ -181,13 +185,15 @@ def confirm_selection():
181185 self .microcontroller_label .config (text = self .selected_microcontroller )
182186 dialog .destroy ()
183187
184- confirm_button = tk . Button (dialog , text = "Confirmer" , command = confirm_selection )
188+ confirm_button = Button (dialog , text = "Confirmer" , command = confirm_selection )
185189 confirm_button .pack (pady = 10 )
186190
187191 def show_correspondence_table (self ):
188192 """Displays the correspondence table between pin_io objects and microcontroller pins in a table format."""
189193 if self .selected_microcontroller is None :
190- messagebox .showwarning ("Aucun microcontrôleur sélectionné" , "Veuillez d'abord sélectionner un microcontrôleur." )
194+ messagebox .showwarning (
195+ "Aucun microcontrôleur sélectionné" , "Veuillez d'abord sélectionner un microcontrôleur."
196+ )
191197 return
192198
193199 pin_mappings = MICROCONTROLLER_PINS .get (self .selected_microcontroller )
@@ -279,7 +285,7 @@ def create_menu(self, menu_name, options, menu_commands):
279285 - options (list): List of options under the menu.
280286 """
281287 # Create the menu button
282- btn = tk . Button (
288+ btn = Button (
283289 self .menu_bar ,
284290 text = menu_name ,
285291 bg = "#333333" ,
@@ -312,7 +318,7 @@ def select_menu_item(option):
312318
313319 # Populate the dropdown with menu options
314320 for option in options :
315- option_btn = tk . Button (
321+ option_btn = Button (
316322 dropdown ,
317323 text = option ,
318324 bg = "#333333" ,
@@ -343,7 +349,7 @@ def toggle_dropdown(self, menu_name):
343349 - menu_name (str): The name of the menu to toggle.
344350 """
345351 for child in self .menu_bar .winfo_children ():
346- if isinstance (child , tk . Button ) and hasattr (child , "dropdown" ):
352+ if isinstance (child , Button ) and hasattr (child , "dropdown" ):
347353 if child ["text" ] == menu_name :
348354 if child .dropdown .winfo_ismapped ():
349355 child .dropdown .place_forget ()
@@ -387,11 +393,11 @@ def close_dropdown(self, event):
387393 and not any (
388394 self .is_descendant (event .widget , child .dropdown )
389395 for child in self .menu_bar .winfo_children ()
390- if isinstance (child , tk . Button ) and hasattr (child , "dropdown" )
396+ if isinstance (child , Button ) and hasattr (child , "dropdown" )
391397 )
392398 ):
393399 for child in self .menu_bar .winfo_children ():
394- if isinstance (child , tk . Button ) and hasattr (child , "dropdown" ):
400+ if isinstance (child , Button ) and hasattr (child , "dropdown" ):
395401 child .dropdown .place_forget ()
396402
397403 # Menu Handler Functions
@@ -424,9 +430,9 @@ def open_file(self):
424430
425431 for key , val in circuit_data .items ():
426432 if key == "_battery_pos_wire" :
427- battery_pos_wire_end = val [' end' ]
433+ battery_pos_wire_end = val [" end" ]
428434 elif key == "_battery_neg_wire" :
429- battery_neg_wire_end = val [' end' ]
435+ battery_neg_wire_end = val [" end" ]
430436
431437 self .board .draw_blank_board_model (
432438 x_o ,
@@ -451,7 +457,9 @@ def open_file(self):
451457 messagebox .showinfo ("Ouvrir un fichier" , f"Circuit chargé depuis { file_path } " )
452458 except Exception as e :
453459 print (f"Error loading file: { e } " )
454- messagebox .showerror ("Erreur d'ouverture" , f"Une erreur s'est produite lors de l'ouverture du fichier:\n { e } " )
460+ messagebox .showerror (
461+ "Erreur d'ouverture" , f"Une erreur s'est produite lors de l'ouverture du fichier:\n { e } "
462+ )
455463 raise e
456464 else :
457465 print ("Open file cancelled." )
@@ -529,7 +537,7 @@ def save_file(self):
529537 if "label" in comp_data :
530538 comp_data ["label" ] = comp_data ["type" ]
531539 if "wire" in key :
532- comp_data .pop ("XY" , None ) # Remove XY, will be recalculated anyway
540+ comp_data .pop ("XY" , None ) # Remove XY, will be recalculated anyway
533541 if key == "_battery" :
534542 comp_data .pop ("battery_rect" , None )
535543 # Save the data to a JSON file
@@ -539,7 +547,9 @@ def save_file(self):
539547 messagebox .showinfo ("Sauvegarde réussie" , f"Circuit sauvegardé dans { file_path } " )
540548 except (TypeError , KeyError ) as e :
541549 print (f"Error saving file: { e } " )
542- messagebox .showerror ("Erreur de sauvegarde" , f"Une erreur s'est produite lors de la sauvegarde du fichier:\n { e } " )
550+ messagebox .showerror (
551+ "Erreur de sauvegarde" , f"Une erreur s'est produite lors de la sauvegarde du fichier:\n { e } "
552+ )
543553 else :
544554 print ("Save file cancelled." )
545555
@@ -568,7 +578,7 @@ def confirm_selection():
568578 self .serial_port .com_port = selected_option
569579 dialog .destroy ()
570580
571- confirm_button = tk . Button (dialog , text = "Confirm" , command = confirm_selection )
581+ confirm_button = Button (dialog , text = "Confirm" , command = confirm_selection )
572582 confirm_button .pack (pady = 10 )
573583
574584 def open_documentation (self ):
0 commit comments