From e9be3dca6d808285798fe9f60bc03aa0db3fba05 Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 21 Jul 2018 16:26:40 +0800 Subject: [PATCH] X now clears the scribble --- gameplay/sudoku_gameplay.py | 3 +++ graphic_components/board.py | 7 +++---- graphic_components/sudoku_graphics.py | 15 +++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gameplay/sudoku_gameplay.py b/gameplay/sudoku_gameplay.py index 105c525..e985be5 100644 --- a/gameplay/sudoku_gameplay.py +++ b/gameplay/sudoku_gameplay.py @@ -44,6 +44,9 @@ class SudokuSystem: if val == 0: self.change_cell_status(row, col, EMPTY) + def clear_scribble(self, row, col): + self.scribbles[row, col] = '' + def toggle_scribble(self, row, col, val): if val in self.scribbles[row, col]: self.scribbles[row, col] = self.scribbles[row, col].replace(val, '') diff --git a/graphic_components/board.py b/graphic_components/board.py index fa5fe64..b62b8d2 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -130,12 +130,11 @@ class GameBoard(BoxBoard): self.numring.scribbling = scribbling def select_ring_number(self, val, scribbling): + if val == 'X': + val = 0 if scribbling: - if not val == 'X': - self.gamegrid.change_cell_scribbles(val) + self.gamegrid.change_cell_scribbles(val) else: - if val == 'X': - val = 0 self.gamegrid.replace_cell_number(int(val)) def game_refocus(self): diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index ec740dd..6723b03 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -174,7 +174,10 @@ class SudokuGrid(BaseSudokuItem): self.update() def change_cell_scribbles(self, val): - self.sudoku_grid.toggle_scribble(self.mouse_h, self.mouse_w, val) + if val == 0: + self.sudoku_grid.clear_scribble(self.mouse_h, self.mouse_w) + else: + self.sudoku_grid.toggle_scribble(self.mouse_h, self.mouse_w, val) self.grid_painter.update() def replace_cell_number(self, val): @@ -276,8 +279,6 @@ class NumberRing(BaseSudokuItem): self.cell_height = 24 self.cell_buttons = [] - for btn in self.cell_buttons: - btn.buttonClicked.connect(func) for i in range(10): if i == 0: cell_string = 'X' @@ -344,6 +345,12 @@ class NumberRing(BaseSudokuItem): else: self.setFocus() + def mousePressEvent(self, event): + if not any(btn.isUnderMouse() for btn in self.cell_buttons): + self.toggle_anim(False) + else: + self.setFocus() + def close_menu(self): if not self.scribbling: self.toggle_anim(False) @@ -364,7 +371,7 @@ class NumberRing(BaseSudokuItem): if txt: print('keypress:', txt) self.keyPressed.emit(txt, self.scribbling) - if not self.scribbling or txt == 'X': + if not self.scribbling: self.clearFocus() def keyReleaseEvent(self, event):