From e9593b6bc6d85f0e0486668626ed5c7f9e2f36c2 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sat, 5 Sep 2020 10:57:07 +0200 Subject: [PATCH 1/6] spinner --- katrain/gui/badukpan.py | 13 +++++++------ katrain/gui/kivyutils.py | 29 ++++++++++++++++++++++------- katrain/gui/popups.py | 30 ++++++++++++++++++++++-------- katrain/popups.kv | 7 +++---- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/katrain/gui/badukpan.py b/katrain/gui/badukpan.py index 4c4221a..535970b 100644 --- a/katrain/gui/badukpan.py +++ b/katrain/gui/badukpan.py @@ -452,7 +452,6 @@ class BadukPanWidget(Widget): width=dp(1.2), ) - # children of current moves in undo / review alpha = GHOST_ALPHA if katrain.analysis_controls.show_children.active: @@ -465,12 +464,14 @@ class BadukPanWidget(Widget): (move.coords, [move.gtp()] + child_node.candidate_moves[0]["pv"], current_node) ) Color(*STONE_COLORS[child_node.player]) - for s in range(0,360,30): + for s in range(0, 360, 30): Line( circle=( self.gridpos_x[move.coords[0]], self.gridpos_y[move.coords[1]], - self.stone_size - 1.2,s,s+15 + self.stone_size - 1.2, + s, + s + 12, ), width=dp(1.2), ) @@ -520,9 +521,9 @@ class BadukPanWidget(Widget): stone_size = self.stone_size * sizefac Color(1, 1, 1, 1) - Rectangle( - pos=(board_coords[0] - stone_size, board_coords[1] - stone_size), - size=(2 * stone_size, 2 * stone_size), + Rectangle( # not sure why the -1 here, but seems to center better + pos=(board_coords[0] - stone_size - 1, board_coords[1] - stone_size), + size=(2 * stone_size + 1, 2 * stone_size + 1), source=f"img/{move_player}_stone.png", ) Color(*STONE_TEXT_COLORS[move_player]) diff --git a/katrain/gui/kivyutils.py b/katrain/gui/kivyutils.py index 678759c..f03b1b8 100644 --- a/katrain/gui/kivyutils.py +++ b/katrain/gui/kivyutils.py @@ -205,7 +205,7 @@ class IMETextField(MDTextField): self._imo_cursor = self.cursor -class I18NSpinner(Spinner): +class KeyValueSpinner(Spinner): __events__ = ["on_select"] sync_height_frac = NumericProperty(1.0) value_refs = ListProperty() @@ -214,9 +214,8 @@ class I18NSpinner(Spinner): def __init__(self, **kwargs): super().__init__(**kwargs) - self.bind(size=self.update_dropdown_props, pos=self.update_dropdown_props, value_refs=self.i18n_values) - self.i18n_values() - MDApp.get_running_app().bind(language=self.i18n_values) + self.build_values() + self.bind(size=self.update_dropdown_props, pos=self.update_dropdown_props, value_refs=self.build_values) @property def selected(self): @@ -245,9 +244,8 @@ class I18NSpinner(Spinner): except (ValueError, IndexError): pass - def i18n_values(self, *_args): - if self.value_refs: - self.values = [i18n._(ref) for ref in self.value_refs] + def build_values(self, *_args): + if self.value_refs and self.values: self.text = self.values[self.selected_index] self.font_name = i18n.font_name self.update_dropdown_props() @@ -269,6 +267,23 @@ class I18NSpinner(Spinner): item.font_name = self.font_name +class I18NSpinner(KeyValueSpinner): + __events__ = ["on_select"] + sync_height_frac = NumericProperty(1.0) + value_refs = ListProperty() + selected_index = NumericProperty(0) + font_name = StringProperty(DEFAULT_FONT) + + def __init__(self, **kwargs): + super().__init__(**kwargs) + MDApp.get_running_app().bind(language=self.build_values) + + def build_values(self, *_args): + self.values = [i18n._(ref) for ref in self.value_refs] + super().build_values() + + + class PlayerSetup(MDBoxLayout): player = OptionProperty("B", options=["B", "W"]) mode = StringProperty("") diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 8b776d0..53f2009 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -412,8 +412,17 @@ class ConfigPopup(QuickConfigGui): self.model_files.text = models_available_msg def check_katas(self, *args): + def find_description(path): + file = os.path.split(path)[1].replace(".exe", "") + file_to_desc = {kg.replace(".zip", ""): desc for _, kgs in self.KATAGOS.items() for desc, kg in kgs.items()} + print(file_to_desc,file) + if file in file_to_desc: + return f"{file_to_desc[file]} ({path})" + else: + return f"unkn {path}" + done = set() - model_files = [] + kata_files = [] for path in self.katago_paths + [self.katago_path.text]: path = path.rstrip("/\\") if path.startswith("katrain"): @@ -433,11 +442,14 @@ class ConfigPopup(QuickConfigGui): ] if files and path not in self.paths: self.paths.append(path) # persistent on paths with models found - model_files += files - katas_available_msg = i18n._("katago binaries available").format(num=len(model_files)) - self.katago_files.values = [katas_available_msg, i18n._("default katago option")] + sorted( - model_files, key=lambda f: "bs29" in f - ) + kata_files += files + + kata_files = [(path, find_description(path)) for path in sorted(kata_files, key=lambda f: "bs29" in f)] + katas_available_msg = i18n._("katago binaries available").format(num=len(kata_files)) + self.katago_files.values = [katas_available_msg, i18n._("default katago option")] + [ + path for path, desc in kata_files + ] + self.katago_files.value_keys = ["", ""] + [desc for path, desc in kata_files] self.katago_files.text = katas_available_msg MODELS = { @@ -449,18 +461,20 @@ class ConfigPopup(QuickConfigGui): KATAGOS = { "win": { "OpenCL v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-opencl-windows-x64.zip", - # "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-windows-x64.zip", "Eigen AVX2 (Modern CPUs) v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-cpu-eigen-avx2-windows-x64.zip", "Eigen (CPU, Non-optimized) v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-cpu-eigen-windows-x64.zip", "OpenCL v1.6.1 (bigger boards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1%2Bbs29/katago-v1.6.1+bs29-gpu-opencl-windows-x64.zip", }, "linux": { "OpenCL v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-opencl-linux-x64.zip", - # "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-linux-x64.zip", "Eigen AVX2 (Modern CPUs) v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-cpu-eigen-avx2-linux-x64.zip", "Eigen (CPU, Non-optimized) v1.6.1": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-cpu-eigen-linux-x64.zip", "OpenCL v1.6.1 (bigger boards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1%2Bbs29/katago-v1.6.1+bs29-gpu-opencl-linux-x64.zip", }, + "just-descriptions": { + "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-windows-x64.zip", + "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-linux-x64.zip", + }, } def download_models(self, *_largs): diff --git a/katrain/popups.kv b/katrain/popups.kv index 5522888..0dedc90 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -109,12 +109,11 @@ on_press: root.download_katas() size_hint_y: 0.7 AnchorLayout: - Spinner: + KeyValueSpinner: id: katago_files text: '' - on_text: - if self.text and self.text == self.values[1]: katago_path.text = '' - elif self.text and self.text != self.values[0]: katago_path.text = args[1] + on_select: + if self.selected_index != 0: katago_path.text = self.values[self.selected_index] size_hint_y: 0.7 sync_height_frac: 1.0 -font_size: self.height * 0.5 From f035627b1d626c45a90c5e1ed8477f26303b543a Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sat, 5 Sep 2020 16:35:57 +0200 Subject: [PATCH 2/6] fix kv spinner --- katrain/gui/popups.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 53f2009..024e71f 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -414,12 +414,12 @@ class ConfigPopup(QuickConfigGui): def check_katas(self, *args): def find_description(path): file = os.path.split(path)[1].replace(".exe", "") - file_to_desc = {kg.replace(".zip", ""): desc for _, kgs in self.KATAGOS.items() for desc, kg in kgs.items()} + file_to_desc = {re.match(r".*/([^/]+)",kg)[1].replace('.zip',''): desc for _, kgs in self.KATAGOS.items() for desc, kg in kgs.items()} print(file_to_desc,file) if file in file_to_desc: - return f"{file_to_desc[file]} ({path})" + return f"{file_to_desc[file]} - {path}" else: - return f"unkn {path}" + return path done = set() kata_files = [] @@ -447,9 +447,9 @@ class ConfigPopup(QuickConfigGui): kata_files = [(path, find_description(path)) for path in sorted(kata_files, key=lambda f: "bs29" in f)] katas_available_msg = i18n._("katago binaries available").format(num=len(kata_files)) self.katago_files.values = [katas_available_msg, i18n._("default katago option")] + [ - path for path, desc in kata_files + desc for path, desc in kata_files ] - self.katago_files.value_keys = ["", ""] + [desc for path, desc in kata_files] + self.katago_files.value_keys = ["", ""] + [path for path, desc in kata_files] self.katago_files.text = katas_available_msg MODELS = { From 58f91072ebaa54ed3a597467443a380e7e8740aa Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sat, 5 Sep 2020 17:01:44 +0200 Subject: [PATCH 3/6] hmm --- katrain/gui/kivyutils.py | 5 +++-- katrain/gui/popups.py | 10 +++++----- katrain/popups.kv | 9 ++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/katrain/gui/kivyutils.py b/katrain/gui/kivyutils.py index f03b1b8..0d00ca3 100644 --- a/katrain/gui/kivyutils.py +++ b/katrain/gui/kivyutils.py @@ -211,7 +211,7 @@ class KeyValueSpinner(Spinner): value_refs = ListProperty() selected_index = NumericProperty(0) font_name = StringProperty(DEFAULT_FONT) - + no_update = BooleanProperty(False) def __init__(self, **kwargs): super().__init__(**kwargs) self.build_values() @@ -230,9 +230,10 @@ class KeyValueSpinner(Spinner): new_index = self.values.index(text) if new_index != self.selected_index: self.selected_index = new_index - self.dispatch("on_select") + return self.dispatch("on_select") except (ValueError, IndexError): pass + return not self.no_update def on_select(self, *args): pass diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 024e71f..74651a6 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -453,9 +453,9 @@ class ConfigPopup(QuickConfigGui): self.katago_files.text = katas_available_msg MODELS = { - "latest 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz", - "latest 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz", - "latest 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz", + "Latest 20 block model": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz", + "Latest 30 block model": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz", + "Latest 40 block model": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz", } KATAGOS = { @@ -472,8 +472,8 @@ class ConfigPopup(QuickConfigGui): "OpenCL v1.6.1 (bigger boards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1%2Bbs29/katago-v1.6.1+bs29-gpu-opencl-linux-x64.zip", }, "just-descriptions": { - "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-windows-x64.zip", - "CUDA v1.6.1 (New NVIDIA cards)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-linux-x64.zip", + "CUDA v1.6.1 (Windows)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-windows-x64.zip", + "CUDA v1.6.1 (Linux)": "https://github.com/lightvector/KataGo/releases/download/v1.6.1/katago-v1.6.1-gpu-cuda10.2-linux-x64.zip", }, } diff --git a/katrain/popups.kv b/katrain/popups.kv index 0dedc90..6bb7d5c 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -112,8 +112,9 @@ KeyValueSpinner: id: katago_files text: '' + no_update: True on_select: - if self.selected_index != 0: katago_path.text = self.values[self.selected_index] + if self.selected_index != 0: katago_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 sync_height_frac: 1.0 -font_size: self.height * 0.5 @@ -139,10 +140,12 @@ on_press: root.download_models() size_hint_y: 0.7 AnchorLayout: - Spinner: + KeyValueSpinner: id: model_files text: '' - on_text: if self.text and self.text != self.values[0]: model_path.text = args[1] + no_update: True + on_select: + if self.selected_index != 0: katago_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 sync_height_frac: 1.0 -font_size: self.height * 0.5 From f947835e6468f3e01b8f9c6293ee47cc0d27afea Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sun, 6 Sep 2020 21:33:01 +0200 Subject: [PATCH 4/6] models --- katrain/__main__.py | 2 +- katrain/core/game_node.py | 3 --- katrain/gui/kivyutils.py | 2 +- katrain/gui/popups.py | 28 +++++++++++++++++++++++++--- katrain/popups.kv | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/katrain/__main__.py b/katrain/__main__.py index ee5d2c8..a667637 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -288,7 +288,7 @@ class KaTrainGui(Screen, KaTrainBase): def _do_resign(self): self.game.current_node.end_state = f"{self.game.current_node.player}+R" - self.log(self.game.current_node.end_state,OUTPUT_INFO) + self.log(self.game.current_node.end_state, OUTPUT_INFO) def _do_redo(self, n_times=1): self.board_gui.animating_pv = None diff --git a/katrain/core/game_node.py b/katrain/core/game_node.py index c4afc3b..502c8bb 100644 --- a/katrain/core/game_node.py +++ b/katrain/core/game_node.py @@ -263,6 +263,3 @@ class GameNode(SGFNode): moves = [(policy_grid[y][x], Move((x, y), player=self.next_player)) for x in range(szx) for y in range(szy)] moves.append((self.policy[-1], Move(None, player=self.next_player))) return sorted(moves, key=lambda mp: -mp[0]) - - - diff --git a/katrain/gui/kivyutils.py b/katrain/gui/kivyutils.py index 0d00ca3..1227ad7 100644 --- a/katrain/gui/kivyutils.py +++ b/katrain/gui/kivyutils.py @@ -212,6 +212,7 @@ class KeyValueSpinner(Spinner): selected_index = NumericProperty(0) font_name = StringProperty(DEFAULT_FONT) no_update = BooleanProperty(False) + def __init__(self, **kwargs): super().__init__(**kwargs) self.build_values() @@ -284,7 +285,6 @@ class I18NSpinner(KeyValueSpinner): super().build_values() - class PlayerSetup(MDBoxLayout): player = OptionProperty("B", options=["B", "W"]) mode = StringProperty("") diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 74651a6..43a108c 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -386,6 +386,18 @@ class ConfigPopup(QuickConfigGui): super().build_and_set_properties() def check_models(self, *args): + def find_description(path): + file = os.path.split(path)[1] + file_to_desc = { + re.match(r".*/([^/]+)", model)[1].replace(".zip", ".bin.gz"): desc + for mods in [self.MODELS, self.MODEL_DESC] + for desc, model in mods.items() + } + if file in file_to_desc: + return f"{file_to_desc[file]} - {path}" + else: + return path + done = set() model_files = [] for path in self.paths + [self.model_path.text]: @@ -407,15 +419,21 @@ class ConfigPopup(QuickConfigGui): if files and path not in self.paths: self.paths.append(path) # persistent on paths with models found model_files += files + + model_files = sorted([(find_description(path), path) for path in model_files]) models_available_msg = i18n._("models available").format(num=len(model_files)) - self.model_files.values = [models_available_msg] + model_files + self.model_files.values = [models_available_msg] + [desc for desc, path in model_files] + self.model_files.value_keys = [""] + [path for desc, path in model_files] self.model_files.text = models_available_msg def check_katas(self, *args): def find_description(path): file = os.path.split(path)[1].replace(".exe", "") - file_to_desc = {re.match(r".*/([^/]+)",kg)[1].replace('.zip',''): desc for _, kgs in self.KATAGOS.items() for desc, kg in kgs.items()} - print(file_to_desc,file) + file_to_desc = { + re.match(r".*/([^/]+)", kg)[1].replace(".zip", ""): desc + for _, kgs in self.KATAGOS.items() + for desc, kg in kgs.items() + } if file in file_to_desc: return f"{file_to_desc[file]} - {path}" else: @@ -457,6 +475,10 @@ class ConfigPopup(QuickConfigGui): "Latest 30 block model": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz", "Latest 40 block model": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz", } + MODEL_DESC = { + "Fat 40 block model": "https://d3dndmfyhecmj0.cloudfront.net/g170/neuralnets/g170e-b40c384x2-s2348692992-d1229892979.zip", + "Latest 15 block model": "https://d3dndmfyhecmj0.cloudfront.net/g170/neuralnets/g170e-b15c192-s1672170752-d466197061.bin.gz", + } KATAGOS = { "win": { diff --git a/katrain/popups.kv b/katrain/popups.kv index 6bb7d5c..b7b1363 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -145,7 +145,7 @@ text: '' no_update: True on_select: - if self.selected_index != 0: katago_path.text = self.value_keys[self.selected_index] + if self.selected_index != 0: model_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 sync_height_frac: 1.0 -font_size: self.height * 0.5 From c25ae5ae5e1cd35045f15e03c4dd931d2fec4b1c Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sun, 6 Sep 2020 21:40:25 +0200 Subject: [PATCH 5/6] hmm --- katrain/gui/kivyutils.py | 4 +--- katrain/popups.kv | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/katrain/gui/kivyutils.py b/katrain/gui/kivyutils.py index 1227ad7..1cd1521 100644 --- a/katrain/gui/kivyutils.py +++ b/katrain/gui/kivyutils.py @@ -211,7 +211,6 @@ class KeyValueSpinner(Spinner): value_refs = ListProperty() selected_index = NumericProperty(0) font_name = StringProperty(DEFAULT_FONT) - no_update = BooleanProperty(False) def __init__(self, **kwargs): super().__init__(**kwargs) @@ -231,10 +230,9 @@ class KeyValueSpinner(Spinner): new_index = self.values.index(text) if new_index != self.selected_index: self.selected_index = new_index - return self.dispatch("on_select") + self.dispatch("on_select") except (ValueError, IndexError): pass - return not self.no_update def on_select(self, *args): pass diff --git a/katrain/popups.kv b/katrain/popups.kv index b7b1363..b497fc1 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -112,7 +112,6 @@ KeyValueSpinner: id: katago_files text: '' - no_update: True on_select: if self.selected_index != 0: katago_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 @@ -143,7 +142,6 @@ KeyValueSpinner: id: model_files text: '' - no_update: True on_select: if self.selected_index != 0: model_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 From d6083e6a60b340c8275b96ab1988df3db26d5c92 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sun, 6 Sep 2020 22:07:07 +0200 Subject: [PATCH 6/6] clip spinner --- katrain/popups.kv | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/katrain/popups.kv b/katrain/popups.kv index b497fc1..c9c5265 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -112,6 +112,11 @@ KeyValueSpinner: id: katago_files text: '' + text_autoupdate: True + -text_size: self.width, None + -halign: 'center' + -shorten: True + -shorten_from: 'right' on_select: if self.selected_index != 0: katago_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7 @@ -142,6 +147,11 @@ KeyValueSpinner: id: model_files text: '' + text_autoupdate: True + -text_size: self.width, None + -halign: 'center' + -shorten: True + -shorten_from: 'right' on_select: if self.selected_index != 0: model_path.text = self.value_keys[self.selected_index] size_hint_y: 0.7