Merge branch 'coretk' into coretk-progress

This commit is contained in:
Huy Pham 2019-11-27 08:51:02 -08:00
commit 15e484c8c2
5 changed files with 70 additions and 22 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,5 +1,7 @@
import tkinter as tk
from tkinter import ttk
from core.api.grpc import core_pb2
from coretk.dialogs.dialog import Dialog
PAD = 5
@ -10,37 +12,51 @@ class MobilityPlayerDialog(Dialog):
super().__init__(
master, app, f"{canvas_node.core_node.name} Mobility Player", modal=False
)
self.canvas_node = canvas_node
self.node = canvas_node.core_node
self.config = self.app.core.mobility_configs[canvas_node.core_node.id]
self.play_button = None
self.pause_button = None
self.stop_button = None
self.progressbar = None
self.draw()
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)
frame.grid(sticky="ew", pady=PAD)
frame.columnconfigure(0, weight=1)
progressbar = ttk.Progressbar(frame, mode="indeterminate")
progressbar.grid(row=0, column=0, sticky="ew", padx=PAD)
progressbar.start()
self.progressbar = ttk.Progressbar(frame, mode="indeterminate")
self.progressbar.grid(row=0, column=0, sticky="ew", padx=PAD)
self.progressbar.start()
label = ttk.Label(frame, text="time")
label.grid(row=0, column=1)
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):
@ -51,11 +67,26 @@ class MobilityPlayerDialog(Dialog):
def click_play(self):
self.clear_buttons()
self.play_button.state(["pressed"])
session_id = self.app.core.session_id
self.app.core.client.mobility_action(
session_id, self.node.id, core_pb2.MobilityAction.START
)
self.progressbar.start()
def click_pause(self):
self.clear_buttons()
self.pause_button.state(["pressed"])
session_id = self.app.core.session_id
self.app.core.client.mobility_action(
session_id, self.node.id, core_pb2.MobilityAction.PAUSE
)
self.progressbar.stop()
def click_stop(self):
self.clear_buttons()
self.stop_button.state(["pressed"])
session_id = self.app.core.session_id
self.app.core.client.mobility_action(
session_id, self.node.id, core_pb2.MobilityAction.STOP
)
self.progressbar.stop()

View file

@ -586,6 +586,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...")
@ -613,7 +632,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

@ -16,7 +16,6 @@ class WirelessConnection:
canvas_node_two = self.core.canvas_nodes[node_two_id]
key = tuple(sorted((node_one_id, node_two_id)))
if key not in self.map:
print("not in map")
x1, y1 = self.canvas.coords(canvas_node_one.id)
x2, y2 = self.canvas.coords(canvas_node_two.id)
wlan_canvas_id = self.canvas.create_line(

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"/>