updated annotation text to be selectable/moveable, save annotation text with other shapes and reload from xml
This commit is contained in:
parent
2824ae09b0
commit
71df2a3b7f
5 changed files with 45 additions and 53 deletions
|
@ -322,11 +322,11 @@ class CoreClient:
|
||||||
if shapes_config:
|
if shapes_config:
|
||||||
shapes_config = json.loads(shapes_config)
|
shapes_config = json.loads(shapes_config)
|
||||||
for shape_config in 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"]
|
shape_type = shape_config["type"]
|
||||||
try:
|
try:
|
||||||
shape_type = ShapeType(shape_type)
|
shape_type = ShapeType(shape_type)
|
||||||
x1, y1, x2, y2 = shape_config["iconcoords"]
|
coords = shape_config["iconcoords"]
|
||||||
data = AnnotationData(
|
data = AnnotationData(
|
||||||
shape_config["label"],
|
shape_config["label"],
|
||||||
shape_config["fontfamily"],
|
shape_config["fontfamily"],
|
||||||
|
@ -337,11 +337,11 @@ class CoreClient:
|
||||||
shape_config["width"],
|
shape_config["width"],
|
||||||
)
|
)
|
||||||
shape = Shape(
|
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
|
self.app.canvas.shapes[shape.id] = shape
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging.debug("unknown shape: %s", shape_type)
|
logging.exception("unknown shape: %s", shape_type)
|
||||||
|
|
||||||
for tag in LIFT_ORDER:
|
for tag in LIFT_ORDER:
|
||||||
self.app.canvas.tag_raise(tag)
|
self.app.canvas.tag_raise(tag)
|
||||||
|
|
|
@ -15,12 +15,10 @@ class ShapeDialog(Dialog):
|
||||||
def __init__(self, master, app, shape):
|
def __init__(self, master, app, shape):
|
||||||
if is_draw_shape(shape.shape_type):
|
if is_draw_shape(shape.shape_type):
|
||||||
title = "Add Shape"
|
title = "Add Shape"
|
||||||
self.id = shape.id
|
|
||||||
else:
|
else:
|
||||||
title = "Add Text"
|
title = "Add Text"
|
||||||
self.id = None
|
|
||||||
self.canvas = app.canvas
|
|
||||||
super().__init__(master, app, title, modal=True)
|
super().__init__(master, app, title, modal=True)
|
||||||
|
self.canvas = app.canvas
|
||||||
self.fill = None
|
self.fill = None
|
||||||
self.border = None
|
self.border = None
|
||||||
self.shape = shape
|
self.shape = shape
|
||||||
|
@ -146,12 +144,8 @@ class ShapeDialog(Dialog):
|
||||||
self.border.config(background=color[1], text=color[1])
|
self.border.config(background=color[1], text=color[1])
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
if (
|
self.shape.delete()
|
||||||
is_draw_shape(self.shape.shape_type)
|
self.canvas.shapes.pop(self.shape.id)
|
||||||
and not self.canvas.shapes[self.id].created
|
|
||||||
):
|
|
||||||
self.canvas.delete(self.id)
|
|
||||||
self.canvas.shapes.pop(self.id)
|
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
def click_add(self):
|
def click_add(self):
|
||||||
|
@ -209,29 +203,15 @@ class ShapeDialog(Dialog):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
text = self.shape_text.get()
|
text = self.shape_text.get()
|
||||||
x = self.shape.x1
|
|
||||||
y = self.shape.y1
|
|
||||||
text_font = self.make_font()
|
text_font = self.make_font()
|
||||||
if self.shape.text_id is None:
|
self.canvas.itemconfig(
|
||||||
tid = self.canvas.create_text(
|
self.shape.id, text=text, fill=self.text_color, font=text_font
|
||||||
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.save_text()
|
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):
|
def add_shape(self):
|
||||||
self.canvas.itemconfig(
|
self.canvas.itemconfig(
|
||||||
self.id,
|
self.shape.id,
|
||||||
fill=self.fill_color,
|
fill=self.fill_color,
|
||||||
dash="",
|
dash="",
|
||||||
outline=self.border_color,
|
outline=self.border_color,
|
||||||
|
@ -239,7 +219,7 @@ class ShapeDialog(Dialog):
|
||||||
)
|
)
|
||||||
shape_text = self.shape_text.get()
|
shape_text = self.shape_text.get()
|
||||||
size = int(self.font_size.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
|
_y = y0 + 1.5 * size
|
||||||
_x = (x0 + x1) / 2
|
_x = (x0 + x1) / 2
|
||||||
text_font = self.make_font()
|
text_font = self.make_font()
|
||||||
|
|
|
@ -10,7 +10,7 @@ from coretk.graph.enums import GraphMode, ScaleOption
|
||||||
from coretk.graph.linkinfo import LinkInfo, Throughput
|
from coretk.graph.linkinfo import LinkInfo, Throughput
|
||||||
from coretk.graph.node import CanvasNode
|
from coretk.graph.node import CanvasNode
|
||||||
from coretk.graph.shape import Shape
|
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.images import Images
|
||||||
from coretk.nodeutils import NodeUtils
|
from coretk.nodeutils import NodeUtils
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
self.edges = {}
|
self.edges = {}
|
||||||
self.shapes = {}
|
self.shapes = {}
|
||||||
self.texts = {}
|
|
||||||
self.wireless_edges = {}
|
self.wireless_edges = {}
|
||||||
self.drawing_edge = None
|
self.drawing_edge = None
|
||||||
self.grid = None
|
self.grid = None
|
||||||
|
@ -244,14 +243,12 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.context = None
|
self.context = None
|
||||||
else:
|
else:
|
||||||
if self.mode == GraphMode.ANNOTATION:
|
if self.mode == GraphMode.ANNOTATION:
|
||||||
if is_draw_shape(self.annotation_type):
|
|
||||||
self.focus_set()
|
self.focus_set()
|
||||||
x, y = self.canvas_xy(event)
|
x, y = self.canvas_xy(event)
|
||||||
if self.shape_drawing:
|
if self.shape_drawing:
|
||||||
self.shapes[self.selected].shape_complete(x, y)
|
shape = self.shapes[self.selected]
|
||||||
|
shape.shape_complete(x, y)
|
||||||
self.shape_drawing = False
|
self.shape_drawing = False
|
||||||
elif is_shape_text(self.annotation_type):
|
|
||||||
self.text.shape_complete(self.text.cursor_x, self.text.cursor_y)
|
|
||||||
else:
|
else:
|
||||||
self.focus_set()
|
self.focus_set()
|
||||||
self.selected = self.get_selected(event)
|
self.selected = self.get_selected(event)
|
||||||
|
@ -404,13 +401,10 @@ class CanvasGraph(tk.Canvas):
|
||||||
|
|
||||||
if self.mode == GraphMode.ANNOTATION and selected is None:
|
if self.mode == GraphMode.ANNOTATION and selected is None:
|
||||||
x, y = self.canvas_xy(event)
|
x, y = self.canvas_xy(event)
|
||||||
if is_draw_shape(self.annotation_type):
|
|
||||||
shape = Shape(self.app, self, self.annotation_type, x, y)
|
shape = Shape(self.app, self, self.annotation_type, x, y)
|
||||||
self.selected = shape.id
|
self.selected = shape.id
|
||||||
self.shapes[shape.id] = shape
|
|
||||||
self.shape_drawing = True
|
self.shape_drawing = True
|
||||||
elif is_shape_text(self.annotation_type):
|
self.shapes[shape.id] = shape
|
||||||
self.text = Shape(self.app, self, self.annotation_type, x, y)
|
|
||||||
|
|
||||||
if self.mode == GraphMode.SELECT:
|
if self.mode == GraphMode.SELECT:
|
||||||
if selected is not None:
|
if selected is not None:
|
||||||
|
@ -449,7 +443,8 @@ class CanvasGraph(tk.Canvas):
|
||||||
if self.mode == GraphMode.ANNOTATION:
|
if self.mode == GraphMode.ANNOTATION:
|
||||||
if is_draw_shape(self.annotation_type) and self.shape_drawing:
|
if is_draw_shape(self.annotation_type) and self.shape_drawing:
|
||||||
x, y = self.canvas_xy(event)
|
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 (
|
if (
|
||||||
self.mode == GraphMode.SELECT
|
self.mode == GraphMode.SELECT
|
||||||
and self.selected is not None
|
and self.selected is not None
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from tkinter.font import Font
|
from tkinter.font import Font
|
||||||
|
|
||||||
from coretk.dialogs.shapemod import ShapeDialog
|
from coretk.dialogs.shapemod import ShapeDialog
|
||||||
|
@ -76,6 +77,7 @@ class Shape:
|
||||||
outline=self.shape_data.border_color,
|
outline=self.shape_data.border_color,
|
||||||
width=self.shape_data.border_width,
|
width=self.shape_data.border_width,
|
||||||
)
|
)
|
||||||
|
self.draw_shape_text()
|
||||||
elif self.shape_type == ShapeType.RECTANGLE:
|
elif self.shape_type == ShapeType.RECTANGLE:
|
||||||
self.id = self.canvas.create_rectangle(
|
self.id = self.canvas.create_rectangle(
|
||||||
self.x1,
|
self.x1,
|
||||||
|
@ -88,7 +90,22 @@ class Shape:
|
||||||
outline=self.shape_data.border_color,
|
outline=self.shape_data.border_color,
|
||||||
width=self.shape_data.border_width,
|
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:
|
if self.shape_data.text:
|
||||||
x = (self.x1 + self.x2) / 2
|
x = (self.x1 + self.x2) / 2
|
||||||
y = self.y1 + 1.5 * self.shape_data.font_size
|
y = self.y1 + 1.5 * self.shape_data.font_size
|
||||||
|
|
|
@ -123,9 +123,9 @@ class NodeElement:
|
||||||
if x is not None and y is not None:
|
if x is not None and y is not None:
|
||||||
lat, lon, alt = self.session.location.getgeo(x, y, z)
|
lat, lon, alt = self.session.location.getgeo(x, y, z)
|
||||||
position = etree.SubElement(self.element, "position")
|
position = etree.SubElement(self.element, "position")
|
||||||
add_attribute(position, "x", x)
|
add_attribute(position, "x", int(x))
|
||||||
add_attribute(position, "y", y)
|
add_attribute(position, "y", int(y))
|
||||||
add_attribute(position, "z", z)
|
add_attribute(position, "z", int(z))
|
||||||
add_attribute(position, "lat", lat)
|
add_attribute(position, "lat", lat)
|
||||||
add_attribute(position, "lon", lon)
|
add_attribute(position, "lon", lon)
|
||||||
add_attribute(position, "alt", alt)
|
add_attribute(position, "alt", alt)
|
||||||
|
|
Loading…
Add table
Reference in a new issue