From c82453b9814a08bfc6134571a7631614e7a95d40 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Thu, 5 Dec 2019 11:15:51 -0800 Subject: [PATCH] load shapes --- coretk/coretk/coreclient.py | 103 +++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 1a7d06e3..273e3037 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -7,12 +7,12 @@ import os import time from core.api.grpc import client, core_pb2 -from coretk import appconfig, parsedata +from coretk import appconfig from coretk.dialogs.mobilityplayer import MobilityPlayer from coretk.dialogs.sessions import SessionsDialog from coretk.interface import InterfaceManager from coretk.nodeutils import NodeDraw, NodeUtils -from coretk.shape import Shape, ShapeData +from coretk.shape import ShapeData OBSERVERS = { "processes": "ps", @@ -282,47 +282,48 @@ class CoreClient: return self.state == core_pb2.SessionState.RUNTIME def parse_metadata(self, config): - for key, value in config.items(): - if "global_options" != key: - canvas_config = parsedata.parse(value) - print(canvas_config) - if canvas_config.get("type"): - config_type = canvas_config["type"] - if config_type == "rectangle" or config_type == "oval": - data = ShapeData( - False, - canvas_config["label"], - canvas_config["fontfamily"], - canvas_config["fontsize"], - canvas_config["labelcolor"], - canvas_config["color"], - canvas_config["border"], - canvas_config["width"], - ) - coords = tuple( - [float(x) for x in canvas_config["iconcoords"].split()] - ) - shape = Shape( - self.app, - self.app.canvas, - None, - None, - coords, - data, - config_type, - ) - self.app.canvas.shapes[shape.id] = shape - elif canvas_config["type"] == "text": - print("not implemented") - else: - if "wallpaper" in canvas_config: - logging.info("canvas metadata: %s", canvas_config) - wallpaper_style = canvas_config["wallpaper-style"] - self.app.canvas.scale_option.set(wallpaper_style) - wallpaper = canvas_config["wallpaper"] - wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)) - self.app.canvas.set_wallpaper(wallpaper) + # for key, value in config.items(): + # if "global_options" != key: + # canvas_config = parsedata.parse(value) + # print(canvas_config) + # if canvas_config.get("type"): + # config_type = canvas_config["type"] + # if config_type == "rectangle" or config_type == "oval": + # data = ShapeData( + # False, + # canvas_config["label"], + # canvas_config["fontfamily"], + # canvas_config["fontsize"], + # canvas_config["labelcolor"], + # canvas_config["color"], + # canvas_config["border"], + # canvas_config["width"], + # ) + # coords = tuple( + # [float(x) for x in canvas_config["iconcoords"].split()] + # ) + # shape = Shape( + # self.app, + # self.app.canvas, + # None, + # None, + # coords, + # data, + # config_type, + # ) + # self.app.canvas.shapes[shape.id] = shape + # elif canvas_config["type"] == "text": + # print("not implemented") + # else: + # if "wallpaper" in canvas_config: + # logging.info("canvas metadata: %s", canvas_config) + # wallpaper_style = canvas_config["wallpaper-style"] + # self.app.canvas.scale_option.set(wallpaper_style) + # wallpaper = canvas_config["wallpaper"] + # wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)) + # self.app.canvas.set_wallpaper(wallpaper) # canvas settings + print(config) canvas_config = config.get("canvas") if canvas_config: logging.info("canvas metadata: %s", canvas_config) @@ -332,6 +333,24 @@ class CoreClient: wallpaper = canvas_config["wallpaper"] wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)) self.app.canvas.set_wallpaper(wallpaper) + for key, annotation_config in config.items(): + if "annotation" in key: + annotation_config = json.loads(annotation_config) + print(annotation_config) + config_type = annotation_config["type"] + if config_type in ["rectangle", "oval"]: + coords = tuple(annotation_config["iconcoords"]) + data = ShapeData( + False, + annotation_config["label"], + annotation_config["fontfamily"], + annotation_config["fontsize"], + annotation_config["labelcolor"], + annotation_config["color"], + annotation_config["border"], + annotation_config["width"], + ) + print(data, coords) def create_new_session(self): """