gui: improved throughputs start/stop to coincide with session start and stop based on a tracked variable

This commit is contained in:
Blake Harnden 2022-10-12 20:53:59 -07:00
parent 03775c2c3c
commit e0a21fb099
2 changed files with 17 additions and 7 deletions

View file

@ -70,6 +70,9 @@ class CoreClient:
self.session: Optional[Session] = None self.session: Optional[Session] = None
self.user = getpass.getuser() self.user = getpass.getuser()
# menu options
self.show_throughputs: tk.BooleanVar = tk.BooleanVar(value=False)
# global service settings # global service settings
self.services: Dict[str, Set[str]] = {} self.services: Dict[str, Set[str]] = {}
self.config_services_groups: Dict[str, Set[str]] = {} self.config_services_groups: Dict[str, Set[str]] = {}
@ -242,6 +245,7 @@ class CoreClient:
logger.warning("unknown node event: %s", event) logger.warning("unknown node event: %s", event)
def enable_throughputs(self) -> None: def enable_throughputs(self) -> None:
if not self.handling_throughputs:
self.handling_throughputs = self.client.throughputs( self.handling_throughputs = self.client.throughputs(
self.session.id, self.handle_throughputs self.session.id, self.handle_throughputs
) )
@ -431,13 +435,15 @@ class CoreClient:
definition, definition,
result, result,
) )
if self.show_throughputs.get():
self.enable_throughputs()
except grpc.RpcError as e: except grpc.RpcError as e:
self.app.show_grpc_exception("Start Session Error", e) self.app.show_grpc_exception("Start Session Error", e)
return result, exceptions return result, exceptions
def stop_session(self, session_id: int = None) -> bool: def stop_session(self, session_id: int = None) -> bool:
if not session_id: session_id = session_id or self.session.id
session_id = self.session.id self.cancel_throughputs()
result = False result = False
try: try:
result = self.client.stop_session(session_id) result = self.client.stop_session(session_id)

View file

@ -235,7 +235,11 @@ class Menubar(tk.Menu):
menu.add_command( menu.add_command(
label="Configure Throughput", command=self.click_config_throughput label="Configure Throughput", command=self.click_config_throughput
) )
menu.add_checkbutton(label="Enable Throughput?", command=self.click_throughput) menu.add_checkbutton(
label="Enable Throughput?",
command=self.click_throughput,
variable=self.core.show_throughputs,
)
widget_menu.add_cascade(label="Throughput", menu=menu) widget_menu.add_cascade(label="Throughput", menu=menu)
def draw_widgets_menu(self) -> None: def draw_widgets_menu(self) -> None:
@ -393,7 +397,7 @@ class Menubar(tk.Menu):
dialog.show() dialog.show()
def click_throughput(self) -> None: def click_throughput(self) -> None:
if not self.core.handling_throughputs: if self.core.show_throughputs.get():
self.core.enable_throughputs() self.core.enable_throughputs()
else: else:
self.core.cancel_throughputs() self.core.cancel_throughputs()