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 os
|
||||
import time
|
||||
|
||||
from core.api.grpc import client, core_pb2
|
||||
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}
|
||||
else:
|
||||
emane_config = None
|
||||
|
||||
start = time.time()
|
||||
response = self.client.start_session(
|
||||
self.session_id,
|
||||
nodes,
|
||||
|
@ -293,7 +296,9 @@ class CoreClient:
|
|||
service_configs,
|
||||
file_configs,
|
||||
)
|
||||
process_time = time.time() - start
|
||||
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):
|
||||
if not session_id:
|
||||
|
|
|
@ -197,8 +197,9 @@ class NodeConfigDialog(Dialog):
|
|||
self.node.name = self.name.get()
|
||||
if NodeUtils.is_image_node(self.node.type):
|
||||
self.node.image = self.container_image.get()
|
||||
if NodeUtils.is_container_node(self.node.type):
|
||||
self.node.server = self.server.get()
|
||||
server = self.server.get()
|
||||
if NodeUtils.is_container_node(self.node.type) and server != "localhost":
|
||||
self.node.server = server
|
||||
|
||||
# update canvas node
|
||||
self.canvas_node.image = self.image
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"status bar"
|
||||
import time
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
@ -11,6 +10,7 @@ class StatusBar(ttk.Frame):
|
|||
|
||||
self.status = None
|
||||
self.statusvar = tk.StringVar()
|
||||
self.progress_bar = None
|
||||
self.zoom = None
|
||||
self.cpu_usage = None
|
||||
self.memory = None
|
||||
|
@ -19,26 +19,31 @@ class StatusBar(ttk.Frame):
|
|||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
self.columnconfigure(0, weight=8)
|
||||
self.columnconfigure(1, weight=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.columnconfigure(1, weight=7)
|
||||
self.columnconfigure(2, 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.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.grid(row=0, column=1)
|
||||
self.zoom.grid(row=0, column=2)
|
||||
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.grid(row=0, column=3)
|
||||
self.emulation_light.grid(row=0, column=4)
|
||||
|
||||
def processing(self):
|
||||
texts = ["Processing.", "Processing..", "Processing...", "Processing...."]
|
||||
i = 0
|
||||
while self.running:
|
||||
self.statusvar.set(texts[i % 4])
|
||||
self.master.update()
|
||||
i = i + 1
|
||||
time.sleep(0.002)
|
||||
print("thread finish")
|
||||
def start_session_callback(self, process_time):
|
||||
num_nodes = len(self.app.core.canvas_nodes)
|
||||
num_links = len(self.app.core.links)
|
||||
self.progress_bar.stop()
|
||||
self.statusvar.set(
|
||||
"Network topology instantiated in %s seconds (%s node(s) and %s link(s))"
|
||||
% ("%.3f" % process_time, num_nodes, num_links)
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import threading
|
||||
import time
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
|
@ -196,25 +197,11 @@ class Toolbar(ttk.Frame):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
self.app.statusbar.running = True
|
||||
# thread = threading.Thread(target=self.app.statusbar.processing)
|
||||
# thread.start()
|
||||
self.master.config(cursor="watch")
|
||||
self.master.update()
|
||||
self.app.statusbar.progress_bar.start(5)
|
||||
self.app.canvas.mode = GraphMode.SELECT
|
||||
start = time.time()
|
||||
self.app.core.start_session()
|
||||
dur = time.time() - start
|
||||
thread = threading.Thread(target=self.app.core.start_session)
|
||||
thread.start()
|
||||
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):
|
||||
logging.debug("Click LINK button")
|
||||
|
@ -367,8 +354,6 @@ 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
|
||||
|
|
Loading…
Reference in a new issue