save service config, file config when join session, update progress bar to start, stop, join session, delete antennas, wirelesslink as well as other stuff that we had before when join session

This commit is contained in:
Huy Pham 2019-11-26 11:30:25 -08:00
parent 3493b05eb4
commit fa7e5e321b
7 changed files with 86 additions and 21 deletions

View file

@ -137,8 +137,8 @@ class CoreClient:
)
def join_session(self, session_id, query_location=True):
self.master.config(cursor="watch")
self.master.update()
# self.master.config(cursor="watch")
# self.master.update()
# update session and title
self.session_id = session_id
@ -198,12 +198,36 @@ class CoreClient:
# draw session
self.app.canvas.reset_and_redraw(session)
# draw tool bar appropritate with session state
# get node service config and file config
for node in session.nodes:
self.created_nodes.add(node.id)
for link in session.links:
self.created_links.add(tuple(sorted([link.node_one_id, link.node_two_id])))
for node in session.nodes:
if node.type == core_pb2.NodeType.DEFAULT:
for service in node.services:
response = self.client.get_node_service(
self.session_id, node.id, service
)
if node.id not in self.service_configs:
self.service_configs[node.id] = {}
self.service_configs[node.id][service] = response.service
for file in response.service.configs:
response = self.client.get_node_service_file(
self.session_id, node.id, service, file
)
if node.id not in self.file_configs:
self.file_configs[node.id] = {}
if service not in self.file_configs[node.id]:
self.file_configs[node.id][service] = {}
self.file_configs[node.id][service][file] = response.data
if self.is_runtime():
self.app.toolbar.runtime_frame.tkraise()
else:
self.app.toolbar.design_frame.tkraise()
self.master.config(cursor="")
# self.master.config(cursor="")
self.app.statusbar.progress_bar.stop()
def is_runtime(self):
return self.state == core_pb2.SessionState.RUNTIME
@ -310,7 +334,10 @@ class CoreClient:
def stop_session(self, session_id=None):
if not session_id:
session_id = self.session_id
start = time.time()
response = self.client.stop_session(session_id)
process_time = time.time() - start
self.app.statusbar.stop_session_callback(process_time)
logging.debug("stopped session(%s), result: %s", session_id, response.result)
def launch_terminal(self, node_id):

View file

@ -1,4 +1,5 @@
import logging
import threading
import tkinter as tk
from tkinter import ttk
@ -146,7 +147,11 @@ class SessionsDialog(Dialog):
logging.error("querysessiondrawing.py invalid state")
def join_session(self, session_id):
self.app.core.join_session(session_id)
self.app.statusbar.progress_bar.start(5)
thread = threading.Thread(
target=self.app.core.join_session, args=([session_id])
)
thread.start()
self.destroy()
def on_selected(self, event):

View file

@ -7,7 +7,16 @@ import tkinter as tk
from coretk.images import ImageEnum, Images
from coretk.nodeutils import NodeUtils
CANVAS_COMPONENT_TAGS = ["edge", "node", "nodename", "wallpaper", "linkinfo"]
CANVAS_COMPONENT_TAGS = [
"edge",
"node",
"nodename",
"wallpaper",
"linkinfo",
"antenna",
"wireless",
"selectednodes",
]
class GraphHelper:

View file

@ -3,6 +3,8 @@ The actions taken when each menubar option is clicked
"""
import logging
import threading
import time
import webbrowser
from tkinter import filedialog, messagebox
@ -27,7 +29,16 @@ class MenuAction:
self.master = master
self.app = app
def prompt_save_running_session(self):
def cleanup_old_session(self, quitapp=False):
start = time.time()
self.app.core.stop_session()
self.app.core.delete_session()
process_time = time.time() - start
self.app.statusbar.stop_session_callback(process_time)
if quitapp:
self.app.quit()
def prompt_save_running_session(self, quitapp=False):
"""
Prompt use to stop running session before application is closed
@ -43,13 +54,20 @@ class MenuAction:
or state == core_pb2.SessionState.DEFINITION
):
self.app.core.delete_session()
if quitapp:
self.app.quit()
else:
msgbox = messagebox.askyesnocancel("stop", "Stop the running session?")
if msgbox or msgbox is False:
if msgbox:
self.app.core.stop_session()
self.app.core.delete_session()
self.app.statusbar.progress_bar.start(5)
thread = threading.Thread(
target=self.cleanup_old_session, args=([quitapp])
)
thread.start()
# self.app.core.stop_session()
# self.app.core.delete_session()
def on_quit(self, event=None):
"""
@ -57,8 +75,8 @@ class MenuAction:
:return: nothing
"""
self.prompt_save_running_session()
self.app.quit()
self.prompt_save_running_session(quitapp=True)
# self.app.quit()
def file_save_as_xml(self, event=None):
logging.info("menuaction.py file_save_as_xml()")
@ -81,7 +99,10 @@ class MenuAction:
if file_path:
logging.info("opening xml: %s", file_path)
self.prompt_save_running_session()
self.app.core.open_xml(file_path)
self.app.statusbar.progress_bar.start(5)
thread = threading.Thread(target=self.app.core.open_xml, args=([file_path]))
thread.start()
# self.app.core.open_xml(file_path)
def gui_preferences(self):
dialog = PreferencesDialog(self.app, self.app)

View file

@ -27,7 +27,10 @@ class CanvasComponentManagement:
if canvas_node.id not in self.selected:
x0, y0, x1, y1 = self.canvas.bbox(canvas_node.id)
bbox_id = self.canvas.create_rectangle(
(x0 - 6, y0 - 6, x1 + 6, y1 + 6), activedash=True, dash="-"
(x0 - 6, y0 - 6, x1 + 6, y1 + 6),
activedash=True,
dash="-",
tags="selectednodes",
)
self.selected[canvas_node.id] = bbox_id

View file

@ -47,3 +47,7 @@ class StatusBar(ttk.Frame):
"Network topology instantiated in %s seconds (%s node(s) and %s link(s))"
% ("%.3f" % process_time, num_nodes, num_links)
)
def stop_session_callback(self, cleanup_time):
self.progress_bar.stop()
self.statusvar.set("Cleanup completed in %s seconds" % "%.3f" % cleanup_time)

View file

@ -1,6 +1,5 @@
import logging
import threading
import time
import tkinter as tk
from functools import partial
from tkinter import ttk
@ -354,12 +353,9 @@ class Toolbar(ttk.Frame):
:return: nothing
"""
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.statusbar.progress_bar.start(5)
thread = threading.Thread(target=self.app.core.stop_session)
thread.start()
self.app.canvas.delete("wireless")
self.design_frame.tkraise()