Skip to content

Commit 76c193b

Browse files
authored
Merge pull request #91 from Team-Arduino-Logique/90-dessindeplacement-de-fils-est-tres-lent
Placement/déplacement de fils optimisé légèrement + ajustements graphiques
2 parents 3b2d509 + d62ecda commit 76c193b

File tree

7 files changed

+48
-49
lines changed

7 files changed

+48
-49
lines changed

Assets/Icons/input.png

-43 KB
Loading

Assets/Icons/output.png

-42.7 KB
Loading

breadboard.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,7 @@ class Breadboard:
3131
def __init__(self, canvas: Canvas, sketcher: ComponentSketcher):
3232
self.canvas = canvas
3333
self.sketcher = sketcher
34-
self.selector()
3534
self.canvas.config(cursor="")
36-
canvas.bind("<Motion>", self.follow_mouse)
37-
38-
def follow_mouse(self, event):
39-
"""
40-
Updates the mouse coordinates based on the given event.
41-
Args:
42-
event: An event object that contains the current mouse position.
43-
"""
44-
# FIXME fixing the coords crashes the app
45-
self.canvas.coords("selector_cable", [event.x - 10, event.y - 10, event.x + 0, event.y + 0])
46-
47-
def selector(self):
48-
"""
49-
Create the round selector cable movement
50-
"""
51-
self.canvas.create_oval(
52-
100,
53-
100,
54-
110,
55-
110,
56-
fill="#dfdfdf",
57-
outline="#404040",
58-
width=1,
59-
tags=("selector_cable"),
60-
)
61-
self.canvas.itemconfig("selector_cable", state="hidden")
6235

6336
def fill_matrix_830_pts(self, col_distance=1, line_distance=1):
6437
"""

component_sketch.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ def __init__(self, canvas) -> None:
5252
self.drag_selector = False
5353
self.nearest_multipoint = -1
5454
self.drag_chip_data = {"chip_id": None, "x": 0, "y": 0}
55-
self.wire_drag_data: dict[str, str | int | None] = {"wire_id": None, "endpoint": None, "x": 0, "y": 0}
55+
self.wire_drag_data: dict[str, str | int | None] = {
56+
"wire_id": None,
57+
"endpoint": None,
58+
"x": 0,
59+
"y": 0,
60+
"creating_wire": False,
61+
}
5662
self.pin_io_drag_data = {"pin_id": None, "x": 0, "y": 0}
5763
self.delete_mode_active = False
5864
self.drag_mouse = [0, 0]
@@ -323,19 +329,18 @@ def on_wire_body_enter(self, _, wire_id):
323329
"""
324330
Event handler for when the mouse enters the wire body.
325331
"""
326-
if not self.drag_selector and not self.delete_mode_active:
332+
if not self.drag_selector and not self.delete_mode_active and not self.wire_drag_data["creating_wire"]:
327333
color = self.current_dict_circuit[wire_id]["color"]
328334
encre = f"#{color[0]:02x}{color[1]:02x}{color[2]:02x}"
329335
contour = f"#{color[0]//2:02x}{color[1]//2:02x}{color[2]//2:02x}"
330-
self.canvas.itemconfig("selector_cable", fill=contour, outline=encre)
331-
self.canvas.itemconfig("selector_cable", state="normal")
336+
self.canvas.config(cursor=f"dot {encre} {contour}")
332337

333338
def on_wire_body_leave(self, *_):
334339
"""
335340
Event handler for when the mouse leaves the wire body.
336341
"""
337-
if not self.drag_selector:
338-
self.canvas.itemconfig("selector_cable", state="hidden")
342+
if not self.drag_selector and not self.wire_drag_data["creating_wire"]:
343+
self.canvas.config(cursor="arrow")
339344

340345
def on_wire_body_click(self, event, wire_id) -> None:
341346
"""
@@ -349,6 +354,7 @@ def on_wire_body_click(self, event, wire_id) -> None:
349354
self.delete_wire(wire_id)
350355

351356
else:
357+
self.wire_drag_data["creating_wire"] = True
352358
self.wire_drag_data["wire_id"] = wire_id
353359
self.wire_drag_data["endpoint"] = "selector_cable"
354360
endpoint_tag = "selector_cable"
@@ -450,10 +456,7 @@ def on_wire_body_release(self, *_):
450456
"""
451457
Event handler for when the wire body is released.
452458
"""
453-
self.wire_drag_data["wire_id"] = None
454-
self.wire_drag_data["endpoint"] = None
455-
self.nearest_multipoint = -1
456-
self.canvas.itemconfig("selector_cable", state="hidden")
459+
self.wire_drag_data["creating_wire"] = False
457460

458461
def start_chip_drag(self, event, chip_id):
459462
"""
@@ -2410,7 +2413,6 @@ def draw_wire(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZON
24102413
}
24112414
self.canvas.tag_raise(select_start_tag)
24122415
self.canvas.tag_raise(select_end_tag)
2413-
self.canvas.tag_raise("selector_cable")
24142416
# Bind events to the endpoints for drag-and-drop
24152417

24162418
self.canvas.tag_bind(
@@ -2429,6 +2431,12 @@ def draw_wire(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZON
24292431
wire_body_tag, "<B1-Motion>", lambda event, wire_id=wire_id: self.on_wire_body_drag(event, wire_id)
24302432
)
24312433

2434+
self.canvas.tag_bind(
2435+
wire_body_tag,
2436+
"<ButtonRelease-1>",
2437+
lambda event, wire_id=wire_id: self.on_wire_body_release(event, wire_id),
2438+
)
2439+
24322440
self.canvas.tag_bind(
24332441
select_start_tag,
24342442
"<Button-1>",
@@ -2564,10 +2572,10 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ
25642572
self.canvas.tag_raise(element_id)
25652573

25662574
# take the last number of the element_id as the pin number as an integer
2567-
pin_number = element_id.rsplit('_', maxsplit=1)[-1]
2575+
pin_number = element_id.rsplit("_", maxsplit=1)[-1]
25682576

2569-
label_x = x_distance + x_origin + 5 * scale,
2570-
label_y = y_distance + y_origin - 17 * scale,
2577+
label_x = (x_distance + x_origin + 5 * scale,)
2578+
label_y = (y_distance + y_origin - 17 * scale,)
25712579

25722580
label_tag = f"{element_id}_label"
25732581
text_id = self.canvas.create_text(
@@ -2633,8 +2641,6 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ
26332641
)
26342642
params["tags"].append(arrow_head_id)
26352643

2636-
2637-
26382644
self.current_dict_circuit[element_id] = params
26392645

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

menus.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ def create_menu(self, menu_name, options, menu_commands):
272272
pady=5,
273273
font=("FiraCode-Bold", 12),
274274
command=lambda m=menu_name: self.toggle_dropdown(m),
275+
borderwidth=0,
276+
highlightthickness=0,
275277
)
276278
btn.pack(side="left")
277279

@@ -305,6 +307,8 @@ def select_menu_item(option):
305307
pady=5,
306308
font=("FiraCode-Bold", 12),
307309
command=lambda o=option: select_menu_item(o),
310+
borderwidth=0,
311+
highlightthickness=0,
308312
)
309313
option_btn.pack(fill="both")
310314

sidebar.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
self.saved_bindings: dict[str, Callable] = {}
7474

7575
# Creating the sidebar frame
76-
sidebar_frame = tk.Frame(parent, bg="#333333", width=250, bd=0, highlightthickness=0)
76+
sidebar_frame = tk.Frame(parent, bg="#333333", width=275, bd=0, highlightthickness=0)
7777
sidebar_frame.grid(row=2, column=0, sticky="nsew", padx=0, pady=0)
7878
sidebar_frame.grid_propagate(False) # Preventing frame from resizing
7979

@@ -230,8 +230,11 @@ def display_chips(self, chips: list[Tuple[Chip, tk.PhotoImage]]):
230230
command=self.create_select_chip_command(chip.chip_type),
231231
width=100, # Fixed width to match image size
232232
height=60, # Fixed height to match image size
233+
borderwidth=0,
234+
highlightthickness=0,
235+
padx=10
233236
)
234-
btn.grid(row=row, column=col, padx=1, pady=1)
237+
btn.grid(row=row, column=col, padx=0, pady=0)
235238
Hovertip(btn, chip.description, 500) # Adding tooltip with chip name
236239

237240
def enter_effect(_, b=btn):
@@ -265,8 +268,9 @@ def create_manage_button(self, sidebar_frame):
265268
relief="flat",
266269
borderwidth=0,
267270
command=self.manage_components,
271+
highlightthickness=0,
268272
)
269-
manage_button.grid(row=3, column=0, padx=10, pady=5, sticky="we")
273+
manage_button.grid(row=3, column=0, padx=0, pady=0, sticky="we")
270274

271275
def select_chip(self, chip_name):
272276
"""
@@ -479,9 +483,13 @@ def manage_components(self):
479483
"""
480484
path = Path("Components").resolve()
481485
if os.name == "nt": # For Windows
482-
os.startfile(path)
483-
elif os.name == "posix": # For macOS and Linux
484-
subprocess.Popen(["open", path] if sys.platform == "darwin" else ["xdg-open", path])
486+
try:
487+
os.startfile(path)
488+
except AttributeError:
489+
pass
490+
elif os.name == "posix": # For macOS and Linux # type: ignore
491+
with subprocess.Popen(["open", path] if sys.platform == "darwin" else ["xdg-open", path]):
492+
pass
485493
else:
486494
messagebox.showerror("Error", "Unsupported operating system.")
487495

toolbar.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def create_topbar(self, parent: tk.Tk):
8585
relief="raised",
8686
bd=1,
8787
command=self.choose_color,
88+
borderwidth=0,
89+
highlightthickness=0,
8890
)
8991
self.color_button.pack(side=tk.LEFT, padx=2, pady=2)
9092
self.create_button("Delete", right_frame, images)
@@ -134,6 +136,8 @@ def create_button(self, action: str, parent_frame: tk.Frame, images: dict[str, t
134136
command=lambda: self.button_action(action),
135137
padx=2,
136138
pady=2,
139+
borderwidth=0,
140+
highlightthickness=0,
137141
)
138142
# Keep a reference to prevent garbage collection
139143
btn.image = image # type: ignore
@@ -151,6 +155,8 @@ def create_button(self, action: str, parent_frame: tk.Frame, images: dict[str, t
151155
command=lambda: self.button_action(action),
152156
padx=2,
153157
pady=2,
158+
borderwidth=0,
159+
highlightthickness=0,
154160
)
155161
btn.pack(side=tk.LEFT, padx=10, pady=2) # Minimal spacing between buttons
156162
self.buttons[action] = btn # Store button reference
@@ -318,6 +324,7 @@ def canvas_click(self, event):
318324
},
319325
)
320326
]
327+
self.sketcher.wire_drag_data["creating_wire"] = True
321328
self.sketcher.circuit(x_origin, y_origin, model=model_wire)
322329
self.wire_info.wire_id = self.current_dict_circuit["last_id"]
323330
self.wire_info.start_point = (adjusted_x, adjusted_y)
@@ -326,6 +333,7 @@ def canvas_click(self, event):
326333
# Finalize the wire
327334
self.wire_info.start_point = None
328335
self.wire_info.start_col_line = None
336+
self.sketcher.wire_drag_data["creating_wire"] = False
329337
print("Wire placement completed.")
330338

331339
elif self.tool_mode in ("Input", "Output") and self.sketcher.matrix[f"{col},{line}"]["state"] == FREE:

0 commit comments

Comments
 (0)