updated annotation text to be selectable/moveable, save annotation text with other shapes and reload from xml

This commit is contained in:
Blake Harnden 2019-12-06 22:10:27 -08:00
parent 2824ae09b0
commit 71df2a3b7f
5 changed files with 45 additions and 53 deletions

View file

@ -322,11 +322,11 @@ class CoreClient:
if shapes_config:
shapes_config = json.loads(shapes_config)
for shape_config in shapes_config:
logging.info("loading shape: %s", shapes_config)
logging.info("loading shape: %s", shape_config)
shape_type = shape_config["type"]
try:
shape_type = ShapeType(shape_type)
x1, y1, x2, y2 = shape_config["iconcoords"]
coords = shape_config["iconcoords"]
data = AnnotationData(
shape_config["label"],
shape_config["fontfamily"],
@ -337,11 +337,11 @@ class CoreClient:
shape_config["width"],
)
shape = Shape(
self.app, self.app.canvas, shape_type, x1, y1, x2, y2, data
self.app, self.app.canvas, shape_type, *coords, data=data
)
self.app.canvas.shapes[shape.id] = shape
except ValueError:
logging.debug("unknown shape: %s", shape_type)
logging.exception("unknown shape: %s", shape_type)
for tag in LIFT_ORDER:
self.app.canvas.tag_raise(tag)

View file

@ -15,12 +15,10 @@ class ShapeDialog(Dialog):
def __init__(self, master, app, shape):
if is_draw_shape(shape.shape_type):
title = "Add Shape"
self.id = shape.id
else:
title = "Add Text"
self.id = None
self.canvas = app.canvas
super().__init__(master, app, title, modal=True)
self.canvas = app.canvas
self.fill = None
self.border = None
self.shape = shape
@ -146,12 +144,8 @@ class ShapeDialog(Dialog):
self.border.config(background=color[1], text=color[1])
def cancel(self):
if (
is_draw_shape(self.shape.shape_type)
and not self.canvas.shapes[self.id].created
):
self.canvas.delete(self.id)
self.canvas.shapes.pop(self.id)
self.shape.delete()
self.canvas.shapes.pop(self.shape.id)
self.destroy()
def click_add(self):
@ -209,29 +203,15 @@ class ShapeDialog(Dialog):
:return: nothing
"""
text = self.shape_text.get()
x = self.shape.x1
y = self.shape.y1
text_font = self.make_font()
if self.shape.text_id is None:
tid = self.canvas.create_text(
x, y, text=text, fill=self.text_color, font=text_font, tags="text"
)
self.shape.text_id = tid
self.id = tid
self.shape.id = tid
self.canvas.texts[tid] = self.shape
self.shape.created = True
self.canvas.itemconfig(
self.shape.id, text=text, fill=self.text_color, font=text_font
)
self.save_text()
print(self.canvas.texts)
# self.canvas.shapes[self.id].created = True
# else:
# self.canvas.itemconfig(
# self.shape.text_id, text=text, fill=self.text_color, font=f
# )
def add_shape(self):
self.canvas.itemconfig(
self.id,
self.shape.id,
fill=self.fill_color,
dash="",
outline=self.border_color,
@ -239,7 +219,7 @@ class ShapeDialog(Dialog):
)
shape_text = self.shape_text.get()
size = int(self.font_size.get())
x0, y0, x1, y1 = self.canvas.bbox(self.id)
x0, y0, x1, y1 = self.canvas.bbox(self.shape.id)
_y = y0 + 1.5 * size
_x = (x0 + x1) / 2
text_font = self.make_font()

View file

@ -10,7 +10,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 is_draw_shape, is_shape_text
from coretk.graph.shapeutils import is_draw_shape
from coretk.images import Images
from coretk.nodeutils import NodeUtils
@ -45,7 +45,6 @@ class CanvasGraph(tk.Canvas):
self.nodes = {}
self.edges = {}
self.shapes = {}
self.texts = {}
self.wireless_edges = {}
self.drawing_edge = None
self.grid = None
@ -244,14 +243,12 @@ class CanvasGraph(tk.Canvas):
self.context = None
else:
if self.mode == GraphMode.ANNOTATION:
if is_draw_shape(self.annotation_type):
self.focus_set()
x, y = self.canvas_xy(event)
if self.shape_drawing:
self.shapes[self.selected].shape_complete(x, y)
self.shape_drawing = False
elif is_shape_text(self.annotation_type):
self.text.shape_complete(self.text.cursor_x, self.text.cursor_y)
self.focus_set()
x, y = self.canvas_xy(event)
if self.shape_drawing:
shape = self.shapes[self.selected]
shape.shape_complete(x, y)
self.shape_drawing = False
else:
self.focus_set()
self.selected = self.get_selected(event)
@ -404,13 +401,10 @@ class CanvasGraph(tk.Canvas):
if self.mode == GraphMode.ANNOTATION and selected is None:
x, y = self.canvas_xy(event)
if is_draw_shape(self.annotation_type):
shape = Shape(self.app, self, self.annotation_type, x, y)
self.selected = shape.id
self.shapes[shape.id] = shape
self.shape_drawing = True
elif is_shape_text(self.annotation_type):
self.text = Shape(self.app, self, self.annotation_type, x, y)
shape = Shape(self.app, self, self.annotation_type, x, y)
self.selected = shape.id
self.shape_drawing = True
self.shapes[shape.id] = shape
if self.mode == GraphMode.SELECT:
if selected is not None:
@ -449,7 +443,8 @@ class CanvasGraph(tk.Canvas):
if self.mode == GraphMode.ANNOTATION:
if is_draw_shape(self.annotation_type) and self.shape_drawing:
x, y = self.canvas_xy(event)
self.shapes[self.selected].shape_motion(x, y)
shape = self.shapes[self.selected]
shape.shape_motion(x, y)
if (
self.mode == GraphMode.SELECT
and self.selected is not None

View file

@ -1,3 +1,4 @@
import logging
from tkinter.font import Font
from coretk.dialogs.shapemod import ShapeDialog
@ -76,6 +77,7 @@ class Shape:
outline=self.shape_data.border_color,
width=self.shape_data.border_width,
)
self.draw_shape_text()
elif self.shape_type == ShapeType.RECTANGLE:
self.id = self.canvas.create_rectangle(
self.x1,
@ -88,7 +90,22 @@ class Shape:
outline=self.shape_data.border_color,
width=self.shape_data.border_width,
)
self.draw_shape_text()
elif self.shape_type == ShapeType.TEXT:
font = Font(family=self.shape_data.font, size=self.shape_data.font_size)
self.id = self.canvas.create_text(
self.x1,
self.y1,
tags="shapetext",
text=self.shape_data.text,
fill=self.shape_data.text_color,
font=font,
)
else:
logging.error("unknown shape type: %s", self.shape_type)
self.created = True
def draw_shape_text(self):
if self.shape_data.text:
x = (self.x1 + self.x2) / 2
y = self.y1 + 1.5 * self.shape_data.font_size

View file

@ -123,9 +123,9 @@ class NodeElement:
if x is not None and y is not None:
lat, lon, alt = self.session.location.getgeo(x, y, z)
position = etree.SubElement(self.element, "position")
add_attribute(position, "x", x)
add_attribute(position, "y", y)
add_attribute(position, "z", z)
add_attribute(position, "x", int(x))
add_attribute(position, "y", int(y))
add_attribute(position, "z", int(z))
add_attribute(position, "lat", lat)
add_attribute(position, "lon", lon)
add_attribute(position, "alt", alt)