Fix focusing issue of game board
parent
de5af7cb44
commit
9ce1ae0ff7
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
----------
|
||||
|
|
|
@ -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.
|
||||
|
|
3
main.py
3
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):
|
||||
|
|
Loading…
Reference in New Issue