progress bar for start session
This commit is contained in:
parent
a13eb2f214
commit
4238c14362
4 changed files with 33 additions and 37 deletions
|
@ -3,6 +3,7 @@ Incorporate grpc into python tkinter GUI
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
from core.api.grpc import client, core_pb2
|
from core.api.grpc import client, core_pb2
|
||||||
from coretk.dialogs.sessions import SessionsDialog
|
from coretk.dialogs.sessions import SessionsDialog
|
||||||
|
@ -280,6 +281,8 @@ 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
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
response = self.client.start_session(
|
response = self.client.start_session(
|
||||||
self.session_id,
|
self.session_id,
|
||||||
nodes,
|
nodes,
|
||||||
|
@ -293,7 +296,9 @@ class CoreClient:
|
||||||
service_configs,
|
service_configs,
|
||||||
file_configs,
|
file_configs,
|
||||||
)
|
)
|
||||||
|
process_time = time.time() - start
|
||||||
logging.debug("start session(%s), result: %s", self.session_id, response.result)
|
logging.debug("start session(%s), result: %s", self.session_id, response.result)
|
||||||
|
self.app.statusbar.start_session_callback(process_time)
|
||||||
|
|
||||||
def stop_session(self, session_id=None):
|
def stop_session(self, session_id=None):
|
||||||
if not session_id:
|
if not session_id:
|
||||||
|
|
|
@ -197,8 +197,9 @@ class NodeConfigDialog(Dialog):
|
||||||
self.node.name = self.name.get()
|
self.node.name = self.name.get()
|
||||||
if NodeUtils.is_image_node(self.node.type):
|
if NodeUtils.is_image_node(self.node.type):
|
||||||
self.node.image = self.container_image.get()
|
self.node.image = self.container_image.get()
|
||||||
if NodeUtils.is_container_node(self.node.type):
|
server = self.server.get()
|
||||||
self.node.server = self.server.get()
|
if NodeUtils.is_container_node(self.node.type) and server != "localhost":
|
||||||
|
self.node.server = server
|
||||||
|
|
||||||
# update canvas node
|
# update canvas node
|
||||||
self.canvas_node.image = self.image
|
self.canvas_node.image = self.image
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"status bar"
|
"status bar"
|
||||||
import time
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
@ -11,6 +10,7 @@ class StatusBar(ttk.Frame):
|
||||||
|
|
||||||
self.status = None
|
self.status = None
|
||||||
self.statusvar = tk.StringVar()
|
self.statusvar = tk.StringVar()
|
||||||
|
self.progress_bar = None
|
||||||
self.zoom = None
|
self.zoom = None
|
||||||
self.cpu_usage = None
|
self.cpu_usage = None
|
||||||
self.memory = None
|
self.memory = None
|
||||||
|
@ -19,26 +19,31 @@ class StatusBar(ttk.Frame):
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.columnconfigure(0, weight=8)
|
self.columnconfigure(0, weight=1)
|
||||||
self.columnconfigure(1, weight=1)
|
self.columnconfigure(1, weight=7)
|
||||||
self.columnconfigure(2, weight=1)
|
self.columnconfigure(2, weight=1)
|
||||||
self.columnconfigure(3, weight=1)
|
self.columnconfigure(3, weight=1)
|
||||||
|
self.columnconfigure(4, weight=1)
|
||||||
|
|
||||||
|
self.progress_bar = ttk.Progressbar(
|
||||||
|
self, orient="horizontal", mode="indeterminate"
|
||||||
|
)
|
||||||
|
self.progress_bar.grid(row=0, column=0, sticky="nsew")
|
||||||
self.status = ttk.Label(self, textvariable=self.statusvar)
|
self.status = ttk.Label(self, textvariable=self.statusvar)
|
||||||
self.statusvar.set("status")
|
self.statusvar.set("status")
|
||||||
self.status.grid(row=0, column=0)
|
self.status.grid(row=0, column=1, sticky="nsew")
|
||||||
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=2)
|
||||||
self.cpu_usage = ttk.Label(self, text="cpu usage")
|
self.cpu_usage = ttk.Label(self, text="cpu usage")
|
||||||
self.cpu_usage.grid(row=0, column=2)
|
self.cpu_usage.grid(row=0, column=3)
|
||||||
self.emulation_light = ttk.Label(self, text="emulation light")
|
self.emulation_light = ttk.Label(self, text="emulation light")
|
||||||
self.emulation_light.grid(row=0, column=3)
|
self.emulation_light.grid(row=0, column=4)
|
||||||
|
|
||||||
def processing(self):
|
def start_session_callback(self, process_time):
|
||||||
texts = ["Processing.", "Processing..", "Processing...", "Processing...."]
|
num_nodes = len(self.app.core.canvas_nodes)
|
||||||
i = 0
|
num_links = len(self.app.core.links)
|
||||||
while self.running:
|
self.progress_bar.stop()
|
||||||
self.statusvar.set(texts[i % 4])
|
self.statusvar.set(
|
||||||
self.master.update()
|
"Network topology instantiated in %s seconds (%s node(s) and %s link(s))"
|
||||||
i = i + 1
|
% ("%.3f" % process_time, num_nodes, num_links)
|
||||||
time.sleep(0.002)
|
)
|
||||||
print("thread finish")
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -196,25 +197,11 @@ class Toolbar(ttk.Frame):
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
self.app.statusbar.running = True
|
self.app.statusbar.progress_bar.start(5)
|
||||||
# thread = threading.Thread(target=self.app.statusbar.processing)
|
|
||||||
# thread.start()
|
|
||||||
self.master.config(cursor="watch")
|
|
||||||
self.master.update()
|
|
||||||
self.app.canvas.mode = GraphMode.SELECT
|
self.app.canvas.mode = GraphMode.SELECT
|
||||||
start = time.time()
|
thread = threading.Thread(target=self.app.core.start_session)
|
||||||
self.app.core.start_session()
|
thread.start()
|
||||||
dur = time.time() - start
|
|
||||||
self.runtime_frame.tkraise()
|
self.runtime_frame.tkraise()
|
||||||
self.master.config(cursor="")
|
|
||||||
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):
|
def click_link(self):
|
||||||
logging.debug("Click LINK button")
|
logging.debug("Click LINK button")
|
||||||
|
@ -367,8 +354,6 @@ class Toolbar(ttk.Frame):
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("Click on STOP button ")
|
|
||||||
# self.status_thread.join()
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
self.app.core.stop_session()
|
self.app.core.stop_session()
|
||||||
dur = time.time() - start
|
dur = time.time() - start
|
||||||
|
|
Loading…
Reference in a new issue