diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 0f7eb996..79bc5359 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -13,6 +13,8 @@ from coretk.dialogs.sessions import SessionsDialog from coretk.interface import InterfaceManager from coretk.nodeutils import NodeDraw, NodeUtils +# from coretk.shape import Shape, ShapeData + OBSERVERS = { "processes": "ps", "ifconfig": "ifconfig", @@ -281,6 +283,36 @@ 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"): + # if canvas_config["type"] == "rectangle": + # 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()]) + # print(coords) + # shape = Shape(self.app, self.app.canvas, None, None, coords, data, canvas_config["type"]) + # self.app.canvas.shapes[shape.id] = shape + # elif canvas_config["type"] == "oval": + # print("not implemented") + # 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 canvas_config = config.get("canvas") if canvas_config: diff --git a/coretk/coretk/dialogs/shapemod.py b/coretk/coretk/dialogs/shapemod.py index 005ad000..18ba0eca 100644 --- a/coretk/coretk/dialogs/shapemod.py +++ b/coretk/coretk/dialogs/shapemod.py @@ -158,7 +158,12 @@ class ShapeDialog(Dialog): f.append("underline") if shape.text_id is None: shape.text_id = self.canvas.create_text( - text_x, text_y, text=shape_text, fill=self.text_color, font=f + text_x, + text_y, + text=shape_text, + fill=self.text_color, + font=f, + tags="shapetext", ) self.canvas.shapes[self.id].created = True else: diff --git a/coretk/coretk/graph.py b/coretk/coretk/graph.py index 60f4e498..24f07727 100644 --- a/coretk/coretk/graph.py +++ b/coretk/coretk/graph.py @@ -132,6 +132,7 @@ class CanvasGraph(tk.Canvas): self.selected = None self.nodes.clear() self.edges.clear() + self.shapes.clear() self.wireless_edges.clear() self.drawing_edge = None self.draw_session(session) @@ -451,8 +452,6 @@ class CanvasGraph(tk.Canvas): self.context.unpost() self.context = None - # TODO rather than delete, might move the data to somewhere else in order to reuse - # TODO when the user undo def press_delete(self, event): """ delete selected nodes and any data that relates to it @@ -585,6 +584,7 @@ class CanvasGraph(tk.Canvas): if self.adjust_to_dim.get(): self.resize_to_wallpaper() else: + print(self.scale_option.get()) option = ScaleOption(self.scale_option.get()) if option == ScaleOption.UPPER_LEFT: self.wallpaper_upper_left() diff --git a/coretk/coretk/graph_helper.py b/coretk/coretk/graph_helper.py index eea4ff55..af6d4823 100644 --- a/coretk/coretk/graph_helper.py +++ b/coretk/coretk/graph_helper.py @@ -16,6 +16,8 @@ CANVAS_COMPONENT_TAGS = [ "antenna", "wireless", "selectednodes", + "shape", + "shapetext", ] diff --git a/coretk/coretk/parsedata.py b/coretk/coretk/parsedata.py new file mode 100644 index 00000000..9afff3e2 --- /dev/null +++ b/coretk/coretk/parsedata.py @@ -0,0 +1,28 @@ +""" +parse meta data +""" +# from coretk.graph import ScaleOption + + +def parse(meta_string): + parsed = {} + if meta_string[0] == "{" and meta_string[len(meta_string) - 1] == "}": + meta_string = meta_string[1:-1] + for key_value in meta_string.split("} {"): + if key_value[len(key_value) - 1] == "}": + key, value = key_value[:-1].split(" {") + if key == "wallpaper-style": + if value == "upperleft": + parsed[key] = 1 + elif value == "centered": + parsed[key] = 2 + elif value == "scaled": + parsed[key] = 3 + elif value == "tiled": + parsed[key] = 4 + else: + parsed[key] = value + else: + key, value = tuple(key_value.split()) + parsed[key] = value + return parsed diff --git a/coretk/coretk/shape.py b/coretk/coretk/shape.py index c39c549b..63025b34 100644 --- a/coretk/coretk/shape.py +++ b/coretk/coretk/shape.py @@ -10,41 +10,108 @@ ABOVE_COMPONENT = ["gridline", "edge", "linkinfo", "antenna", "node", "nodename" class ShapeData: - def __init__(self): - self.text = "" - self.font = "Arial" - self.font_size = 12 - self.text_color = "#000000" - self.fill_color = "#CFCFFF" - self.border_color = "#000000" - self.border_width = 0 - self.bold = 0 - self.italic = 0 - self.underline = 0 + def __init__( + self, + is_default=True, + text=None, + font=None, + font_size=None, + text_color=None, + fill_color=None, + border_color=None, + border_width=None, + bold=0, + italic=0, + underline=0, + ): + if is_default: + self.text = "" + self.font = "Arial" + self.font_size = 12 + self.text_color = "#000000" + self.fill_color = "#CFCFFF" + self.border_color = "#000000" + self.border_width = 0 + self.bold = 0 + self.italic = 0 + self.underline = 0 + else: + self.text = text + self.font = font + self.font_size = font_size + self.text_color = text_color + self.fill_color = fill_color + self.border_color = border_color + self.border_width = border_width + self.bold = bold + self.italic = italic + self.underline = underline class Shape: - def __init__(self, app, canvas, top_x, top_y): + def __init__( + self, + app, + canvas, + top_x=None, + top_y=None, + coords=None, + data=None, + shape_type=None, + ): self.app = app self.canvas = canvas - self.x0 = top_x - self.y0 = top_y + if data is None: + self.x0 = top_x + self.y0 = top_y + self.created = False + self.text_id = None + self.shape_data = ShapeData() + canvas.delete(canvas.find_withtag("selectednodes")) + annotation_type = self.canvas.annotation_type + if annotation_type == ImageEnum.OVAL: + self.id = canvas.create_oval( + top_x, top_y, top_x, top_y, tags="shape", dash="-" + ) + elif annotation_type == ImageEnum.RECTANGLE: + self.id = canvas.create_rectangle( + top_x, top_y, top_x, top_y, tags="shape", dash="-" + ) + else: + x0, y0, x1, y1 = coords + self.x0 = x0 + self.y0 = y0 + self.created = True + if shape_type == "oval": + self.id = self.canvas.create_oval( + x0, + y0, + x1, + y1, + tags="shape", + fill=data.fill_color, + outline=data.border_color, + width=data.border_width, + ) + elif shape_type == "rectangle": + self.id = self.canvas.create_rectangle( + x0, + y0, + x1, + y1, + tags="shape", + fill=data.fill_color, + outline=data.border_color, + width=data.border_width, + ) + _x = (x0 + x1) / 2 + _y = (y0 + y1) / 2 + self.text_id = self.canvas.create_text( + _x, _y, text=data.text, fill=data.text_color + ) + self.shape_data = data self.cursor_x = None self.cursor_y = None - self.created = False - self.text_id = None - - self.shape_data = ShapeData() - canvas.delete(canvas.find_withtag("selectednodes")) - annotation_type = self.canvas.annotation_type - if annotation_type == ImageEnum.OVAL: - self.id = canvas.create_oval( - top_x, top_y, top_x, top_y, tags="shape", dash="-" - ) - elif annotation_type == ImageEnum.RECTANGLE: - self.id = canvas.create_rectangle( - top_x, top_y, top_x, top_y, tags="shape", dash="-" - ) self.canvas.tag_bind(self.id, "", self.click_release) def shape_motion(self, x1, y1):