From 906294b91fe25c81ebc770b43a0e2db5452eea07 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Tue, 29 Dec 2020 11:06:24 +0100 Subject: [PATCH] fixes from contrib --- katrain/__main__.py | 6 +++--- katrain/core/engine.py | 3 +++ katrain/core/utils.py | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/katrain/__main__.py b/katrain/__main__.py index 03fc4f8..40be2ac 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -190,11 +190,11 @@ class KaTrainGui(Screen, KaTrainBase): # update engine status dot if not self.engine or not self.engine.katago_process or self.engine.katago_process.poll() is not None: self.board_controls.engine_status_col = Theme.ENGINE_DOWN_COLOR - elif len(self.engine.queries) == 0: + elif self.engine.is_idle(): self.board_controls.engine_status_col = Theme.ENGINE_READY_COLOR else: self.board_controls.engine_status_col = Theme.ENGINE_BUSY_COLOR - self.board_controls.queries_remaining = len(self.engine.queries) + self.board_controls.queries_remaining = self.engine.queries_remaining() # redraw board/stones if redraw_board: @@ -629,7 +629,7 @@ class KaTrainGui(Screen, KaTrainBase): self.controls.note.focus or self.popup_open or keycode != self.last_key_down - or time.time() - self.last_focus_event < 0.2 # this is here to prevent alt-tab from firing alt or tab + or time.time() - self.last_focus_event < 0.2 # this is here to prevent alt-tab from firing alt or tab ): return if keycode[1] == "alt": diff --git a/katrain/core/engine.py b/katrain/core/engine.py index edd70f4..6417216 100644 --- a/katrain/core/engine.py +++ b/katrain/core/engine.py @@ -159,6 +159,9 @@ class KataGoEngine: def is_idle(self): return not self.queries and self.write_queue.empty() + def queries_remaining(self): + return len(self.queries) + int(not self.write_queue.empty()) + def _read_stderr_thread(self): while self.katago_process is not None: try: diff --git a/katrain/core/utils.py b/katrain/core/utils.py index 0665961..7d01a2e 100644 --- a/katrain/core/utils.py +++ b/katrain/core/utils.py @@ -57,10 +57,14 @@ def find_package_resource(path, silent_errors=False): def pack_floats(float_list): + if float_list is None: + return b"" return struct.pack(f"{len(float_list)}e", *float_list) def unpack_floats(str, num): + if not str: + return None return struct.unpack(f"{num}e", str)