diff --git a/coretk/coretk/graph.py b/coretk/coretk/graph.py index 6f75e78c..e5a79612 100644 --- a/coretk/coretk/graph.py +++ b/coretk/coretk/graph.py @@ -361,9 +361,6 @@ class CanvasGraph(tk.Canvas): :return: nothing """ logging.debug(f"click press: {event}") - self.delete(self.find_withtag("selectednodes")) - self.canvas_management.selected.clear() - selected = self.get_selected(event) is_node = selected in self.find_withtag("node") if self.mode == GraphMode.EDGE and is_node: @@ -379,16 +376,19 @@ class CanvasGraph(tk.Canvas): self.selected = shape.id self.shapes[shape.id] = shape self.shape_drawing = True - if ( - self.mode == GraphMode.SELECT - and selected is not None - and "shape" in self.gettags(selected) - ): - x, y = self.canvas_xy(event) - self.shapes[selected].cursor_x = x - self.shapes[selected].cursor_y = y - self.canvas_management.node_select(self.shapes[selected]) - self.selected = selected + if self.mode == GraphMode.SELECT: + if selected is not None: + if "shape" in self.gettags(selected): + x, y = self.canvas_xy(event) + self.shapes[selected].cursor_x = x + self.shapes[selected].cursor_y = y + if selected not in self.canvas_management.selected: + self.canvas_management.node_select(self.shapes[selected]) + self.selected = selected + else: + for i in self.find_withtag("selectednodes"): + self.delete(i) + self.canvas_management.selected.clear() def ctrl_click(self, event): logging.debug("Control left click %s", event) @@ -419,7 +419,19 @@ class CanvasGraph(tk.Canvas): and self.selected is not None and "shape" in self.gettags(self.selected) ): - self.shapes[self.selected].motion(event) + x, y = self.canvas_xy(event) + shape = self.shapes[self.selected] + delta_x = x - shape.cursor_x + delta_y = y - shape.cursor_y + shape.motion(event) + # move other selected components + for nid in self.canvas_management.selected: + if nid != self.selected and nid in self.shapes: + self.shapes[nid].motion(None, delta_x, delta_y) + if nid != self.selected and nid in self.nodes: + node_x = self.nodes[nid].core_node.position.x + node_y = self.nodes[nid].core_node.position.y + self.nodes[nid].move(node_x + delta_x, node_y + delta_y) def click_context(self, event): logging.info("context event: %s", self.context) @@ -753,8 +765,9 @@ class CanvasNode: def click_press(self, event): logging.debug(f"node click press {self.core_node.name}: {event}") self.moving = self.canvas.canvas_xy(event) - self.canvas.canvas_management.node_select(self) - self.canvas.selected = self.id + if self.id not in self.canvas.canvas_management.selected: + self.canvas.canvas_management.node_select(self) + self.canvas.selected = self.id def click_release(self, event): logging.debug(f"node click release {self.core_node.name}: {event}") @@ -765,10 +778,19 @@ class CanvasNode: if self.canvas.mode == GraphMode.EDGE: return x, y = self.canvas.canvas_xy(event) + my_x = self.core_node.position.x + my_y = self.core_node.position.y self.move(x, y) - # for nid, bboxid in self.canvas.canvas_management.selected.items(): - # if nid in self.canvas.nodes: - # self.canvas.nodes[nid].motion(event) + # move other selected components + for nid, bboxid in self.canvas.canvas_management.selected.items(): + if nid != self.id and nid in self.canvas.nodes: + other_old_x = self.canvas.nodes[nid].core_node.position.x + other_old_y = self.canvas.nodes[nid].core_node.position.y + other_new_x = x + other_old_x - my_x + other_new_y = y + other_old_y - my_y + self.canvas.nodes[nid].move(other_new_x, other_new_y) + if nid != self.id and nid in self.canvas.shapes: + self.canvas.shapes[nid].motion(None, x - my_x, y - my_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 e30415c6..1365dc0f 100644 --- a/coretk/coretk/nodedelete.py +++ b/coretk/coretk/nodedelete.py @@ -33,6 +33,9 @@ class CanvasComponentManagement: tags="selectednodes", ) self.selected[canvas_node.id] = bbox_id + else: + bbox_id = self.selected.pop(canvas_node.id) + self.canvas.delete(bbox_id) def node_drag(self, canvas_node, offset_x, offset_y): select_id = self.selected.get(canvas_node.id) diff --git a/coretk/coretk/shape.py b/coretk/coretk/shape.py index d60beaef..c39c549b 100644 --- a/coretk/coretk/shape.py +++ b/coretk/coretk/shape.py @@ -59,19 +59,17 @@ class Shape: def click_release(self, event): logging.debug("Click release on shape %s", self.id) - def motion(self, event): + def motion(self, event, delta_x=None, delta_y=None): logging.debug("motion on shape %s", self.id) - delta_x = event.x - self.cursor_x - delta_y = event.y - self.cursor_y - x0, y0, x1, y1 = self.canvas.bbox(self.id) - self.canvas.coords( - self.id, x0 + delta_x, y0 + delta_y, x1 + delta_x, y1 + delta_y - ) + if event is not None: + delta_x = event.x - self.cursor_x + delta_y = event.y - self.cursor_y + self.cursor_x = event.x + self.cursor_y = event.y + self.canvas.move(self.id, delta_x, delta_y) self.canvas.canvas_management.node_drag(self, delta_x, delta_y) if self.text_id is not None: self.canvas.move(self.text_id, delta_x, delta_y) - self.cursor_x = event.x - self.cursor_y = event.y def delete(self): self.canvas.delete(self.id)