load shapes

This commit is contained in:
Huy Pham 2019-12-05 11:15:51 -08:00
parent 8c30ad6af5
commit c82453b981

View file

@ -7,12 +7,12 @@ import os
import time import time
from core.api.grpc import client, core_pb2 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.mobilityplayer import MobilityPlayer
from coretk.dialogs.sessions import SessionsDialog from coretk.dialogs.sessions import SessionsDialog
from coretk.interface import InterfaceManager from coretk.interface import InterfaceManager
from coretk.nodeutils import NodeDraw, NodeUtils from coretk.nodeutils import NodeDraw, NodeUtils
from coretk.shape import Shape, ShapeData from coretk.shape import ShapeData
OBSERVERS = { OBSERVERS = {
"processes": "ps", "processes": "ps",
@ -282,47 +282,48 @@ class CoreClient:
return self.state == core_pb2.SessionState.RUNTIME return self.state == core_pb2.SessionState.RUNTIME
def parse_metadata(self, config): def parse_metadata(self, config):
for key, value in config.items(): # for key, value in config.items():
if "global_options" != key: # if "global_options" != key:
canvas_config = parsedata.parse(value) # canvas_config = parsedata.parse(value)
print(canvas_config) # print(canvas_config)
if canvas_config.get("type"): # if canvas_config.get("type"):
config_type = canvas_config["type"] # config_type = canvas_config["type"]
if config_type == "rectangle" or config_type == "oval": # if config_type == "rectangle" or config_type == "oval":
data = ShapeData( # data = ShapeData(
False, # False,
canvas_config["label"], # canvas_config["label"],
canvas_config["fontfamily"], # canvas_config["fontfamily"],
canvas_config["fontsize"], # canvas_config["fontsize"],
canvas_config["labelcolor"], # canvas_config["labelcolor"],
canvas_config["color"], # canvas_config["color"],
canvas_config["border"], # canvas_config["border"],
canvas_config["width"], # canvas_config["width"],
) # )
coords = tuple( # coords = tuple(
[float(x) for x in canvas_config["iconcoords"].split()] # [float(x) for x in canvas_config["iconcoords"].split()]
) # )
shape = Shape( # shape = Shape(
self.app, # self.app,
self.app.canvas, # self.app.canvas,
None, # None,
None, # None,
coords, # coords,
data, # data,
config_type, # config_type,
) # )
self.app.canvas.shapes[shape.id] = shape # self.app.canvas.shapes[shape.id] = shape
elif canvas_config["type"] == "text": # elif canvas_config["type"] == "text":
print("not implemented") # print("not implemented")
else: # else:
if "wallpaper" in canvas_config: # if "wallpaper" in canvas_config:
logging.info("canvas metadata: %s", canvas_config) # logging.info("canvas metadata: %s", canvas_config)
wallpaper_style = canvas_config["wallpaper-style"] # wallpaper_style = canvas_config["wallpaper-style"]
self.app.canvas.scale_option.set(wallpaper_style) # self.app.canvas.scale_option.set(wallpaper_style)
wallpaper = canvas_config["wallpaper"] # wallpaper = canvas_config["wallpaper"]
wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)) # wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper))
self.app.canvas.set_wallpaper(wallpaper) # self.app.canvas.set_wallpaper(wallpaper)
# canvas settings # canvas settings
print(config)
canvas_config = config.get("canvas") canvas_config = config.get("canvas")
if canvas_config: if canvas_config:
logging.info("canvas metadata: %s", canvas_config) logging.info("canvas metadata: %s", canvas_config)
@ -332,6 +333,24 @@ class CoreClient:
wallpaper = canvas_config["wallpaper"] wallpaper = canvas_config["wallpaper"]
wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)) wallpaper = str(appconfig.BACKGROUNDS_PATH.joinpath(wallpaper))
self.app.canvas.set_wallpaper(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): def create_new_session(self):
""" """