basic status bar, node deletion also remove antenna
This commit is contained in:
parent
4788d7aacc
commit
89dfeae07c
5 changed files with 80 additions and 40 deletions
|
@ -327,7 +327,6 @@ class CoreClient:
|
||||||
emane_config = {x: self.emane_config[x].value for x in self.emane_config}
|
emane_config = {x: self.emane_config[x].value for x in self.emane_config}
|
||||||
else:
|
else:
|
||||||
emane_config = None
|
emane_config = None
|
||||||
print(links)
|
|
||||||
response = self.client.start_session(
|
response = self.client.start_session(
|
||||||
self.session_id,
|
self.session_id,
|
||||||
nodes,
|
nodes,
|
||||||
|
@ -342,6 +341,7 @@ class CoreClient:
|
||||||
file_configs,
|
file_configs,
|
||||||
)
|
)
|
||||||
logging.debug("Start session %s, result: %s", self.session_id, response.result)
|
logging.debug("Start session %s, result: %s", self.session_id, response.result)
|
||||||
|
print(self.servers)
|
||||||
# print(self.client.get_session(self.session_id))
|
# print(self.client.get_session(self.session_id))
|
||||||
|
|
||||||
def stop_session(self):
|
def stop_session(self):
|
||||||
|
|
|
@ -393,6 +393,26 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.canvas_management.delete_selected_nodes()
|
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
|
# delete nodes and link info stored in CanvasGraph object
|
||||||
node_ids = []
|
node_ids = []
|
||||||
for nid in to_delete_nodes:
|
for nid in to_delete_nodes:
|
||||||
|
|
|
@ -88,18 +88,41 @@ class WlanAntennaManager:
|
||||||
"""
|
"""
|
||||||
if self.quantity < 5:
|
if self.quantity < 5:
|
||||||
x, y = self.canvas.coords(self.node_id)
|
x, y = self.canvas.coords(self.node_id)
|
||||||
self.antennas.append(
|
aid = self.canvas.create_image(
|
||||||
self.canvas.create_image(
|
x - 16 + self.offset,
|
||||||
x - 16 + self.offset,
|
y - 23,
|
||||||
y - 16,
|
anchor=tk.CENTER,
|
||||||
anchor=tk.CENTER,
|
image=self.image,
|
||||||
image=self.image,
|
tags="antenna",
|
||||||
tags="antenna",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
# self.canvas.tag_raise("antenna")
|
||||||
|
self.antennas.append(aid)
|
||||||
self.quantity = self.quantity + 1
|
self.quantity = self.quantity + 1
|
||||||
self.offset = self.offset + 8
|
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):
|
def update_antennas_position(self, offset_x, offset_y):
|
||||||
"""
|
"""
|
||||||
redraw antennas of a node according to the new node position
|
redraw antennas of a node according to the new node position
|
||||||
|
@ -108,15 +131,3 @@ class WlanAntennaManager:
|
||||||
"""
|
"""
|
||||||
for i in self.antennas:
|
for i in self.antennas:
|
||||||
self.canvas.move(i, offset_x, offset_y)
|
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)
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"status bar"
|
"status bar"
|
||||||
import time
|
import time
|
||||||
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ class StatusBar(ttk.Frame):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.status = None
|
self.status = None
|
||||||
|
self.statusvar = tk.StringVar()
|
||||||
self.zoom = None
|
self.zoom = None
|
||||||
self.cpu_usage = None
|
self.cpu_usage = None
|
||||||
self.memory = None
|
self.memory = None
|
||||||
|
@ -21,7 +23,8 @@ class StatusBar(ttk.Frame):
|
||||||
self.columnconfigure(1, weight=1)
|
self.columnconfigure(1, weight=1)
|
||||||
self.columnconfigure(2, weight=1)
|
self.columnconfigure(2, weight=1)
|
||||||
self.columnconfigure(3, 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.status.grid(row=0, column=0)
|
||||||
self.zoom = ttk.Label(self, text="zoom")
|
self.zoom = ttk.Label(self, text="zoom")
|
||||||
self.zoom.grid(row=0, column=1)
|
self.zoom.grid(row=0, column=1)
|
||||||
|
@ -31,14 +34,11 @@ class StatusBar(ttk.Frame):
|
||||||
self.emulation_light.grid(row=0, column=3)
|
self.emulation_light.grid(row=0, column=3)
|
||||||
|
|
||||||
def processing(self):
|
def processing(self):
|
||||||
self.running = True
|
|
||||||
texts = ["Processing.", "Processing..", "Processing...", "Processing...."]
|
texts = ["Processing.", "Processing..", "Processing...", "Processing...."]
|
||||||
i = 0
|
i = 0
|
||||||
while self.running is True:
|
while self.running:
|
||||||
self.status.config(text=texts[i % 4])
|
self.statusvar.set(texts[i % 4])
|
||||||
self.app.master.update()
|
self.master.update()
|
||||||
i = i + 1
|
i = i + 1
|
||||||
time.sleep(0.3)
|
time.sleep(0.002)
|
||||||
print("running")
|
|
||||||
print("thread finish")
|
print("thread finish")
|
||||||
# self.status.config(text="status")
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import time
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
@ -196,22 +196,25 @@ class Toolbar(ttk.Frame):
|
||||||
|
|
||||||
:return: nothing
|
: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")
|
self.master.config(cursor="watch")
|
||||||
status_thread = threading.Thread(target=self.app.statusbar.processing)
|
|
||||||
status_thread.start()
|
|
||||||
self.master.update()
|
self.master.update()
|
||||||
self.app.canvas.mode = GraphMode.SELECT
|
self.app.canvas.mode = GraphMode.SELECT
|
||||||
|
start = time.time()
|
||||||
self.app.core.start_session()
|
self.app.core.start_session()
|
||||||
|
dur = time.time() - start
|
||||||
self.runtime_frame.tkraise()
|
self.runtime_frame.tkraise()
|
||||||
self.master.config(cursor="")
|
self.master.config(cursor="")
|
||||||
|
nodes_num = len(self.app.core.canvas_nodes)
|
||||||
self.app.statusbar.running = False
|
links_num = len(self.app.core.links)
|
||||||
if status_thread.is_alive():
|
self.app.statusbar.statusvar.set(
|
||||||
print("still running")
|
"Network topology instantiated in %s seconds (%s node(s) and %s link(s))"
|
||||||
status_thread.join()
|
% ("%.3f" % dur, nodes_num, links_num)
|
||||||
print("thread terminate")
|
)
|
||||||
self.app.statusbar.status.config(text="status")
|
# self.app.statusbar.running = False
|
||||||
|
# print("done")
|
||||||
|
|
||||||
def click_link(self):
|
def click_link(self):
|
||||||
logging.debug("Click LINK button")
|
logging.debug("Click LINK button")
|
||||||
|
@ -365,7 +368,13 @@ class Toolbar(ttk.Frame):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("Click on STOP button ")
|
logging.debug("Click on STOP button ")
|
||||||
|
# self.status_thread.join()
|
||||||
|
start = time.time()
|
||||||
self.app.core.stop_session()
|
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.app.canvas.delete("wireless")
|
||||||
self.design_frame.tkraise()
|
self.design_frame.tkraise()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue