From 1d911a763f8352736acc92ae3a90a7abd4874474 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Mon, 17 Feb 2020 12:56:19 -0800 Subject: [PATCH] scale custom node icon and custom node drawn on canvas --- daemon/core/gui/graph/graph.py | 29 +++++++++++++++++++++-------- daemon/core/gui/toolbar.py | 8 ++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index dd5025fd..f705565f 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -667,9 +667,14 @@ class CanvasGraph(tk.Canvas): core_node = self.core.create_node( actual_x, actual_y, self.node_draw.node_type, self.node_draw.model ) - self.node_draw.image = Images.get( - self.node_draw.image_enum, int(ICON_SIZE * self.app.app_scale) - ) + try: + self.node_draw.image = Images.get( + self.node_draw.image_enum, int(ICON_SIZE * self.app.app_scale) + ) + except AttributeError: + self.node_draw.image = Images.get_custom( + self.node_draw.image_file, int(ICON_SIZE * self.app.app_scale) + ) node = CanvasNode(self.master, x, y, core_node, self.node_draw.image) self.core.canvas_nodes[core_node.id] = node self.nodes[node.id] = node @@ -921,13 +926,21 @@ class CanvasGraph(tk.Canvas): def scale_graph(self): for nid, canvas_node in self.nodes.items(): - image_enum = TypeToImage.get( - canvas_node.core_node.type, canvas_node.core_node.model - ) - img = Images.get(image_enum, int(ICON_SIZE * self.app.app_scale)) + img = None + if NodeUtils.is_custom(canvas_node.core_node.model): + for custom_node in self.app.guiconfig["nodes"]: + if custom_node["name"] == canvas_node.core_node.model: + img = Images.get_custom( + custom_node["image"], int(ICON_SIZE * self.app.app_scale) + ) + else: + image_enum = TypeToImage.get( + canvas_node.core_node.type, canvas_node.core_node.model + ) + img = Images.get(image_enum, int(ICON_SIZE * self.app.app_scale)) + self.itemconfig(nid, image=img) canvas_node.image = img - canvas_node.scale_text() for edge_id in self.find_withtag(tags.EDGE): diff --git a/daemon/core/gui/toolbar.py b/daemon/core/gui/toolbar.py index d0702386..eff37257 100644 --- a/daemon/core/gui/toolbar.py +++ b/daemon/core/gui/toolbar.py @@ -197,8 +197,12 @@ class Toolbar(ttk.Frame): # draw custom nodes for name in sorted(self.app.core.custom_nodes): node_draw = self.app.core.custom_nodes[name] - toolbar_image = Images.get_custom(node_draw.image_file, TOOLBAR_SIZE) - image = Images.get_custom(node_draw.image_file, PICKER_SIZE) + toolbar_image = Images.get_custom( + node_draw.image_file, int(TOOLBAR_SIZE * self.app.app_scale) + ) + image = Images.get_custom( + node_draw.image_file, int(PICKER_SIZE * self.app.app_scale) + ) func = partial( self.update_button, self.node_button,