diff --git a/coretk/coretk/dialogs/marker.py b/coretk/coretk/dialogs/marker.py new file mode 100644 index 00000000..8a476548 --- /dev/null +++ b/coretk/coretk/dialogs/marker.py @@ -0,0 +1,53 @@ +""" +marker dialog +""" + +from tkinter import ttk + +from coretk.dialogs.colorpicker import ColorPicker +from coretk.dialogs.dialog import Dialog + +MARKER_THICKNESS = [3, 5, 8, 10] + + +class Marker(Dialog): + def __init__(self, master, app, initcolor="#000000"): + super().__init__(master, app, "marker tool", modal=False) + self.app = app + self.color = initcolor + self.radius = MARKER_THICKNESS[0] + self.draw() + + def draw(self): + button = ttk.Button(self.top, text="clear", command=self.clear_marker) + button.grid(row=0, column=0) + + frame = ttk.Frame(self.top) + frame.grid(row=1, column=0) + + button = ttk.Button(frame, text="radius 1") + button.grid(row=0, column=0) + button = ttk.Button(frame, text="radius 2") + button.grid(row=0, column=1) + button = ttk.Button(frame, text="radius 3") + button.grid(row=1, column=0) + button = ttk.Button(frame, text="radius 4") + button.grid(row=1, column=1) + + label = ttk.Label(self.top, background=self.color) + label.grid(row=2, column=0, sticky="nsew") + label.bind("", self.change_color) + + # button = ttk.Button(self.top, text="color", command=self.change_color) + # button.grid(row=2, column=0) + + def clear_marker(self): + canvas = self.app.canvas + for i in canvas.find_withtag("marker"): + canvas.delete(i) + + def change_color(self, event): + color_picker = ColorPicker(self, self.app, self.color) + color = color_picker.askcolor() + event.widget.configure(background=color) + self.color = color diff --git a/coretk/coretk/graph/graph.py b/coretk/coretk/graph/graph.py index 77cc2264..e0878f20 100644 --- a/coretk/coretk/graph/graph.py +++ b/coretk/coretk/graph/graph.py @@ -12,7 +12,7 @@ from coretk.graph.enums import GraphMode, ScaleOption from coretk.graph.linkinfo import LinkInfo, Throughput from coretk.graph.node import CanvasNode from coretk.graph.shape import Shape -from coretk.graph.shapeutils import ShapeType, is_draw_shape +from coretk.graph.shapeutils import ShapeType, is_draw_shape, is_marker from coretk.images import Images from coretk.nodeutils import NodeUtils @@ -45,6 +45,7 @@ class CanvasGraph(tk.Canvas): self.ratio = 1.0 self.offset = (0, 0) self.cursor = (0, 0) + self.marker_tool = None # background related self.wallpaper_id = None @@ -499,10 +500,22 @@ class CanvasGraph(tk.Canvas): self.drawing_edge = CanvasEdge(x, y, x, y, selected, self) if self.mode == GraphMode.ANNOTATION and 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 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", + ) + else: + 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: @@ -573,6 +586,18 @@ class CanvasGraph(tk.Canvas): 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): + marker_tool = self.app.toolbar.marker_tool + r = marker_tool.radius + self.create_oval( + x - r, + y - r, + x + r, + y + r, + fill=self.app.toolbar.marker_tool.color, + outline="", + tags="marker", + ) if self.mode == GraphMode.EDGE: return diff --git a/coretk/coretk/graph/shapeutils.py b/coretk/coretk/graph/shapeutils.py index a566a713..0e2cc29c 100644 --- a/coretk/coretk/graph/shapeutils.py +++ b/coretk/coretk/graph/shapeutils.py @@ -17,3 +17,7 @@ def is_draw_shape(shape_type): def is_shape_text(shape_type): return shape_type == ShapeType.TEXT + + +def is_marker(shape_type): + return shape_type == ShapeType.MARKER diff --git a/coretk/coretk/toolbar.py b/coretk/coretk/toolbar.py index 323c5d67..96b317c2 100644 --- a/coretk/coretk/toolbar.py +++ b/coretk/coretk/toolbar.py @@ -6,9 +6,10 @@ from tkinter import ttk from tkinter.font import Font from coretk.dialogs.customnodes import CustomNodesDialog +from coretk.dialogs.marker import Marker from coretk.graph import tags from coretk.graph.enums import GraphMode -from coretk.graph.shapeutils import ShapeType +from coretk.graph.shapeutils import ShapeType, is_marker from coretk.images import ImageEnum, Images from coretk.nodeutils import NodeUtils from coretk.themes import Styles @@ -57,6 +58,9 @@ class Toolbar(ttk.Frame): self.network_picker = None self.annotation_picker = None + # dialog + self.marker_tool = None + # draw components self.draw() @@ -401,6 +405,9 @@ class Toolbar(ttk.Frame): self.annotation_button.image = image self.app.canvas.mode = GraphMode.ANNOTATION self.app.canvas.annotation_type = shape_type + if is_marker(shape_type): + self.marker_tool = Marker(self.master, self.app) + self.marker_tool.show() def click_run_button(self): logging.debug("Click on RUN button") @@ -410,6 +417,8 @@ class Toolbar(ttk.Frame): def click_marker_button(self): logging.debug("Click on marker button") + dialog = Marker(self.master, self.app) + dialog.show() def click_two_node_button(self): logging.debug("Click TWONODE button")