def click_motion(self, event): """ Redraw drawing edge according to the current position of the mouse :param event: mouse event :return: nothing """ x, y = self.canvas_xy(event) if not self.inside_canvas(x, y): if self.select_box: self.select_box.delete() self.select_box = None if is_draw_shape(self.annotation_type) and self.shape_drawing: shape = self.shapes.pop(self.selected) shape.delete() self.shape_drawing = False return x_offset = x - self.cursor[0] y_offset = y - self.cursor[1] self.cursor = x, y if self.mode == GraphMode.EDGE and self.drawing_edge is not None: x1, y1, _, _ = self.coords(self.drawing_edge.id) self.coords(self.drawing_edge.id, x1, y1, x, y) if self.mode == GraphMode.ANNOTATION: if is_draw_shape(self.annotation_type) and self.shape_drawing: shape = self.shapes[self.selected] shape.shape_motion(x, y) elif is_marker(self.annotation_type): r = self.app.toolbar.marker_tool.radius self.create_oval( x - r, y - r, x + r, y + r, fill=self.app.toolbar.marker_tool.color, outline="", tags="marker", ) return if self.mode == GraphMode.EDGE: return # move selected objects if self.selection: for selected_id in self.selection: if selected_id in self.shapes: shape = self.shapes[selected_id] shape.motion(x_offset, y_offset) if selected_id in self.nodes: node = self.nodes[selected_id] node.motion(x_offset, y_offset, update=self.core.is_runtime()) else: if self.select_box and self.mode == GraphMode.SELECT: self.select_box.shape_motion(x, y)
def click_motion(self, event: tk.Event) -> None: x, y = self.canvas_xy(event) if not self.inside_canvas(x, y): if self.select_box: self.select_box.delete() self.select_box = None if is_draw_shape( self.manager.annotation_type) and self.shape_drawing: shape = self.shapes.pop(self.selected) shape.delete() self.shape_drawing = False return x_offset = x - self.cursor[0] y_offset = y - self.cursor[1] self.cursor = x, y if self.manager.mode == GraphMode.EDGE and self.drawing_edge is not None: self.drawing_edge.drawing(self.cursor) if self.manager.mode == GraphMode.ANNOTATION: if is_draw_shape( self.manager.annotation_type) and self.shape_drawing: shape = self.shapes[self.selected] shape.shape_motion(x, y) return elif is_marker(self.manager.annotation_type): r = self.app.toolbar.marker_frame.size.get() self.create_oval( x - r, y - r, x + r, y + r, fill=self.app.toolbar.marker_frame.color, outline="", tags=(tags.MARKER, tags.ANNOTATION), ) return if self.manager.mode == GraphMode.EDGE: return # move selected objects if self.selection: for selected_id in self.selection: if self.manager.mode in MOVE_SHAPE_MODES and selected_id in self.shapes: shape = self.shapes[selected_id] shape.motion(x_offset, y_offset) elif self.manager.mode in MOVE_NODE_MODES and selected_id in self.nodes: node = self.nodes[selected_id] node.motion(x_offset, y_offset, update=self.core.is_runtime()) elif (self.manager.mode in MOVE_NODE_MODES and selected_id in self.shadow_nodes): shadow_node = self.shadow_nodes[selected_id] shadow_node.motion(x_offset, y_offset) else: if self.select_box and self.manager.mode == GraphMode.SELECT: self.select_box.shape_motion(x, y)
def draw(self): self.top.columnconfigure(0, weight=1) self.draw_label_options() if is_draw_shape(self.shape.shape_type): self.draw_shape_options() self.draw_spacer() self.draw_buttons()
def __init__(self, master: "Application", app: "Application", shape: "Shape"): if is_draw_shape(shape.shape_type): title = "Add Shape" else: title = "Add Text" super().__init__(master, app, title, modal=True) self.canvas = app.canvas self.fill = None self.border = None self.shape = shape data = shape.shape_data self.shape_text = tk.StringVar(value=data.text) self.font = tk.StringVar(value=data.font) self.font_size = tk.IntVar(value=data.font_size) self.text_color = data.text_color fill_color = data.fill_color if not fill_color: fill_color = "#CFCFFF" self.fill_color = fill_color self.border_color = data.border_color self.border_width = tk.IntVar(value=0) self.bold = tk.BooleanVar(value=data.bold) self.italic = tk.BooleanVar(value=data.italic) self.underline = tk.BooleanVar(value=data.underline) self.draw()
def __init__(self, app: "Application", shape: "Shape") -> None: if is_draw_shape(shape.shape_type): title = "Add Shape" else: title = "Add Text" super().__init__(app, title) self.canvas: "CanvasGraph" = app.manager.current() self.fill: Optional[ttk.Label] = None self.border: Optional[ttk.Label] = None self.shape: "Shape" = shape data = shape.shape_data self.shape_text: tk.StringVar = tk.StringVar(value=data.text) self.font: tk.StringVar = tk.StringVar(value=data.font) self.font_size: tk.IntVar = tk.IntVar(value=data.font_size) self.text_color: str = data.text_color fill_color = data.fill_color if not fill_color: fill_color = "#CFCFFF" self.fill_color: str = fill_color self.border_color: str = data.border_color self.border_width: tk.IntVar = tk.IntVar(value=0) self.bold: tk.BooleanVar = tk.BooleanVar(value=data.bold) self.italic: tk.BooleanVar = tk.BooleanVar(value=data.italic) self.underline: tk.BooleanVar = tk.BooleanVar(value=data.underline) self.draw()
def click_add(self): if is_draw_shape(self.shape.shape_type): self.add_shape() elif is_shape_text(self.shape.shape_type): self.add_text() self.destroy()