basic status bar, node deletion also remove antenna

This commit is contained in:
Huy Pham 2019-11-25 11:23:04 -08:00
parent 4788d7aacc
commit 89dfeae07c
5 changed files with 80 additions and 40 deletions

View file

@ -327,7 +327,6 @@ class CoreClient:
emane_config = {x: self.emane_config[x].value for x in self.emane_config}
else:
emane_config = None
print(links)
response = self.client.start_session(
self.session_id,
nodes,
@ -342,6 +341,7 @@ class CoreClient:
file_configs,
)
logging.debug("Start session %s, result: %s", self.session_id, response.result)
print(self.servers)
# print(self.client.get_session(self.session_id))
def stop_session(self):

View file

@ -393,6 +393,26 @@ class CanvasGraph(tk.Canvas):
self.canvas_management.delete_selected_nodes()
)
# delete antennas
for cnid in to_delete_nodes:
canvas_node = self.nodes[cnid]
if canvas_node.core_node.type != core_pb2.NodeType.WIRELESS_LAN:
canvas_node.antenna_draw.delete_antennas()
else:
for e in canvas_node.edges:
link_proto = self.core.links[e.token]
node_one_id, node_two_id = (
link_proto.node_one_id,
link_proto.node_two_id,
)
if node_one_id == canvas_node.core_node.id:
neighbor_id = node_two_id
else:
neighbor_id = node_one_id
neighbor = self.core.canvas_nodes[neighbor_id]
if neighbor.core_node.type != core_pb2.NodeType.WIRELESS_LAN:
neighbor.antenna_draw.delete_antenna()
# delete nodes and link info stored in CanvasGraph object
node_ids = []
for nid in to_delete_nodes:

View file

@ -88,18 +88,41 @@ class WlanAntennaManager:
"""
if self.quantity < 5:
x, y = self.canvas.coords(self.node_id)
self.antennas.append(
self.canvas.create_image(
x - 16 + self.offset,
y - 16,
anchor=tk.CENTER,
image=self.image,
tags="antenna",
)
aid = self.canvas.create_image(
x - 16 + self.offset,
y - 23,
anchor=tk.CENTER,
image=self.image,
tags="antenna",
)
# self.canvas.tag_raise("antenna")
self.antennas.append(aid)
self.quantity = self.quantity + 1
self.offset = self.offset + 8
def delete_antenna(self):
"""
delete one antenna
:return: nothing
"""
if len(self.antennas) > 0:
self.canvas.delete(self.antennas.pop())
self.quantity -= 1
self.offset -= 8
def delete_antennas(self):
"""
delete all antennas
:return: nothing
"""
for aid in self.antennas:
self.canvas.delete(aid)
self.antennas.clear()
self.quantity = 0
self.offset = 0
def update_antennas_position(self, offset_x, offset_y):
"""
redraw antennas of a node according to the new node position
@ -108,15 +131,3 @@ class WlanAntennaManager:
"""
for i in self.antennas:
self.canvas.move(i, offset_x, offset_y)
def delete_antenna(self, canvas_id):
return
def delete_antennas(self):
"""
Delete all the antennas of a node
:return: nothing
"""
for i in self.antennas:
self.canvas.delete(i)

View file

@ -1,5 +1,6 @@
"status bar"
import time
import tkinter as tk
from tkinter import ttk
@ -9,6 +10,7 @@ class StatusBar(ttk.Frame):
self.app = app
self.status = None
self.statusvar = tk.StringVar()
self.zoom = None
self.cpu_usage = None
self.memory = None
@ -21,7 +23,8 @@ class StatusBar(ttk.Frame):
self.columnconfigure(1, weight=1)
self.columnconfigure(2, weight=1)
self.columnconfigure(3, weight=1)
self.status = ttk.Label(self, text="status")
self.status = ttk.Label(self, textvariable=self.statusvar)
self.statusvar.set("status")
self.status.grid(row=0, column=0)
self.zoom = ttk.Label(self, text="zoom")
self.zoom.grid(row=0, column=1)
@ -31,14 +34,11 @@ class StatusBar(ttk.Frame):
self.emulation_light.grid(row=0, column=3)
def processing(self):
self.running = True
texts = ["Processing.", "Processing..", "Processing...", "Processing...."]
i = 0
while self.running is True:
self.status.config(text=texts[i % 4])
self.app.master.update()
while self.running:
self.statusvar.set(texts[i % 4])
self.master.update()
i = i + 1
time.sleep(0.3)
print("running")
time.sleep(0.002)
print("thread finish")
# self.status.config(text="status")

View file

@ -1,5 +1,5 @@
import logging
import threading
import time
import tkinter as tk
from functools import partial
from tkinter import ttk
@ -196,22 +196,25 @@ class Toolbar(ttk.Frame):
:return: nothing
"""
logging.debug("clicked start button")
self.app.statusbar.running = True
# thread = threading.Thread(target=self.app.statusbar.processing)
# thread.start()
self.master.config(cursor="watch")
status_thread = threading.Thread(target=self.app.statusbar.processing)
status_thread.start()
self.master.update()
self.app.canvas.mode = GraphMode.SELECT
start = time.time()
self.app.core.start_session()
dur = time.time() - start
self.runtime_frame.tkraise()
self.master.config(cursor="")
self.app.statusbar.running = False
if status_thread.is_alive():
print("still running")
status_thread.join()
print("thread terminate")
self.app.statusbar.status.config(text="status")
nodes_num = len(self.app.core.canvas_nodes)
links_num = len(self.app.core.links)
self.app.statusbar.statusvar.set(
"Network topology instantiated in %s seconds (%s node(s) and %s link(s))"
% ("%.3f" % dur, nodes_num, links_num)
)
# self.app.statusbar.running = False
# print("done")
def click_link(self):
logging.debug("Click LINK button")
@ -365,7 +368,13 @@ class Toolbar(ttk.Frame):
:return: nothing
"""
logging.debug("Click on STOP button ")
# self.status_thread.join()
start = time.time()
self.app.core.stop_session()
dur = time.time() - start
self.app.statusbar.statusvar.set(
"Cleanup completed in %s seconds" % "%.3f" % dur
)
self.app.canvas.delete("wireless")
self.design_frame.tkraise()