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
|
@ -47,6 +47,7 @@ from core.gui.dialogs.mobilityplayer import MobilityPlayer
|
||||||
from core.gui.dialogs.sessions import SessionsDialog
|
from core.gui.dialogs.sessions import SessionsDialog
|
||||||
from core.gui.graph.edges import CanvasEdge
|
from core.gui.graph.edges import CanvasEdge
|
||||||
from core.gui.graph.node import CanvasNode
|
from core.gui.graph.node import CanvasNode
|
||||||
|
from core.gui.graph.shape import Shape
|
||||||
from core.gui.interface import InterfaceManager
|
from core.gui.interface import InterfaceManager
|
||||||
from core.gui.nodeutils import NodeDraw, NodeUtils
|
from core.gui.nodeutils import NodeDraw, NodeUtils
|
||||||
|
|
||||||
|
@ -354,33 +355,12 @@ class CoreClient:
|
||||||
canvas.set_wallpaper(wallpaper)
|
canvas.set_wallpaper(wallpaper)
|
||||||
|
|
||||||
# load saved shapes
|
# load saved shapes
|
||||||
# shapes_config = config.get("shapes")
|
shapes_config = config.get("shapes")
|
||||||
# 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.debug("loading shape: %s", shape_config)
|
logging.debug("loading shape: %s", shape_config)
|
||||||
# shape_type = shape_config["type"]
|
Shape.from_metadata(self.app, shape_config)
|
||||||
# try:
|
|
||||||
# shape_type = ShapeType(shape_type)
|
|
||||||
# coords = shape_config["iconcoords"]
|
|
||||||
# data = AnnotationData(
|
|
||||||
# shape_config["label"],
|
|
||||||
# shape_config["fontfamily"],
|
|
||||||
# shape_config["fontsize"],
|
|
||||||
# shape_config["labelcolor"],
|
|
||||||
# shape_config["color"],
|
|
||||||
# shape_config["border"],
|
|
||||||
# shape_config["width"],
|
|
||||||
# shape_config["bold"],
|
|
||||||
# shape_config["italic"],
|
|
||||||
# shape_config["underline"],
|
|
||||||
# )
|
|
||||||
# shape = Shape(
|
|
||||||
# self.app, self.app.canvas, shape_type, *coords, data=data
|
|
||||||
# )
|
|
||||||
# canvas.shapes[shape.id] = shape
|
|
||||||
# except ValueError:
|
|
||||||
# logging.exception("unknown shape: %s", shape_type)
|
|
||||||
|
|
||||||
# load edges config
|
# load edges config
|
||||||
edges_config = config.get("edges")
|
edges_config = config.get("edges")
|
||||||
|
@ -559,7 +539,7 @@ class CoreClient:
|
||||||
def set_metadata(self) -> None:
|
def set_metadata(self) -> None:
|
||||||
# create canvas data
|
# create canvas data
|
||||||
canvases = []
|
canvases = []
|
||||||
for canvas in self.app.manager.canvases.values():
|
for canvas in self.app.manager.all():
|
||||||
wallpaper_path = None
|
wallpaper_path = None
|
||||||
if canvas.wallpaper_file:
|
if canvas.wallpaper_file:
|
||||||
wallpaper = Path(canvas.wallpaper_file)
|
wallpaper = Path(canvas.wallpaper_file)
|
||||||
|
@ -583,9 +563,9 @@ class CoreClient:
|
||||||
|
|
||||||
# create shapes data
|
# create shapes data
|
||||||
shapes = []
|
shapes = []
|
||||||
# TODO: handle shapes being on multiple canvases
|
for canvas in self.app.manager.all():
|
||||||
# for shape in self.app.canvas.shapes.values():
|
for shape in canvas.shapes.values():
|
||||||
# shapes.append(shape.metadata())
|
shapes.append(shape.metadata())
|
||||||
shapes = json.dumps(shapes)
|
shapes = json.dumps(shapes)
|
||||||
|
|
||||||
# create edges config
|
# create edges config
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ShapeDialog(Dialog):
|
||||||
else:
|
else:
|
||||||
title = "Add Text"
|
title = "Add Text"
|
||||||
super().__init__(app, title)
|
super().__init__(app, title)
|
||||||
self.canvas: "CanvasGraph" = app.canvas
|
self.canvas: "CanvasGraph" = app.manager.current()
|
||||||
self.fill: Optional[ttk.Label] = None
|
self.fill: Optional[ttk.Label] = None
|
||||||
self.border: Optional[ttk.Label] = None
|
self.border: Optional[ttk.Label] = None
|
||||||
self.shape: "Shape" = shape
|
self.shape: "Shape" = shape
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ShowVar(BooleanVar):
|
||||||
return tk.NORMAL if self.get() else tk.HIDDEN
|
return tk.NORMAL if self.get() else tk.HIDDEN
|
||||||
|
|
||||||
def click_handler(self) -> None:
|
def click_handler(self) -> None:
|
||||||
for canvas in self.manager.canvases.values():
|
for canvas in self.manager.all():
|
||||||
canvas.itemconfigure(self.tag, state=self.state())
|
canvas.itemconfigure(self.tag, state=self.state())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import logging
|
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.dialogs.shapemod import ShapeDialog
|
||||||
from core.gui.graph import tags
|
from core.gui.graph import tags
|
||||||
|
@ -69,6 +69,31 @@ class Shape:
|
||||||
self.shape_data = data
|
self.shape_data = data
|
||||||
self.draw()
|
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:
|
def draw(self) -> None:
|
||||||
if self.created:
|
if self.created:
|
||||||
dash = None
|
dash = None
|
||||||
|
@ -184,6 +209,7 @@ class Shape:
|
||||||
x1, y1 = self.canvas.get_actual_coords(x1, y1)
|
x1, y1 = self.canvas.get_actual_coords(x1, y1)
|
||||||
coords = (x1, y1)
|
coords = (x1, y1)
|
||||||
return {
|
return {
|
||||||
|
"canvas": self.canvas.id,
|
||||||
"type": self.shape_type.value,
|
"type": self.shape_type.value,
|
||||||
"iconcoords": coords,
|
"iconcoords": coords,
|
||||||
"label": self.shape_data.text,
|
"label": self.shape_data.text,
|
||||||
|
|
Loading…
Add table
Reference in a new issue