From 804b95d486de3ac21e218a965da68c34ff826703 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 27 Nov 2019 13:23:45 -0800 Subject: [PATCH] consolidated node move logic to one function, used by both node events and node drag --- coretk/coretk/graph.py | 36 ++++++------------------------------ coretk/coretk/nodedelete.py | 4 +++- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/coretk/coretk/graph.py b/coretk/coretk/graph.py index 7bfe7ed3..274073df 100644 --- a/coretk/coretk/graph.py +++ b/coretk/coretk/graph.py @@ -598,17 +598,18 @@ class CanvasNode: old_y = self.core_node.position.y x_offset = x - old_x y_offset = y - old_y - self.core_node.position.x = x - self.core_node.position.y = y + self.core_node.position.x = int(x) + self.core_node.position.y = int(y) self.canvas.move(self.id, x_offset, y_offset) self.canvas.move(self.text_id, x_offset, y_offset) self.antenna_draw.update_antennas_position(x_offset, y_offset) + self.canvas.canvas_management.node_drag(self, x_offset, y_offset) for edge in self.edges: x1, y1, x2, y2 = self.canvas.coords(edge.id) if edge.src == self.id: - self.canvas.coords(edge.id, x_offset, y_offset, x2, y2) + self.canvas.coords(edge.id, x, y, x2, y2) else: - self.canvas.coords(edge.id, x1, y1, x_offset, y_offset) + self.canvas.coords(edge.id, x1, y1, x, y) edge.link_info.recalculate_info() self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans) @@ -650,32 +651,7 @@ class CanvasNode: if self.canvas.mode == GraphMode.EDGE or self.canvas.mode == GraphMode.NODE: return x, y = self.canvas.canvas_xy(event) - moving_x, moving_y = self.moving - offset_x, offset_y = x - moving_x, y - moving_y - self.moving = x, y - - old_x, old_y = self.canvas.coords(self.id) - self.canvas.move(self.id, offset_x, offset_y) - self.canvas.move(self.text_id, offset_x, offset_y) - self.antenna_draw.update_antennas_position(offset_x, offset_y) - self.canvas.canvas_management.node_drag(self, offset_x, offset_y) - - new_x, new_y = self.canvas.coords(self.id) - - if self.canvas.core.is_runtime(): - self.canvas.core.edit_node(self.core_node.id, int(new_x), int(new_y)) - - for edge in self.edges: - x1, y1, x2, y2 = self.canvas.coords(edge.id) - if x1 == old_x and y1 == old_y: - self.canvas.coords(edge.id, new_x, new_y, x2, y2) - else: - self.canvas.coords(edge.id, x1, y1, new_x, new_y) - edge.link_info.recalculate_info() - - self.canvas.helper.update_wlan_connection( - old_x, old_y, new_x, new_y, self.wlans - ) + self.move(x, y) def select_multiple(self, event): self.canvas.canvas_management.node_select(self, True) diff --git a/coretk/coretk/nodedelete.py b/coretk/coretk/nodedelete.py index f52731e4..341f95ef 100644 --- a/coretk/coretk/nodedelete.py +++ b/coretk/coretk/nodedelete.py @@ -35,7 +35,9 @@ class CanvasComponentManagement: self.selected[canvas_node.id] = bbox_id def node_drag(self, canvas_node, offset_x, offset_y): - self.canvas.move(self.selected[canvas_node.id], offset_x, offset_y) + select_id = self.selected.get(canvas_node.id) + if select_id is not None: + self.canvas.move(select_id, offset_x, offset_y) def delete_current_bbox(self): for bbid in self.selected.values():