updates to handle node events for moving nodes and displaying mobility player dialog on session event with configured data

This commit is contained in:
Blake Harnden 2019-11-26 16:50:23 -08:00
parent 2586a5ad6f
commit 2a08c770d3
4 changed files with 48 additions and 18 deletions

View file

@ -119,10 +119,11 @@ class CoreClient:
self.custom_observers[observer.name] = observer
def handle_events(self, event):
logging.info("event: %s", event)
if event.HasField("link_event"):
logging.info("link event: %s", event)
self.app.canvas.wireless_draw.handle_link_event(event.link_event)
elif event.HasField("session_event"):
logging.info("session event: %s", event)
session_event = event.session_event
if session_event.event <= core_pb2.SessionState.SHUTDOWN:
self.state = event.session_event.event
@ -136,20 +137,19 @@ class CoreClient:
self.mobility_players[node_id] = dialog
# mobility stop
elif session_event.event == 8:
node_id = session_event.node_id
if node_id not in self.mobility_players:
canvas_node = self.canvas_nodes[node_id]
dialog = MobilityPlayerDialog(self.app, self.app, canvas_node)
dialog.show()
self.mobility_players[node_id] = dialog
pass
# mobility pause
elif session_event.event == 9:
node_id = session_event.node_id
if node_id not in self.mobility_players:
canvas_node = self.canvas_nodes[node_id]
dialog = MobilityPlayerDialog(self.app, self.app, canvas_node)
dialog.show()
self.mobility_players[node_id] = dialog
pass
elif event.HasField("node_event"):
node_event = event.node_event
node_id = node_event.node.id
x = node_event.node.position.x
y = node_event.node.position.y
canvas_node = self.canvas_nodes[node_id]
canvas_node.move(x, y)
else:
logging.info("unhandled event: %s", event)
def handle_throughputs(self, event):
interface_throughputs = event.interface_throughputs

View file

@ -1,3 +1,4 @@
import tkinter as tk
from tkinter import ttk
from coretk.dialogs.dialog import Dialog
@ -10,6 +11,7 @@ class MobilityPlayerDialog(Dialog):
super().__init__(
master, app, f"{canvas_node.core_node.name} Mobility Player", modal=False
)
self.config = self.app.core.mobility_configs[canvas_node.core_node.id]
self.play_button = None
self.pause_button = None
self.stop_button = None
@ -18,7 +20,8 @@ class MobilityPlayerDialog(Dialog):
def draw(self):
self.top.columnconfigure(0, weight=1)
label = ttk.Label(self.top, text="File Name")
file_name = self.config["file"].value
label = ttk.Label(self.top, text=file_name)
label.grid(sticky="ew", pady=PAD)
frame = ttk.Frame(self.top)
@ -32,15 +35,24 @@ class MobilityPlayerDialog(Dialog):
frame = ttk.Frame(self.top)
frame.grid(sticky="ew", pady=PAD)
self.play_button = ttk.Button(frame, text="Play", command=self.click_play)
self.play_button.grid(row=0, column=0, sticky="ew", padx=PAD)
self.pause_button = ttk.Button(frame, text="Pause", command=self.click_pause)
self.pause_button.grid(row=0, column=1, sticky="ew", padx=PAD)
self.stop_button = ttk.Button(frame, text="Stop", command=self.click_stop)
self.stop_button.grid(row=0, column=2, sticky="ew", padx=PAD)
checkbutton = ttk.Checkbutton(frame, text="Loop?")
loop = tk.IntVar(value=int(self.config["loop"].value == "1"))
checkbutton = ttk.Checkbutton(
frame, text="Loop?", variable=loop, state=tk.DISABLED
)
checkbutton.grid(row=0, column=3, padx=PAD)
label = ttk.Label(frame, text="rate 50 ms")
rate = self.config["refresh_ms"].value
label = ttk.Label(frame, text=f"rate {rate} ms")
label.grid(row=0, column=4)
def clear_buttons(self):

View file

@ -585,6 +585,25 @@ class CanvasNode:
self.canvas.itemconfig(self.id, image=self.image)
self.canvas.itemconfig(self.text_id, text=self.core_node.name)
def move(self, x, y):
old_x = self.core_node.position.x
old_y = self.core_node.position.y
x_offset = x - old_x
y_offset = y - old_y
self.core_node.position.x = x
self.core_node.position.y = y
for edge in self.edges:
x1, y1, x2, y2 = self.canvas.coords(edge.id)
if edge.src == self.id:
self.canvas.coords(edge.id, x_offset, y_offset, x2, y2)
else:
self.canvas.coords(edge.id, x1, y1, x_offset, y_offset)
edge.link_info.recalculate_info()
self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans)
self.canvas.move(self.id, x_offset, y_offset)
self.canvas.move(self.text_id, x_offset, y_offset)
self.antenna_draw.update_antennas_position(x_offset, y_offset)
def on_enter(self, event):
if self.app.core.is_runtime() and self.app.core.observer:
self.tooltip.text.set("waiting...")
@ -612,7 +631,6 @@ class CanvasNode:
def click_press(self, event):
logging.debug(f"node click press {self.core_node.name}: {event}")
self.moving = self.canvas.canvas_xy(event)
self.canvas.canvas_management.node_select(self)
def click_release(self, event):

View file

@ -188,7 +188,7 @@
<configuration name="error" value="0"/>
</mobility_configuration>
<mobility_configuration node="10" model="ns2script">
<configuration name="file" value="sample1.scen"/>
<configuration name="file" value="/home/developer/.core/configs/sample1.scen"/>
<configuration name="refresh_ms" value="50"/>
<configuration name="loop" value="1"/>
<configuration name="autostart" value="5"/>