Esempio n. 1
0
    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)
Esempio n. 2
0
    def click_press(self, event: tk.Event):
        """
        Start drawing an edge if mouse click is on a node
        """
        x, y = self.canvas_xy(event)
        if not self.inside_canvas(x, y):
            return

        self.cursor = x, y
        selected = self.get_selected(event)
        logging.debug("click press(%s): %s", self.cursor, selected)
        x_check = self.cursor[0] - self.offset[0]
        y_check = self.cursor[1] - self.offset[1]
        logging.debug("click press offset(%s, %s)", x_check, y_check)
        is_node = selected in self.nodes
        if self.mode == GraphMode.EDGE and is_node:
            pos = self.coords(selected)
            self.drawing_edge = CanvasEdge(self, selected, pos, pos)

        if self.mode == GraphMode.ANNOTATION:
            if 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=(tags.MARKER, tags.ANNOTATION),
                    state=self.show_annotations.state(),
                )
                return
            if selected is None:
                shape = Shape(self.app, self, self.annotation_type, x, y)
                self.selected = shape.id
                self.shape_drawing = True
                self.shapes[shape.id] = shape

        if selected is not None:
            if selected not in self.selection:
                if selected in self.shapes:
                    shape = self.shapes[selected]
                    self.select_object(shape.id)
                    self.selected = selected
                elif selected in self.nodes:
                    node = self.nodes[selected]
                    self.select_object(node.id)
                    self.selected = selected
                    logging.debug(
                        "selected node(%s), coords: (%s, %s)",
                        node.core_node.name,
                        node.core_node.position.x,
                        node.core_node.position.y,
                    )
        else:
            if self.mode == GraphMode.SELECT:
                shape = Shape(self.app, self, ShapeType.RECTANGLE, x, y)
                self.select_box = shape
            self.clear_selection()
Esempio n. 3
0
    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)
Esempio n. 4
0
 def update_annotation(self, shape_type: ShapeType, image_enum: ImageEnum,
                       image: PhotoImage) -> None:
     logging.debug("clicked annotation")
     self.annotation_button.configure(image=image)
     self.annotation_button.image = image
     self.app.canvas.annotation_type = shape_type
     self.current_annotation = shape_type
     self.annotation_enum = image_enum
     if is_marker(shape_type):
         self.show_marker()
     else:
         self.hide_marker()
Esempio n. 5
0
 def update_annotation(self, image, shape_type):
     logging.info("clicked annotation: ")
     self.hide_pickers()
     self.annotation_button.configure(image=image)
     self.annotation_button.image = image
     self.app.canvas.mode = GraphMode.ANNOTATION
     self.app.canvas.annotation_type = shape_type
     if is_marker(shape_type):
         if self.marker_tool:
             self.marker_tool.destroy()
         self.marker_tool = MarkerDialog(self.master, self.app)
         self.marker_tool.show()
Esempio n. 6
0
 def update_annotation(self, image: "ImageTk.PhotoImage",
                       shape_type: ShapeType, image_enum):
     logging.debug("clicked annotation: ")
     self.hide_pickers()
     self.annotation_button.configure(image=image)
     self.annotation_button.image = image
     self.app.canvas.mode = GraphMode.ANNOTATION
     self.app.canvas.annotation_type = shape_type
     self.annotation_enum = image_enum
     if is_marker(shape_type):
         if self.marker_tool:
             self.marker_tool.destroy()
         self.marker_tool = MarkerDialog(self.app, self.app)
         self.marker_tool.show()
Esempio n. 7
0
 def draw_annotation_picker(self) -> None:
     """
     Draw the options for marker button.
     """
     self.design_frame.select_radio(self.annotation_button)
     self.app.canvas.mode = GraphMode.ANNOTATION
     self.app.canvas.annotation_type = self.current_annotation
     if is_marker(self.current_annotation):
         self.show_marker()
     self.picker = PickerFrame(self.app, self.annotation_button)
     nodes = [
         (ImageEnum.MARKER, ShapeType.MARKER),
         (ImageEnum.OVAL, ShapeType.OVAL),
         (ImageEnum.RECTANGLE, ShapeType.RECTANGLE),
         (ImageEnum.TEXT, ShapeType.TEXT),
     ]
     for image_enum, shape_type in nodes:
         label = shape_type.value
         func = partial(self.update_annotation, shape_type, image_enum)
         self.picker.create_button(label, func, image_enum)
     self.picker.show()