pygui: added multi canvas support to shapes, updated how shape metadata is saved and loaded to align
This commit is contained in:
parent
4a8f8557a6
commit
367a2096fa
4 changed files with 41 additions and 35 deletions
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
||||
|
||||
from core.gui.dialogs.shapemod import ShapeDialog
|
||||
from core.gui.graph import tags
|
||||
|
@ -69,6 +69,31 @@ class Shape:
|
|||
self.shape_data = data
|
||||
self.draw()
|
||||
|
||||
@classmethod
|
||||
def from_metadata(cls, app: "Application", config: Dict[str, Any]) -> None:
|
||||
shape_type = config["type"]
|
||||
try:
|
||||
shape_type = ShapeType(shape_type)
|
||||
coords = config["iconcoords"]
|
||||
data = AnnotationData(
|
||||
config["label"],
|
||||
config["fontfamily"],
|
||||
config["fontsize"],
|
||||
config["labelcolor"],
|
||||
config["color"],
|
||||
config["border"],
|
||||
config["width"],
|
||||
config["bold"],
|
||||
config["italic"],
|
||||
config["underline"],
|
||||
)
|
||||
canvas_id = config.get("canvas", 1)
|
||||
canvas = app.manager.get(canvas_id)
|
||||
shape = Shape(app, canvas, shape_type, *coords, data=data)
|
||||
canvas.shapes[shape.id] = shape
|
||||
except ValueError:
|
||||
logging.exception("unknown shape: %s", shape_type)
|
||||
|
||||
def draw(self) -> None:
|
||||
if self.created:
|
||||
dash = None
|
||||
|
@ -184,6 +209,7 @@ class Shape:
|
|||
x1, y1 = self.canvas.get_actual_coords(x1, y1)
|
||||
coords = (x1, y1)
|
||||
return {
|
||||
"canvas": self.canvas.id,
|
||||
"type": self.shape_type.value,
|
||||
"iconcoords": coords,
|
||||
"label": self.shape_data.text,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue