work on marker tool

This commit is contained in:
Huy Pham 2019-12-18 09:49:45 -08:00
parent 0b0ab08030
commit da26e34765
4 changed files with 97 additions and 6 deletions

View file

@ -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("<Button-1>", 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

View file

@ -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

View file

@ -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

View file

@ -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")