pygui: small cleanup to node utils to simplify usage where possible
This commit is contained in:
parent
0fee29754d
commit
097f248120
8 changed files with 42 additions and 42 deletions
|
@ -843,10 +843,10 @@ class CoreClient:
|
|||
self.links[edge.token] = edge
|
||||
src_node = canvas_src_node.core_node
|
||||
dst_node = canvas_dst_node.core_node
|
||||
if NodeUtils.is_container_node(src_node.type):
|
||||
if NodeUtils.is_container_node(src_node):
|
||||
src_iface_id = edge.link.iface1.id
|
||||
self.iface_to_edge[(src_node.id, src_iface_id)] = edge
|
||||
if NodeUtils.is_container_node(dst_node.type):
|
||||
if NodeUtils.is_container_node(dst_node):
|
||||
dst_iface_id = edge.link.iface2.id
|
||||
self.iface_to_edge[(dst_node.id, dst_iface_id)] = edge
|
||||
|
||||
|
@ -893,7 +893,7 @@ class CoreClient:
|
|||
def get_service_configs_proto(self) -> List[services_pb2.ServiceConfig]:
|
||||
configs = []
|
||||
for node in self.session.nodes.values():
|
||||
if not NodeUtils.is_container_node(node.type):
|
||||
if not NodeUtils.is_container_node(node):
|
||||
continue
|
||||
if not node.service_configs:
|
||||
continue
|
||||
|
@ -913,7 +913,7 @@ class CoreClient:
|
|||
def get_service_file_configs_proto(self) -> List[services_pb2.ServiceFileConfig]:
|
||||
configs = []
|
||||
for node in self.session.nodes.values():
|
||||
if not NodeUtils.is_container_node(node.type):
|
||||
if not NodeUtils.is_container_node(node):
|
||||
continue
|
||||
if not node.service_file_configs:
|
||||
continue
|
||||
|
@ -930,7 +930,7 @@ class CoreClient:
|
|||
) -> List[configservices_pb2.ConfigServiceConfig]:
|
||||
config_service_protos = []
|
||||
for node in self.session.nodes.values():
|
||||
if not NodeUtils.is_container_node(node.type):
|
||||
if not NodeUtils.is_container_node(node):
|
||||
continue
|
||||
if not node.config_service_configs:
|
||||
continue
|
||||
|
|
|
@ -225,7 +225,7 @@ class NodeConfigDialog(Dialog):
|
|||
row += 1
|
||||
|
||||
# node type field
|
||||
if NodeUtils.is_model_node(self.node.type):
|
||||
if NodeUtils.is_model_node(self.node):
|
||||
label = ttk.Label(frame, text="Type")
|
||||
label.grid(row=row, column=0, sticky=tk.EW, padx=PADX, pady=PADY)
|
||||
combobox = ttk.Combobox(
|
||||
|
@ -245,7 +245,7 @@ class NodeConfigDialog(Dialog):
|
|||
entry.grid(row=row, column=1, sticky=tk.EW)
|
||||
row += 1
|
||||
|
||||
if NodeUtils.is_container_node(self.node.type):
|
||||
if NodeUtils.is_container_node(self.node):
|
||||
# server
|
||||
frame.grid(sticky=tk.EW)
|
||||
frame.columnconfigure(1, weight=1)
|
||||
|
@ -259,7 +259,7 @@ class NodeConfigDialog(Dialog):
|
|||
combobox.grid(row=row, column=1, sticky=tk.EW)
|
||||
row += 1
|
||||
|
||||
if NodeUtils.is_rj45_node(self.node.type):
|
||||
if NodeUtils.is_rj45_node(self.node):
|
||||
response = self.app.core.client.get_ifaces()
|
||||
logging.debug("host machine available interfaces: %s", response)
|
||||
ifaces = ListboxScroll(frame)
|
||||
|
@ -383,7 +383,7 @@ class NodeConfigDialog(Dialog):
|
|||
if NodeUtils.is_image_node(self.node.type):
|
||||
self.node.image = self.container_image.get()
|
||||
server = self.server.get()
|
||||
if NodeUtils.is_container_node(self.node.type):
|
||||
if NodeUtils.is_container_node(self.node):
|
||||
if server == DEFAULT_SERVER:
|
||||
self.node.server = None
|
||||
else:
|
||||
|
|
|
@ -26,7 +26,7 @@ class RunToolDialog(Dialog):
|
|||
store all CORE nodes (nodes that execute commands) from all existing nodes
|
||||
"""
|
||||
for node in self.app.core.session.nodes.values():
|
||||
if NodeUtils.is_container_node(node.type):
|
||||
if NodeUtils.is_container_node(node):
|
||||
self.executable_nodes[node.name] = node.id
|
||||
|
||||
def draw(self) -> None:
|
||||
|
|
|
@ -20,11 +20,11 @@ class NodeInfoFrame(InfoFrameBase):
|
|||
node = self.canvas_node.core_node
|
||||
frame = DetailsFrame(self)
|
||||
frame.grid(sticky=tk.EW)
|
||||
frame.add_detail("ID", node.id)
|
||||
frame.add_detail("ID", str(node.id))
|
||||
frame.add_detail("Name", node.name)
|
||||
if NodeUtils.is_model_node(node.type):
|
||||
if NodeUtils.is_model_node(node):
|
||||
frame.add_detail("Type", node.model)
|
||||
if NodeUtils.is_container_node(node.type):
|
||||
if NodeUtils.is_container_node(node):
|
||||
for index, service in enumerate(sorted(node.services)):
|
||||
if index == 0:
|
||||
frame.add_detail("Services", service)
|
||||
|
@ -35,6 +35,6 @@ class NodeInfoFrame(InfoFrameBase):
|
|||
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):
|
||||
if NodeUtils.is_container_node(node):
|
||||
server = node.server if node.server else "localhost"
|
||||
frame.add_detail("Server", server)
|
||||
|
|
|
@ -207,7 +207,7 @@ class CanvasManager:
|
|||
# create session nodes
|
||||
for core_node in session.nodes.values():
|
||||
# add node, avoiding ignored nodes
|
||||
if NodeUtils.is_ignore_node(core_node.type):
|
||||
if NodeUtils.is_ignore_node(core_node):
|
||||
continue
|
||||
self.add_core_node(core_node)
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class CanvasNode:
|
|||
def on_enter(self, event: tk.Event) -> None:
|
||||
is_runtime = self.app.core.is_runtime()
|
||||
has_observer = self.app.core.observer is not None
|
||||
is_container = NodeUtils.is_container_node(self.core_node.type)
|
||||
is_container = NodeUtils.is_container_node(self.core_node)
|
||||
if is_runtime and has_observer and is_container:
|
||||
self.tooltip.text.set("waiting...")
|
||||
self.tooltip.on_enter(event)
|
||||
|
@ -205,7 +205,7 @@ class CanvasNode:
|
|||
|
||||
def double_click(self, event: tk.Event) -> None:
|
||||
if self.app.core.is_runtime():
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
if NodeUtils.is_container_node(self.core_node):
|
||||
self.canvas.core.launch_terminal(self.core_node.id)
|
||||
else:
|
||||
self.show_config()
|
||||
|
@ -233,7 +233,7 @@ class CanvasNode:
|
|||
self.context.add_command(
|
||||
label="Mobility Player", command=self.show_mobility_player
|
||||
)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
if NodeUtils.is_container_node(self.core_node):
|
||||
services_menu = tk.Menu(self.context)
|
||||
for service in sorted(self.core_node.services):
|
||||
service_menu = tk.Menu(services_menu)
|
||||
|
@ -251,7 +251,7 @@ class CanvasNode:
|
|||
self.context.add_cascade(label="Services", menu=services_menu)
|
||||
else:
|
||||
self.context.add_command(label="Configure", command=self.show_config)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
if NodeUtils.is_container_node(self.core_node):
|
||||
self.context.add_command(label="Services", command=self.show_services)
|
||||
self.context.add_command(
|
||||
label="Config Services", command=self.show_config_services
|
||||
|
@ -268,7 +268,7 @@ class CanvasNode:
|
|||
self.context.add_command(
|
||||
label="Mobility Config", command=self.show_mobility_config
|
||||
)
|
||||
if NodeUtils.is_wireless_node(self.core_node.type):
|
||||
if NodeUtils.is_wireless_node(self.core_node):
|
||||
self.context.add_command(
|
||||
label="Link To Selected", command=self.wireless_link_selected
|
||||
)
|
||||
|
@ -406,9 +406,9 @@ class CanvasNode:
|
|||
if self == node:
|
||||
return False
|
||||
# rj45 nodes can only support one link
|
||||
if NodeUtils.is_rj45_node(self.core_node.type) and self.edges:
|
||||
if NodeUtils.is_rj45_node(self.core_node) and self.edges:
|
||||
return False
|
||||
if NodeUtils.is_rj45_node(node.core_node.type) and node.edges:
|
||||
if NodeUtils.is_rj45_node(node.core_node) and node.edges:
|
||||
return False
|
||||
# only 1 link between bridge based nodes
|
||||
is_src_bridge = NodeUtils.is_bridge_node(self.core_node)
|
||||
|
@ -420,7 +420,7 @@ class CanvasNode:
|
|||
return True
|
||||
|
||||
def is_wireless(self) -> bool:
|
||||
return NodeUtils.is_wireless_node(self.core_node.type)
|
||||
return NodeUtils.is_wireless_node(self.core_node)
|
||||
|
||||
def hide(self) -> None:
|
||||
self.hidden = True
|
||||
|
|
|
@ -179,8 +179,8 @@ class InterfaceManager:
|
|||
) -> None:
|
||||
src_node = canvas_src_node.core_node
|
||||
dst_node = canvas_dst_node.core_node
|
||||
is_src_container = NodeUtils.is_container_node(src_node.type)
|
||||
is_dst_container = NodeUtils.is_container_node(dst_node.type)
|
||||
is_src_container = NodeUtils.is_container_node(src_node)
|
||||
is_dst_container = NodeUtils.is_container_node(dst_node)
|
||||
if is_src_container and is_dst_container:
|
||||
self.current_subnets = self.next_subnets()
|
||||
elif is_src_container and not is_dst_container:
|
||||
|
@ -232,10 +232,10 @@ class InterfaceManager:
|
|||
dst_node = edge.dst.core_node
|
||||
self.determine_subnets(edge.src, edge.dst)
|
||||
src_iface = None
|
||||
if NodeUtils.is_container_node(src_node.type):
|
||||
if NodeUtils.is_container_node(src_node):
|
||||
src_iface = self.create_iface(edge.src, edge.linked_wireless)
|
||||
dst_iface = None
|
||||
if NodeUtils.is_container_node(dst_node.type):
|
||||
if NodeUtils.is_container_node(dst_node):
|
||||
dst_iface = self.create_iface(edge.dst, edge.linked_wireless)
|
||||
link = Link(
|
||||
type=LinkType.WIRED,
|
||||
|
|
|
@ -79,42 +79,42 @@ class NodeUtils:
|
|||
|
||||
@classmethod
|
||||
def is_router_node(cls, node: Node) -> bool:
|
||||
return cls.is_model_node(node.type) and node.model in cls.ROUTER_NODES
|
||||
return cls.is_model_node(node) and node.model in cls.ROUTER_NODES
|
||||
|
||||
@classmethod
|
||||
def is_ignore_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type in cls.IGNORE_NODES
|
||||
def is_ignore_node(cls, node: Node) -> bool:
|
||||
return node.type in cls.IGNORE_NODES
|
||||
|
||||
@classmethod
|
||||
def is_container_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type in cls.CONTAINER_NODES
|
||||
def is_container_node(cls, node: Node) -> bool:
|
||||
return node.type in cls.CONTAINER_NODES
|
||||
|
||||
@classmethod
|
||||
def is_model_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type == NodeType.DEFAULT
|
||||
def is_model_node(cls, node: Node) -> bool:
|
||||
return node.type == NodeType.DEFAULT
|
||||
|
||||
@classmethod
|
||||
def is_image_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type in cls.IMAGE_NODES
|
||||
|
||||
@classmethod
|
||||
def is_wireless_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type in cls.WIRELESS_NODES
|
||||
def is_wireless_node(cls, node: Node) -> bool:
|
||||
return node.type in cls.WIRELESS_NODES
|
||||
|
||||
@classmethod
|
||||
def is_rj45_node(cls, node_type: NodeType) -> bool:
|
||||
return node_type in cls.RJ45_NODES
|
||||
def is_rj45_node(cls, node: Node) -> bool:
|
||||
return node.type in cls.RJ45_NODES
|
||||
|
||||
@classmethod
|
||||
def node_icon(
|
||||
cls, node_type: NodeType, model: str, gui_config: GuiConfig, scale: float = 1.0
|
||||
cls, node: Node, gui_config: GuiConfig, scale: float = 1.0
|
||||
) -> PhotoImage:
|
||||
|
||||
image_enum = TypeToImage.get(node_type, model)
|
||||
image_enum = TypeToImage.get(node.type, node.model)
|
||||
if image_enum:
|
||||
return Images.get(image_enum, int(ICON_SIZE * scale))
|
||||
else:
|
||||
image_stem = cls.get_image_file(gui_config, model)
|
||||
image_stem = cls.get_image_file(gui_config, node.model)
|
||||
if image_stem:
|
||||
return Images.get_with_image_file(image_stem, int(ICON_SIZE * scale))
|
||||
|
||||
|
@ -122,7 +122,7 @@ class NodeUtils:
|
|||
def node_image(
|
||||
cls, core_node: Node, gui_config: GuiConfig, scale: float = 1.0
|
||||
) -> PhotoImage:
|
||||
image = cls.node_icon(core_node.type, core_node.model, gui_config, scale)
|
||||
image = cls.node_icon(core_node, gui_config, scale)
|
||||
if core_node.icon:
|
||||
try:
|
||||
image = Images.create(core_node.icon, int(ICON_SIZE * scale))
|
||||
|
|
Loading…
Reference in a new issue