pygui: improvements to handling grpc events and updating gui
This commit is contained in:
parent
433fe4ae58
commit
df03f1e173
1 changed files with 7 additions and 3 deletions
|
@ -4,9 +4,10 @@ Incorporate grpc into python tkinter GUI
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional
|
from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Optional
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ class CoreClient:
|
||||||
self.cancel_events()
|
self.cancel_events()
|
||||||
self._client.create_session(self.session_id)
|
self._client.create_session(self.session_id)
|
||||||
self.handling_events = self._client.events(
|
self.handling_events = self._client.events(
|
||||||
self.session_id, self.handle_events
|
self.session_id, self.handle_stream(self.handle_events)
|
||||||
)
|
)
|
||||||
if throughputs_enabled:
|
if throughputs_enabled:
|
||||||
self.enable_throughputs()
|
self.enable_throughputs()
|
||||||
|
@ -126,6 +127,9 @@ class CoreClient:
|
||||||
for observer in self.app.guiconfig.observers:
|
for observer in self.app.guiconfig.observers:
|
||||||
self.custom_observers[observer.name] = observer
|
self.custom_observers[observer.name] = observer
|
||||||
|
|
||||||
|
def handle_stream(self, func: Callable) -> Callable:
|
||||||
|
return partial(self.app.after, 0, func)
|
||||||
|
|
||||||
def handle_events(self, event: core_pb2.Event):
|
def handle_events(self, event: core_pb2.Event):
|
||||||
if event.session_id != self.session_id:
|
if event.session_id != self.session_id:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
|
@ -199,7 +203,7 @@ class CoreClient:
|
||||||
|
|
||||||
def enable_throughputs(self):
|
def enable_throughputs(self):
|
||||||
self.handling_throughputs = self.client.throughputs(
|
self.handling_throughputs = self.client.throughputs(
|
||||||
self.session_id, self.handle_throughputs
|
self.session_id, self.handle_stream(self.handle_throughputs)
|
||||||
)
|
)
|
||||||
|
|
||||||
def cancel_throughputs(self):
|
def cancel_throughputs(self):
|
||||||
|
|
Loading…
Reference in a new issue