updated gui to display custom icons if set, updated grpc to send custon icon and image data when present
This commit is contained in:
parent
fb63d7e8b3
commit
d343bd0655
3 changed files with 18 additions and 2 deletions
|
@ -46,6 +46,7 @@ class NodeConfigDialog(Dialog):
|
||||||
self.canvas_node = canvas_node
|
self.canvas_node = canvas_node
|
||||||
self.node = canvas_node.core_node
|
self.node = canvas_node.core_node
|
||||||
self.image = canvas_node.image
|
self.image = canvas_node.image
|
||||||
|
self.image_file = None
|
||||||
self.image_button = None
|
self.image_button = None
|
||||||
self.name = tk.StringVar(value=self.node.name)
|
self.name = tk.StringVar(value=self.node.name)
|
||||||
self.type = tk.StringVar(value=self.node.model)
|
self.type = tk.StringVar(value=self.node.model)
|
||||||
|
@ -201,6 +202,7 @@ class NodeConfigDialog(Dialog):
|
||||||
if file_path:
|
if file_path:
|
||||||
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||||
self.image_button.config(image=self.image)
|
self.image_button.config(image=self.image)
|
||||||
|
self.image_file = file_path
|
||||||
|
|
||||||
def config_apply(self):
|
def config_apply(self):
|
||||||
# update core node
|
# update core node
|
||||||
|
@ -211,6 +213,10 @@ class NodeConfigDialog(Dialog):
|
||||||
if NodeUtils.is_container_node(self.node.type) and server != "localhost":
|
if NodeUtils.is_container_node(self.node.type) and server != "localhost":
|
||||||
self.node.server = server
|
self.node.server = server
|
||||||
|
|
||||||
|
# set custom icon
|
||||||
|
if self.image_file:
|
||||||
|
self.node.icon = self.image_file
|
||||||
|
|
||||||
# update canvas node
|
# update canvas node
|
||||||
self.canvas_node.image = self.image
|
self.canvas_node.image = self.image
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import tkinter as tk
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
|
from coretk import nodeutils
|
||||||
from coretk.dialogs.shapemod import ShapeDialog
|
from coretk.dialogs.shapemod import ShapeDialog
|
||||||
from coretk.graph import tags
|
from coretk.graph import tags
|
||||||
from coretk.graph.edges import CanvasEdge, CanvasWirelessEdge
|
from coretk.graph.edges import CanvasEdge, CanvasWirelessEdge
|
||||||
|
@ -12,6 +13,7 @@ from coretk.graph.linkinfo import LinkInfo, Throughput
|
||||||
from coretk.graph.node import CanvasNode
|
from coretk.graph.node import CanvasNode
|
||||||
from coretk.graph.shape import Shape
|
from coretk.graph.shape import Shape
|
||||||
from coretk.graph.shapeutils import ShapeType, is_draw_shape
|
from coretk.graph.shapeutils import ShapeType, is_draw_shape
|
||||||
|
from coretk.images import Images
|
||||||
from coretk.nodeutils import NodeUtils
|
from coretk.nodeutils import NodeUtils
|
||||||
|
|
||||||
ZOOM_IN = 1.1
|
ZOOM_IN = 1.1
|
||||||
|
@ -186,12 +188,19 @@ class CanvasGraph(tk.Canvas):
|
||||||
"""
|
"""
|
||||||
# draw existing nodes
|
# draw existing nodes
|
||||||
for core_node in session.nodes:
|
for core_node in session.nodes:
|
||||||
|
logging.info("drawing core node: %s", core_node)
|
||||||
# peer to peer node is not drawn on the GUI
|
# peer to peer node is not drawn on the GUI
|
||||||
if NodeUtils.is_ignore_node(core_node.type):
|
if NodeUtils.is_ignore_node(core_node.type):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# draw nodes on the canvas
|
# draw nodes on the canvas
|
||||||
image = NodeUtils.node_icon(core_node.type, core_node.model)
|
image = NodeUtils.node_icon(core_node.type, core_node.model)
|
||||||
|
if core_node.icon:
|
||||||
|
try:
|
||||||
|
image = Images.create(core_node.icon, nodeutils.ICON_SIZE)
|
||||||
|
except OSError:
|
||||||
|
logging.error("invalid icon: %s", core_node.icon)
|
||||||
|
|
||||||
x = core_node.position.x
|
x = core_node.position.x
|
||||||
y = core_node.position.y
|
y = core_node.position.y
|
||||||
node = CanvasNode(self.master, x, y, core_node, image)
|
node = CanvasNode(self.master, x, y, core_node, image)
|
||||||
|
|
|
@ -393,15 +393,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
position = core_pb2.Position(
|
position = core_pb2.Position(
|
||||||
x=node.position.x, y=node.position.y, z=node.position.z
|
x=node.position.x, y=node.position.y, z=node.position.z
|
||||||
)
|
)
|
||||||
|
|
||||||
services = getattr(node, "services", [])
|
services = getattr(node, "services", [])
|
||||||
if services is None:
|
if services is None:
|
||||||
services = []
|
services = []
|
||||||
services = [x.name for x in services]
|
services = [x.name for x in services]
|
||||||
|
|
||||||
emane_model = None
|
emane_model = None
|
||||||
if isinstance(node, EmaneNet):
|
if isinstance(node, EmaneNet):
|
||||||
emane_model = node.model.name
|
emane_model = node.model.name
|
||||||
|
image = getattr(node, "image", None)
|
||||||
|
|
||||||
node_proto = core_pb2.Node(
|
node_proto = core_pb2.Node(
|
||||||
id=node.id,
|
id=node.id,
|
||||||
|
@ -411,6 +410,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
type=node_type.value,
|
type=node_type.value,
|
||||||
position=position,
|
position=position,
|
||||||
services=services,
|
services=services,
|
||||||
|
icon=node.icon,
|
||||||
|
image=image,
|
||||||
)
|
)
|
||||||
if isinstance(node, (DockerNode, LxcNode)):
|
if isinstance(node, (DockerNode, LxcNode)):
|
||||||
node_proto.image = node.image
|
node_proto.image = node.image
|
||||||
|
|
Loading…
Reference in a new issue