@@ -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 ]))
0 commit comments