Example #1
0
def get_icon(node: Node, app: "Application") -> PhotoImage:
    scale = app.app_scale
    image = None
    # node icon was overriden with a specific value
    if node.icon:
        try:
            image = images.from_file(node.icon,
                                     width=images.NODE_SIZE,
                                     scale=scale)
        except OSError:
            logging.error("invalid icon: %s", node.icon)
    # custom node
    elif is_custom(node):
        image_file = _get_custom_file(app.guiconfig, node.model)
        logging.info("custom node file: %s", image_file)
        if image_file:
            image = images.from_file(image_file,
                                     width=images.NODE_SIZE,
                                     scale=scale)
    # built in node
    else:
        image = images.from_node(node, scale=scale)
    # default image, if everything above fails
    if not image:
        image = images.from_enum(ImageEnum.EDITNODE,
                                 width=images.NODE_SIZE,
                                 scale=scale)
    return image
Example #2
0
 def update_icon(self, icon_path: str) -> None:
     if not Path(icon_path).exists():
         logger.error(f"node icon does not exist: {icon_path}")
         return
     self.core_node.icon = icon_path
     self.image = images.from_file(icon_path, width=images.NODE_SIZE)
     self.canvas.itemconfig(self.id, image=self.image)
Example #3
0
 def click_icon(self) -> None:
     file_path = image_chooser(self, ICONS_PATH)
     if file_path:
         image = images.from_file(file_path, width=images.NODE_SIZE)
         self.image = image
         self.image_file = file_path
         self.image_button.config(image=self.image)
Example #4
0
 def from_custom(cls, custom_node: CustomNode) -> "NodeDraw":
     node_draw = NodeDraw()
     node_draw.custom = True
     node_draw.image_file = custom_node.image
     node_draw.image = images.from_file(custom_node.image,
                                        width=images.NODE_SIZE)
     node_draw.node_type = NodeType.DEFAULT
     node_draw.services = set(custom_node.services)
     node_draw.label = custom_node.name
     node_draw.model = custom_node.name
     node_draw.tooltip = custom_node.name
     return node_draw
Example #5
0
 def get_file_icon(self, file_path: str, *, width: int) -> PhotoImage:
     return images.from_file(file_path, width=width, scale=self.app_scale)
Example #6
0
 def draw_preview(self) -> None:
     image = images.from_file(self.filename.get(), width=250, height=135)
     self.image_label.config(image=image)
     self.image_label.image = image