pygui cleanup of edge code to use position tuples instead of individual params
This commit is contained in:
parent
23562cd294
commit
6f87986364
3 changed files with 18 additions and 19 deletions
|
@ -130,7 +130,8 @@ class Edge:
|
|||
def redraw(self):
|
||||
self.canvas.itemconfig(self.id, width=self.scaled_width(), fill=self.color)
|
||||
src_x, src_y, _, _, _, _ = self.canvas.coords(self.id)
|
||||
self.move_src(src_x, src_y)
|
||||
src_pos = src_x, src_y
|
||||
self.move_src(src_pos)
|
||||
|
||||
def middle_label_pos(self) -> Tuple[float, float]:
|
||||
_, _, x, y, _, _ = self.canvas.coords(self.id)
|
||||
|
@ -145,22 +146,20 @@ class Edge:
|
|||
else:
|
||||
self.canvas.itemconfig(self.middle_label, text=text)
|
||||
|
||||
def move_node(self, node_id: int, x: float, y: float) -> None:
|
||||
def move_node(self, node_id: int, pos: Tuple[float, float]) -> None:
|
||||
if self.src == node_id:
|
||||
self.move_src(x, y)
|
||||
self.move_src(pos)
|
||||
else:
|
||||
self.move_dst(x, y)
|
||||
self.move_dst(pos)
|
||||
|
||||
def move_dst(self, x: float, y: float) -> None:
|
||||
dst_pos = (x, y)
|
||||
def move_dst(self, dst_pos: Tuple[float, float]) -> None:
|
||||
src_x, src_y, _, _, _, _ = self.canvas.coords(self.id)
|
||||
src_pos = (src_x, src_y)
|
||||
src_pos = src_x, src_y
|
||||
self.moved(src_pos, dst_pos)
|
||||
|
||||
def move_src(self, x: float, y: float) -> None:
|
||||
src_pos = (x, y)
|
||||
def move_src(self, src_pos: Tuple[float, float]) -> None:
|
||||
_, _, _, _, dst_x, dst_y = self.canvas.coords(self.id)
|
||||
dst_pos = (dst_x, dst_y)
|
||||
dst_pos = dst_x, dst_y
|
||||
self.moved(src_pos, dst_pos)
|
||||
|
||||
def moved(self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float]) -> None:
|
||||
|
@ -220,8 +219,8 @@ class CanvasEdge(Edge):
|
|||
self.draw(src_pos, dst_pos)
|
||||
self.set_binding()
|
||||
|
||||
def move_node(self, node_id: int, x: float, y: float) -> None:
|
||||
super().move_node(node_id, x, y)
|
||||
def move_node(self, node_id: int, pos: Tuple[float, float]) -> None:
|
||||
super().move_node(node_id, pos)
|
||||
self.update_labels()
|
||||
|
||||
def set_binding(self) -> None:
|
||||
|
@ -302,8 +301,8 @@ class CanvasEdge(Edge):
|
|||
def complete(self, dst: int) -> None:
|
||||
self.dst = dst
|
||||
self.token = create_edge_token(self.src, self.dst)
|
||||
x, y = self.canvas.coords(self.dst)
|
||||
self.move_dst(x, y)
|
||||
dst_pos = self.canvas.coords(self.dst)
|
||||
self.move_dst(dst_pos)
|
||||
self.check_wireless()
|
||||
self.canvas.tag_raise(self.src)
|
||||
self.canvas.tag_raise(self.dst)
|
||||
|
|
|
@ -628,7 +628,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.cursor = x, y
|
||||
|
||||
if self.mode == GraphMode.EDGE and self.drawing_edge is not None:
|
||||
self.drawing_edge.move_dst(x, y)
|
||||
self.drawing_edge.move_dst(self.cursor)
|
||||
if self.mode == GraphMode.ANNOTATION:
|
||||
if is_draw_shape(self.annotation_type) and self.shape_drawing:
|
||||
shape = self.shapes[self.selected]
|
||||
|
|
|
@ -130,7 +130,7 @@ class CanvasNode:
|
|||
def motion(self, x_offset: int, y_offset: int, update: bool = True):
|
||||
original_position = self.canvas.coords(self.id)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
x, y = self.canvas.coords(self.id)
|
||||
pos = self.canvas.coords(self.id)
|
||||
|
||||
# check new position
|
||||
bbox = self.canvas.bbox(self.id)
|
||||
|
@ -148,12 +148,12 @@ class CanvasNode:
|
|||
|
||||
# move edges
|
||||
for edge in self.edges:
|
||||
edge.move_node(self.id, x, y)
|
||||
edge.move_node(self.id, pos)
|
||||
for edge in self.wireless_edges:
|
||||
edge.move_node(self.id, x, y)
|
||||
edge.move_node(self.id, pos)
|
||||
|
||||
# set actual coords for node and update core is running
|
||||
real_x, real_y = self.canvas.get_actual_coords(x, y)
|
||||
real_x, real_y = self.canvas.get_actual_coords(*pos)
|
||||
self.core_node.position.x = real_x
|
||||
self.core_node.position.y = real_y
|
||||
if self.app.core.is_runtime() and update:
|
||||
|
|
Loading…
Reference in a new issue