diff --git a/graphic_components/board.py b/graphic_components/board.py index 1f752f6..22e020b 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -147,7 +147,7 @@ class GameBoard(BoxBoard): self.numring = sdk_grap.NumberRing(parent=self) self.playmenu = sdk_grap.PlayMenu(parent=self) - self.gamegrid.setFocus(Qt.MouseFocusReason) + #self.gamegrid.setFocus(Qt.MouseFocusReason) self.show_grid(False) self.show_playmenu(False) @@ -161,6 +161,10 @@ class GameBoard(BoxBoard): self.anim.finished.connect(lambda: self.show_playmenu(True)) self.toggle_anim(True) + self.refocus_timer = QTimer() + self.refocus_timer.timeout.connect(self.game_refocus) + self.refocus_timer.setSingleShot(True) + def show_number_ring(self, x=0, y=0, scribbling=False): """Display the Number Ring if it is not visible, while setting the focus to it @@ -174,6 +178,7 @@ class GameBoard(BoxBoard): True to set Scribble mode, False otherwise """ if not self.numring.isVisible(): + self.game_unfocus() self.numring.setPos(x, y) self.numring.setVisible(True) self.numring.setFocus() @@ -201,9 +206,17 @@ class GameBoard(BoxBoard): """Enable the grid and give it grid focus """ self.gamegrid.set_disabled(False) - self.gamegrid.setFocus() + #self.gamegrid.setFocus() self.gamegrid.scribbling = self.numring.scribbling # To update the grid scribbling mode + def game_unfocus(self): + """Enable the grid and give it grid focus + """ + self.gamegrid.set_disabled(True) + #self.gamegrid.setFocus() + #self.gamegrid.scribbling = self.numring.scribbling # To update the grid scribbling mode + + def show_grid(self, state): """Show the grid, if it is not; Hide the grid, if it is. Note: Animation only plays when showing the grid. diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py index 3dabf98..67a458e 100644 --- a/graphic_components/menu_graphics.py +++ b/graphic_components/menu_graphics.py @@ -84,10 +84,6 @@ class TimerDisplayer(QGraphicsWidget): class DifficultyDisplayer(QGraphicsWidget): -<<<<<<< HEAD - notFocus = Signal() - difficultySelected = Signal(str) -======= """Display the current difficulty. Clicking on it displays the difficulty menu. Attributes @@ -98,9 +94,8 @@ class DifficultyDisplayer(QGraphicsWidget): difficultySelected = pyqtSignal(str) Emitted when a difficulty is selected. Emits the selected difficulty """ - notFocus = pyqtSignal() - difficultySelected = pyqtSignal(str) ->>>>>>> Document menu_graphics + notFocus = Signal() + difficultySelected = Signal(str) def __init__(self, parent=None): """Create the box and the text. @@ -167,6 +162,7 @@ class DifficultyDisplayer(QGraphicsWidget): if not self.diff_menu.isVisible(): self.diff_menu.setFocus() self.diff_menu.setVisible(True) + self.clicked.emit() else: self.diff_menu.setVisible(False) self.notFocus.emit() @@ -247,7 +243,7 @@ class DifficultyMenu(QGraphicsWidget): return QRectF(0, 0, self.width, self.height) def clicked_on(self, string): - """Emits the menuCLicked signal with the selected difficulty, when one of the buttons is pressed. + """Emits the menuClicked signal with the selected difficulty, when one of the buttons is pressed. Parameters ---------- diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index 50fa6e4..a2103f9 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -192,7 +192,7 @@ class SudokuGrid(BaseSudokuItem): self.setAcceptHoverEvents(True) self.setAcceptedMouseButtons(Qt.LeftButton) - self.setFlag(QGraphicsItem.ItemIsFocusable, True) + #self.setFlag(QGraphicsItem.ItemIsFocusable, True) self.set_disabled(False) # Set up the animation @@ -326,18 +326,19 @@ class SudokuGrid(BaseSudokuItem): if not self.sudoku_grid.get_cell_status(self.mouse_h, self.mouse_w) == sdk.FIXED: self.buttonClicked.emit(w, h, self.scribbling) + self.set_disabled(True) else: self.buttonClicked.emit(0, 0, self.scribbling) - def focusInEvent(self, event): + #def focusInEvent(self, event): """Reimplemented from QGraphicsObject. Unfreeze the grid on focus """ - self.set_disabled(False) + #self.set_disabled(False) - def focusOutEvent(self, event): + #def focusOutEvent(self, event): """Reimplemented from QGraphicsObject. Freeze the grid when out of focus """ - self.set_disabled(True) + #self.set_disabled(True) def keyPressEvent(self, event): """Reimplemented from QGraphicsObject. Check if scribble key is held, toggling on scribbling mode. diff --git a/main.py b/main.py index 0ad19bb..4c05911 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,8 @@ class SudokuWindow(QGraphicsView): self.gameboard.gridDrawn.connect(lambda: self.menuboard.show_children(True)) self.gameboard.newGameSelected.connect(self.menuboard.set_difficulty_text) self.gameboard.sudokuDone.connect(self.menuboard.finish_the_game) - self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus) + self.menuboard.diff_display.clicked.connect(self.gameboard.game_unfocus) + self.menuboard.diff_display.notFocus.connect(lambda: self.gameboard.refocus_timer.start(10)) self.menuboard.diff_display.difficultySelected.connect(self.gameboard.new_game) def resizeEvent(self, event):