From 2de8c85171fdbf8e62b399742553674618cbbfa0 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 1 May 2020 16:59:43 +0200 Subject: [PATCH] fix togglebuttons --- game_node.py | 2 +- gui/kivyutils.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/game_node.py b/game_node.py index faf6d51..267b38d 100644 --- a/game_node.py +++ b/game_node.py @@ -110,7 +110,7 @@ class GameNode(SGFNode): if sgf or hints or teach: policy_ranking = self.parent.policy_ranking - currmove_policy_with_ix = [(ix + 1,p) for (p, m), ix in zip(policy_ranking, range(len(policy_ranking))) if m == single_move] + currmove_policy_with_ix = [(ix + 1, p) for (p, m), ix in zip(policy_ranking, range(len(policy_ranking))) if m == single_move] if currmove_policy_with_ix: text += f"Move was #{currmove_policy_with_ix[0][0]} according to policy ({currmove_policy_with_ix[0][1]:.2%}).\n" if not currmove_policy_with_ix or currmove_policy_with_ix[0] != 1 and (sgf or hints): diff --git a/gui/kivyutils.py b/gui/kivyutils.py index 74d66f7..3b683f3 100644 --- a/gui/kivyutils.py +++ b/gui/kivyutils.py @@ -92,6 +92,13 @@ class StyledButton(Button, ToolTipBehavior): class StyledToggleButton(StyledButton, ToggleButtonBehavior, ToolTipBehavior): value = StringProperty("") + allow_no_selection = BooleanProperty(False) + + def _do_press(self): + if (self.last_touch and self.last_touch.button != "left") or (not self.allow_no_selection and self.state == "down"): + return + self._release_group(self) + self.state = "normal" if self.state == "down" else "down" class StyledSpinner(Spinner): @@ -145,14 +152,13 @@ class ToggleButtonContainer(GridLayout): if len(self.labels) < len(self.options): self.labels += self.options[len(self.labels) + 1 :] - def state_handler(btn, *args): + def state_handler(*args): self.dispatch("on_selection") - btn.state = "down" # no toggle for i, opt in enumerate(self.options): state = "down" if opt == self.selected else "normal" tooltip = self.tooltips[i] if self.tooltips else None - self.add_widget(StyledToggleButton(group=self.group, text=self.labels[i], value=opt, state=state, on_press=state_handler,tooltip_text=tooltip)) + self.add_widget(StyledToggleButton(group=self.group, text=self.labels[i], value=opt, state=state, on_press=state_handler, tooltip_text=tooltip)) Clock.schedule_once(self._size, 0) def _size(self, _dt): @@ -294,8 +300,6 @@ class ScoreGraph(Label): dot_point[1] = self.pos[1] + self.height / 2 + available_height / 2 * ((nn_values or [0])[-1] / self.y_scale) self.dot_pos = [c - self.highlight_size / 2 for c in dot_point] - # print("Graph updated to ", len(line_points), "points, hl=", self.highlighted_index, self.dot_pos) - def update_value(self, node): self.highlighted_index = index = node.depth self.nodes.extend([None] * max(0, index - (len(self.nodes) - 1)))