<reponame>kleberango/core
import tkinter as tk
from typing import TYPE_CHECKING

from core.gui.frames.base import DetailsFrame, InfoFrameBase
from core.gui.nodeutils import NodeUtils
from core.gui.wrappers import NodeType

if TYPE_CHECKING:
    from core.gui.app import Application
    from core.gui.graph.node import CanvasNode


class NodeInfoFrame(InfoFrameBase):
    def __init__(self, master, app: "Application", canvas_node: "CanvasNode") -> None:
        super().__init__(master, app)
        self.canvas_node: "CanvasNode" = canvas_node

    def draw(self) -> None:
        self.columnconfigure(0, weight=1)
        node = self.canvas_node.core_node
        frame = DetailsFrame(self)
        frame.grid(sticky=tk.EW)
        frame.add_detail("ID", node.id)
        frame.add_detail("Name", node.name)
        if NodeUtils.is_model_node(node.type):
            frame.add_detail("Type", node.model)
        if NodeUtils.is_container_node(node.type):
            for index, service in enumerate(sorted(node.services)):
                if index == 0:
                    frame.add_detail("Services", service)
                else:
                    frame.add_detail("", service)
        if node.type == NodeType.EMANE:
            emane = node.emane.split("_")[1:]
            frame.add_detail("EMANE", emane)
        if NodeUtils.is_image_node(node.type):
            frame.add_detail("Image", node.image)
        if NodeUtils.is_container_node(node.type):
            server = node.server if node.server else "localhost"
            frame.add_detail("Server", server)

import tkinter as tk
from typing import TYPE_CHECKING

from core.gui.frames.base import DetailsFrame, InfoFrameBase
from core.gui.nodeutils import NodeUtils
from core.gui.wrappers import NodeType

if TYPE_CHECKING:
    from core.gui.app import Application
    from core.gui.graph.node import CanvasNode


class NodeInfoFrame(InfoFrameBase):
    def __init__(self, master, app: "Application", canvas_node: "CanvasNode") -> None:
        super().__init__(master, app)
        self.canvas_node: "CanvasNode" = canvas_node

    def draw(self) -> None:
        self.columnconfigure(0, weight=1)
        node = self.canvas_node.core_node
        frame = DetailsFrame(self)
        frame.grid(sticky=tk.EW)
        frame.add_detail("ID", node.id)
        frame.add_detail("Name", node.name)
        if NodeUtils.is_model_node(node.type):
            frame.add_detail("Type", node.model)
        if NodeUtils.is_container_node(node.type):
            for index, service in enumerate(sorted(node.services)):
                if index == 0:
                    frame.add_detail("Services", service)
                else:
                    frame.add_detail("", service)
        if node.type == NodeType.EMANE:
            emane = node.emane.split("_")[1:]
            frame.add_detail("EMANE", emane)
        if NodeUtils.is_image_node(node.type):
            frame.add_detail("Image", node.image)
        if NodeUtils.is_container_node(node.type):
            server = node.server if node.server else "localhost"
            frame.add_detail("Server", server)