Merge branch 'coretk' into coretk-color
This commit is contained in:
commit
ea2bfad591
13 changed files with 160 additions and 78 deletions
|
@ -183,8 +183,7 @@ class CoreClient:
|
|||
)
|
||||
|
||||
def handle_exception_event(self, event):
|
||||
print(event)
|
||||
print(event.node_id)
|
||||
logging.info("exception event: %s", event)
|
||||
self.app.statusbar.core_alarms.append(event)
|
||||
|
||||
def join_session(self, session_id, query_location=True):
|
||||
|
@ -229,26 +228,25 @@ class CoreClient:
|
|||
|
||||
# get emane model config
|
||||
response = self.client.get_emane_model_configs(self.session_id)
|
||||
for _id in response.configs:
|
||||
config = response.configs[_id]
|
||||
for config in response.configs:
|
||||
interface = None
|
||||
node_id = _id
|
||||
if _id >= 1000:
|
||||
interface = _id % 1000
|
||||
node_id = int(_id / 1000)
|
||||
if config.interface != -1:
|
||||
interface = config.interface
|
||||
self.set_emane_model_config(
|
||||
node_id, config.model, config.config, interface
|
||||
config.node_id, config.model, config.config, interface
|
||||
)
|
||||
|
||||
# get wlan configurations
|
||||
response = self.client.get_wlan_configs(self.session_id)
|
||||
for _id in response.configs:
|
||||
mapped_config = response.configs[_id]
|
||||
self.wlan_configs[_id] = mapped_config.config
|
||||
|
||||
# save and retrieve data, needed for session nodes
|
||||
for node in session.nodes:
|
||||
# get node service config and file config
|
||||
# get wlan configs for wlan nodes
|
||||
if node.type == core_pb2.NodeType.WIRELESS_LAN:
|
||||
response = self.client.get_wlan_config(self.session_id, node.id)
|
||||
self.wlan_configs[node.id] = response.config
|
||||
# retrieve service configurations data for default nodes
|
||||
elif node.type == core_pb2.NodeType.DEFAULT:
|
||||
if node.type == core_pb2.NodeType.DEFAULT:
|
||||
for service in node.services:
|
||||
response = self.client.get_node_service(
|
||||
self.session_id, node.id, service
|
||||
|
|
|
@ -46,6 +46,7 @@ class NodeConfigDialog(Dialog):
|
|||
self.canvas_node = canvas_node
|
||||
self.node = canvas_node.core_node
|
||||
self.image = canvas_node.image
|
||||
self.image_file = None
|
||||
self.image_button = None
|
||||
self.name = tk.StringVar(value=self.node.name)
|
||||
self.type = tk.StringVar(value=self.node.model)
|
||||
|
@ -201,6 +202,7 @@ class NodeConfigDialog(Dialog):
|
|||
if file_path:
|
||||
self.image = Images.create(file_path, nodeutils.ICON_SIZE)
|
||||
self.image_button.config(image=self.image)
|
||||
self.image_file = file_path
|
||||
|
||||
def config_apply(self):
|
||||
# update core node
|
||||
|
@ -211,6 +213,10 @@ class NodeConfigDialog(Dialog):
|
|||
if NodeUtils.is_container_node(self.node.type) and server != "localhost":
|
||||
self.node.server = server
|
||||
|
||||
# set custom icon
|
||||
if self.image_file:
|
||||
self.node.icon = self.image_file
|
||||
|
||||
# update canvas node
|
||||
self.canvas_node.image = self.image
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import tkinter as tk
|
|||
from PIL import Image, ImageTk
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk import nodeutils
|
||||
from coretk.dialogs.shapemod import ShapeDialog
|
||||
from coretk.graph import tags
|
||||
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.shape import Shape
|
||||
from coretk.graph.shapeutils import ShapeType, is_draw_shape
|
||||
from coretk.images import Images
|
||||
from coretk.nodeutils import NodeUtils
|
||||
|
||||
ZOOM_IN = 1.1
|
||||
|
@ -136,6 +138,11 @@ class CanvasGraph(tk.Canvas):
|
|||
valid_y = y1 <= y <= y2
|
||||
return valid_x and valid_y
|
||||
|
||||
def valid_position(self, x1, y1, x2, y2):
|
||||
valid_topleft = self.inside_canvas(x1, y1)
|
||||
valid_bottomright = self.inside_canvas(x2, y2)
|
||||
return valid_topleft and valid_bottomright
|
||||
|
||||
def draw_grid(self):
|
||||
"""
|
||||
Create grid.
|
||||
|
@ -186,12 +193,19 @@ class CanvasGraph(tk.Canvas):
|
|||
"""
|
||||
# draw existing 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
|
||||
if NodeUtils.is_ignore_node(core_node.type):
|
||||
continue
|
||||
|
||||
# draw nodes on the canvas
|
||||
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
|
||||
y = core_node.position.y
|
||||
node = CanvasNode(self.master, x, y, core_node, image)
|
||||
|
@ -530,6 +544,13 @@ class CanvasGraph(tk.Canvas):
|
|||
"""
|
||||
x, y = self.canvas_xy(event)
|
||||
if not self.inside_canvas(x, y):
|
||||
if self.select_box:
|
||||
self.select_box.delete()
|
||||
self.select_box = None
|
||||
if is_draw_shape(self.annotation_type) and self.shape_drawing:
|
||||
shape = self.shapes.pop(self.selected)
|
||||
shape.delete()
|
||||
self.shape_drawing = False
|
||||
return
|
||||
|
||||
x_offset = x - self.cursor[0]
|
||||
|
@ -595,10 +616,7 @@ class CanvasGraph(tk.Canvas):
|
|||
if self.selected is None or self.selected in self.shapes:
|
||||
actual_x, actual_y = self.get_actual_coords(x, y)
|
||||
core_node = self.core.create_node(
|
||||
int(actual_x),
|
||||
int(actual_y),
|
||||
self.node_draw.node_type,
|
||||
self.node_draw.model,
|
||||
actual_x, actual_y, self.node_draw.node_type, self.node_draw.model
|
||||
)
|
||||
node = CanvasNode(self.master, x, y, core_node, self.node_draw.image)
|
||||
self.core.canvas_nodes[core_node.id] = node
|
||||
|
|
|
@ -103,10 +103,19 @@ class CanvasNode:
|
|||
self.motion(x_offset, y_offset, update=False)
|
||||
|
||||
def motion(self, x_offset, y_offset, update=True):
|
||||
original_position = self.canvas.coords(self.id)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
x, y = self.canvas.coords(self.id)
|
||||
|
||||
# check new position
|
||||
bbox = self.canvas.bbox(self.id)
|
||||
if not self.canvas.valid_position(*bbox):
|
||||
self.canvas.coords(self.id, original_position)
|
||||
return
|
||||
|
||||
# move test and selection box
|
||||
self.canvas.move(self.text_id, x_offset, y_offset)
|
||||
self.canvas.move_selection(self.id, x_offset, y_offset)
|
||||
x, y = self.canvas.coords(self.id)
|
||||
|
||||
# move antennae
|
||||
for antenna_id in self.antennae:
|
||||
|
@ -131,8 +140,8 @@ class CanvasNode:
|
|||
|
||||
# set actual coords for node and update core is running
|
||||
real_x, real_y = self.canvas.get_actual_coords(x, y)
|
||||
self.core_node.position.x = int(real_x)
|
||||
self.core_node.position.y = int(real_y)
|
||||
self.core_node.position.x = real_x
|
||||
self.core_node.position.y = real_y
|
||||
if self.app.core.is_runtime() and update:
|
||||
self.app.core.edit_node(self.core_node)
|
||||
|
||||
|
@ -155,11 +164,6 @@ class CanvasNode:
|
|||
else:
|
||||
self.show_config()
|
||||
|
||||
def update_coords(self):
|
||||
x, y = self.canvas.coords(self.id)
|
||||
self.core_node.position.x = int(x)
|
||||
self.core_node.position.y = int(y)
|
||||
|
||||
def create_context(self):
|
||||
is_wlan = self.core_node.type == NodeType.WIRELESS_LAN
|
||||
is_emane = self.core_node.type == NodeType.EMANE
|
||||
|
@ -169,6 +173,8 @@ class CanvasNode:
|
|||
context.add_command(label="Configure", command=self.show_config)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
context.add_command(label="Services", state=tk.DISABLED)
|
||||
if is_wlan:
|
||||
context.add_command(label="WLAN Config", command=self.show_wlan_config)
|
||||
if is_wlan and self.core_node.id in self.app.core.mobility_players:
|
||||
context.add_command(
|
||||
label="Mobility Player", command=self.show_mobility_player
|
||||
|
|
|
@ -136,7 +136,13 @@ class Shape:
|
|||
self.canvas.delete(self.id)
|
||||
|
||||
def motion(self, x_offset, y_offset):
|
||||
original_position = self.canvas.coords(self.id)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
coords = self.canvas.coords(self.id)
|
||||
if not self.canvas.valid_position(*coords):
|
||||
self.canvas.coords(self.id, original_position)
|
||||
return
|
||||
|
||||
self.canvas.move_selection(self.id, x_offset, y_offset)
|
||||
if self.text_id is not None:
|
||||
self.canvas.move(self.text_id, x_offset, y_offset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue