Skip to content

Commit 1e7532c

Browse files
committed
Merge branch 'master' of github.com:Team-Arduino-Logique/Arduino-Logique into fix-buttons-for-mac
2 parents 6bb9fe6 + 7bf0af5 commit 1e7532c

File tree

5 files changed

+142
-67
lines changed

5 files changed

+142
-67
lines changed

component_sketch.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
USED,
2727
INPUT,
2828
OUTPUT,
29+
CLOCK,
2930
)
3031
from component_params import BOARD_830_PTS_PARAMS, DIP14_PARAMS
3132
from utils import resource_path
@@ -2581,18 +2582,19 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ
25812582
label_x = (x_distance + x_origin + 5 * scale,)
25822583
label_y = (y_distance + y_origin - 17 * scale,)
25832584

2584-
label_tag = f"{element_id}_label"
2585-
text_id = self.canvas.create_text(
2586-
label_x,
2587-
label_y,
2588-
text=pin_number,
2589-
font=("FiraCode-Bold", int(7 * scale)),
2590-
fill="#000000",
2591-
anchor="center",
2592-
tags=(element_id, label_tag),
2593-
)
2594-
params["label_tag"] = label_tag
2595-
params["tags"].append(text_id)
2585+
if element_type != CLOCK:
2586+
label_tag = f"{element_id}_label"
2587+
text_id = self.canvas.create_text(
2588+
label_x,
2589+
label_y,
2590+
text=pin_number,
2591+
font=("FiraCode-Bold", int(7 * scale)),
2592+
fill="#000000",
2593+
anchor="center",
2594+
tags=(element_id, label_tag),
2595+
)
2596+
params["label_tag"] = label_tag
2597+
params["tags"].append(text_id)
25962598

25972599
if element_type == INPUT:
25982600
# Arrow pointing down
@@ -2645,6 +2647,45 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ
26452647
)
26462648
params["tags"].append(arrow_head_id)
26472649

2650+
elif element_type == CLOCK:
2651+
x_start = x_distance + x_origin + 0 * scale
2652+
y_start = y_distance + y_origin - 13 * scale
2653+
2654+
2655+
l1 = 5 * scale
2656+
h = 5 * scale
2657+
l2 = 5 * scale
2658+
2659+
# Draw the first horizontal line '_'
2660+
line1_id = self.canvas.create_line(
2661+
x_start, y_start,
2662+
x_start + l1, y_start,
2663+
fill="#404040",
2664+
width=2,
2665+
tags=(element_id, interactive_tag, outline_tag),
2666+
)
2667+
params["tags"].append(line1_id)
2668+
2669+
# Draw the vertical line '|'
2670+
line2_id = self.canvas.create_line(
2671+
x_start + l1, y_start,
2672+
x_start + l1, y_start - h,
2673+
fill="#404040",
2674+
width=2,
2675+
tags=(element_id, interactive_tag, outline_tag),
2676+
)
2677+
params["tags"].append(line2_id)
2678+
2679+
# Draw the second horizontal line '_'
2680+
line3_id = self.canvas.create_line(
2681+
x_start + l1, y_start - h,
2682+
x_start + l1 + l2, y_start - h,
2683+
fill="#404040",
2684+
width=2,
2685+
tags=(element_id, interactive_tag, outline_tag),
2686+
)
2687+
params["tags"].append(line3_id)
2688+
26482689
self.current_dict_circuit[element_id] = params
26492690

26502691
print("coord : " + str(coord[0][0]) + "," + str(coord[0][1]))

dataCDLT.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
USED = 1
99
INPUT = 0
1010
OUTPUT = 1
11+
CLOCK = 2
1112
NO = 0
1213
YES = 1
1314
LEFT = 0

menus.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
from breadboard import Breadboard
1717

18-
from dataCDLT import INPUT, OUTPUT
18+
from dataCDLT import INPUT, OUTPUT, CLOCK
1919

2020
if os.name == "darwin":
2121
from tkinter import messagebox, filedialog, ttk
22-
from tkmacosx import Button # type: ignore
22+
from tkmacosx import Button # type: ignore
2323
else:
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\nSimulateur de circuits logiques")
597+
messagebox.showinfo("À propos", "ArduinoLogique v1.0\nSimulateur de circuits logiques")
573598

574599
def open_port(self):
575600
"""Handler for the 'Open Port' menu item."""

sidebar.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def load_chip_images(self, img_path) -> dict[str, tk.PhotoImage]:
122122
images_dict: dict[str, tk.PhotoImage] = {}
123123

124124
if not os.path.isdir(img_path):
125-
messagebox.showerror("Error", f"Chip images directory '{img_path}' not found.")
125+
messagebox.showerror("Erreur", f"Répertoire des images de puces '{img_path}' introuvable.")
126126
return images_dict
127127

128128
supported_formats = (".png", ".gif", ".ppm", ".pgm")
@@ -139,7 +139,7 @@ def load_chip_images(self, img_path) -> dict[str, tk.PhotoImage]:
139139
print(f"Loaded and scaled chip image: {filename}")
140140
except (tk.TclError, FileNotFoundError) as e:
141141
print(f"Error loading image '{filename}': {e}")
142-
messagebox.showwarning("Image Load Error", f"Failed to load '{filename}'.")
142+
messagebox.showwarning("Erreur de chargement d'image", f"Échec du chargement de '{filename}'.")
143143
return images_dict
144144

145145
def create_search_bar(self, sidebar_frame):
@@ -152,7 +152,7 @@ def create_search_bar(self, sidebar_frame):
152152

153153
# Search label
154154
search_label = tk.Label(
155-
search_frame, text="Search Chips", bg="#333333", fg="#479dff", font=("Arial", 10, "bold")
155+
search_frame, text="Rechercher des composants", bg="#333333", fg="#479dff", font=("Arial", 10, "bold")
156156
)
157157
search_label.pack(anchor="w")
158158

@@ -174,7 +174,7 @@ def create_chips_area(self, sidebar_frame):
174174

175175
# Chips label
176176
chips_label = tk.Label(
177-
chips_label_frame, text="Available Chips", bg="#333333", fg="#479dff", font=("Arial", 10, "bold")
177+
chips_label_frame, text="Composants disponibles", bg="#333333", fg="#479dff", font=("Arial", 10, "bold")
178178
)
179179
chips_label.pack(anchor="w")
180180

@@ -264,7 +264,7 @@ def create_manage_button(self, sidebar_frame):
264264
"""
265265
manage_button = Button(
266266
sidebar_frame,
267-
text="Manage Components",
267+
text="Gérer les composants",
268268
bg="#333333", # Matching the sidebar's background to simulate transparency
269269
fg="white",
270270
activebackground="#333333",
@@ -405,7 +405,7 @@ def place_chip_at(self, x, y, chip_name):
405405
print(f"Nearest grid point: {nearest_x}, {nearest_y}, Column: {column}, Line: {line}")
406406

407407
if column is None or line is None:
408-
messagebox.showerror("Placement Error", "No grid point found nearby.")
408+
messagebox.showerror("Erreur de placement", "Aucun point de grille trouvé à proximité.")
409409
return
410410

411411
try:
@@ -414,7 +414,7 @@ def place_chip_at(self, x, y, chip_name):
414414
raise IndexError()
415415
except IndexError as e:
416416
print(f"Error: {e}")
417-
messagebox.showerror("Error", f"Unknown chip: {chip_name}")
417+
messagebox.showerror("Erreur", f"Puces inconnues : {chip_name}")
418418
return
419419

420420
chip_dict["internalFunc"] = self.sketcher.internal_func
@@ -496,7 +496,7 @@ def manage_components(self):
496496
with subprocess.Popen(["open", path] if sys.platform == "darwin" else ["xdg-open", path]):
497497
pass
498498
else:
499-
messagebox.showerror("Error", "Unsupported operating system.")
499+
messagebox.showerror("Erreur", "Système d'exploitation non pris en charge.")
500500

501501
def on_search(self, _):
502502
"""

0 commit comments

Comments
 (0)