From 416a85b4624aa3bdb098cf90b96db56fd10a50bf Mon Sep 17 00:00:00 2001 From: blamarche Date: Tue, 8 Dec 2020 18:00:50 -0500 Subject: [PATCH] added k shortcut to toggle board coordinate display --- katrain/__main__.py | 5 ++++ katrain/gui/badukpan.py | 52 ++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/katrain/__main__.py b/katrain/__main__.py index e4671a4..41613f0 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -138,6 +138,9 @@ class KaTrainGui(Screen, KaTrainBase): self.idle_analysis = not self.idle_analysis self.update_state() + def toggle_board_coordinates(self): + self.board_gui.enable_coordinates(not self.board_gui.get_enable_coordinates()) + def start(self): if self.engine: return @@ -545,6 +548,8 @@ class KaTrainGui(Screen, KaTrainBase): self.nav_drawer.set_state("toggle") elif keycode[1] == "spacebar": self.toggle_continuous_analysis() + elif keycode[1] == "k": + self.toggle_board_coordinates() elif keycode[1] in ["pause", "break", "f15"] and not ctrl_pressed: self.controls.timer.paused = not self.controls.timer.paused elif keycode[1] in ["`", "~", "f12"]: diff --git a/katrain/gui/badukpan.py b/katrain/gui/badukpan.py index 7c404c5..19bf84d 100644 --- a/katrain/gui/badukpan.py +++ b/katrain/gui/badukpan.py @@ -50,6 +50,7 @@ class BadukPanWidget(Widget): self.stone_size = 0 self.selecting_region_of_interest = False self.region_of_interest = [] + self.draw_coords_enabled = True self.active_pv_moves = [] self.animating_pv = None @@ -61,6 +62,14 @@ class BadukPanWidget(Widget): self.bind(size=self.redraw_trigger, pos=self.redraw_trigger) Clock.schedule_interval(self.animate_pv, 0.1) + def enable_coordinates(self, enabled): + self.draw_coords_enabled = enabled + self.draw_board() + self.draw_board_contents() + + def get_enable_coordinates(self): + return self.draw_coords_enabled + def play_stone_sound(self, *_args): if self.katrain.config("timer/sound"): sound = random.choice(self.stones_sounds) @@ -235,8 +244,12 @@ class BadukPanWidget(Widget): with self.canvas.before: self.canvas.before.clear() # set up margins and grid lines - grid_spaces_margin_x = [1.5, 0.75] # left, right - grid_spaces_margin_y = [1.5, 0.75] # bottom, top + if self.draw_coords_enabled: + grid_spaces_margin_x = [1.5, 0.75] # left, right + grid_spaces_margin_y = [1.5, 0.75] # bottom, top + else: #no coordinates means remove the offset + grid_spaces_margin_x = [0.75, 0.75] # left, right + grid_spaces_margin_y = [0.75, 0.75] # bottom, top x_grid_spaces = board_size_x - 1 + sum(grid_spaces_margin_x) y_grid_spaces = board_size_y - 1 + sum(grid_spaces_margin_y) self.grid_size = min(self.width / x_grid_spaces, self.height / y_grid_spaces) @@ -260,7 +273,7 @@ class BadukPanWidget(Widget): else: Color(1, 0.95, 0.8, 1) # image is a bit too light Rectangle( - pos=(self.gridpos_x[0] - self.grid_size * 1.5, self.gridpos_y[0] - self.grid_size * 1.5), + pos=(self.gridpos_x[0] - self.grid_size * grid_spaces_margin_x[0], self.gridpos_y[0] - self.grid_size * grid_spaces_margin_y[0]), size=(self.grid_size * x_grid_spaces, self.grid_size * y_grid_spaces), texture=cached_texture("img/board.png"), ) @@ -286,22 +299,23 @@ class BadukPanWidget(Widget): draw_circle((self.gridpos_x[x], self.gridpos_y[y]), starpt_size, LINE_COLOR) # coordinates - Color(0.25, 0.25, 0.25) - coord_offset = self.grid_size * 1.5 / 2 - for i in range(board_size_x): - draw_text( - pos=(self.gridpos_x[i], self.gridpos_y[0] - coord_offset), - text=Move.GTP_COORD[i], - font_size=self.grid_size / 1.5, - font_name="Roboto", - ) - for i in range(board_size_y): - draw_text( - pos=(self.gridpos_x[0] - coord_offset, self.gridpos_y[i]), - text=str(i + 1), - font_size=self.grid_size / 1.5, - font_name="Roboto", - ) + if self.draw_coords_enabled: + Color(0.25, 0.25, 0.25) + coord_offset = self.grid_size * 1.5 / 2 + for i in range(board_size_x): + draw_text( + pos=(self.gridpos_x[i], self.gridpos_y[0] - coord_offset), + text=Move.GTP_COORD[i], + font_size=self.grid_size / 1.5, + font_name="Roboto", + ) + for i in range(board_size_y): + draw_text( + pos=(self.gridpos_x[0] - coord_offset, self.gridpos_y[i]), + text=str(i + 1), + font_size=self.grid_size / 1.5, + font_name="Roboto", + ) def draw_board_contents(self, *_args): if not (self.katrain and self.katrain.game):