Convert to FocusEvents for menu
parent
4e49c9f032
commit
6bf10818c0
|
@ -70,7 +70,6 @@ class GameBoard(BoxBoard):
|
|||
self.gamegrid.setFocus(Qt.MouseFocusReason)
|
||||
|
||||
def show_number_ring(self, x=0, y=0):
|
||||
print('Before', self.gamegrid.hasFocus(), self.numring.hasFocus())
|
||||
if not self.gamegrid.freeze:
|
||||
self.numring.setPos(x, y)
|
||||
self.numring.setVisible(True)
|
||||
|
@ -78,7 +77,6 @@ class GameBoard(BoxBoard):
|
|||
else:
|
||||
self.gamegrid.freeze = False
|
||||
self.gamegrid.setFocus()
|
||||
print('After', self.gamegrid.hasFocus(), self.numring.hasFocus())
|
||||
|
||||
def select_ring_number(self, val):
|
||||
if val == 'X':
|
||||
|
@ -86,15 +84,9 @@ class GameBoard(BoxBoard):
|
|||
self.gamegrid.replace_cell_number(int(val))
|
||||
self.show_number_ring()
|
||||
|
||||
#def mousePressEvent(self, event):
|
||||
# print('clicked')
|
||||
# extras.print_rect_info(self.boundingRect())
|
||||
# self.buttonClicked.emit(False)
|
||||
|
||||
def freeze_gameboard(self, state):
|
||||
self.gamegrid.freeze = state
|
||||
self.numring.freeze_buttons(state)
|
||||
|
||||
def game_refocus(self):
|
||||
self.gamegrid.freeze = False
|
||||
self.gamegrid.setFocus()
|
||||
|
||||
class MenuBoard(BoxBoard):
|
||||
# TODO: Create the components for the menu: A timer and a difficulty selector
|
||||
|
|
|
@ -38,7 +38,7 @@ class TimerDisplayer(QGraphicsWidget):
|
|||
|
||||
|
||||
class DifficultyDisplayer(QGraphicsWidget):
|
||||
diffClicked = pyqtSignal(bool)
|
||||
notFocus = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
@ -69,6 +69,7 @@ class DifficultyDisplayer(QGraphicsWidget):
|
|||
self.setSizePolicy(self.size_policy)
|
||||
|
||||
self.selected = False
|
||||
self.setFlag(QGraphicsItem.ItemIsFocusable, True)
|
||||
|
||||
def paint(self, painter, style, widget=None):
|
||||
painter.setPen(self.box_pen)
|
||||
|
@ -80,9 +81,16 @@ class DifficultyDisplayer(QGraphicsWidget):
|
|||
for btn in self.diff_buttons:
|
||||
btn.setVisible(self.selected)
|
||||
self.update()
|
||||
|
||||
self.diffClicked.emit(self.selected)
|
||||
if self.selected:
|
||||
self.setFocus()
|
||||
else:
|
||||
self.clearFocus()
|
||||
|
||||
#def boundingRect(self):
|
||||
# return QRectF(-20, -(self.height+10)*4 -20, self.width+40, (self.height+20) * 5)
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
self.selected = False
|
||||
for btn in self.diff_buttons:
|
||||
btn.setVisible(False)
|
||||
self.notFocus.emit()
|
||||
|
|
|
@ -146,9 +146,6 @@ class SudokuGrid(BaseSudokuItem):
|
|||
def focusOutEvent(self, event):
|
||||
self.freeze = True
|
||||
|
||||
#def focusInEvent(self, event):
|
||||
# self.freeze = False
|
||||
|
||||
|
||||
class NumberRing(BaseSudokuItem):
|
||||
# TODO: Add functions to animated the ring appearing
|
||||
|
|
11
main.py
11
main.py
|
@ -16,7 +16,7 @@ class SudokuWindow(QGraphicsView):
|
|||
super().__init__()
|
||||
|
||||
# Set up the Scene to manage the GraphicItems
|
||||
self.scene = QGraphicsScene(0, 0, 420, 510, self)
|
||||
self.scene = QGraphicsScene(0, 0, 500, 600, self)
|
||||
|
||||
self.setScene(self.scene)
|
||||
self.setSceneRect(self.scene.sceneRect())
|
||||
|
@ -30,8 +30,8 @@ class SudokuWindow(QGraphicsView):
|
|||
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
||||
self.layout.addItem(self.gameboard)
|
||||
self.layout.addItem(self.menuboard)
|
||||
self.layout.setSpacing(10)
|
||||
self.layout.setContentsMargins(10, 10, 10, 0)
|
||||
self.layout.setSpacing(50)
|
||||
self.layout.setContentsMargins(50, 50, 50, 0)
|
||||
self.form.setLayout(self.layout)
|
||||
|
||||
self.scene.addItem(self.form)
|
||||
|
@ -40,10 +40,11 @@ class SudokuWindow(QGraphicsView):
|
|||
#self.setGeometry(self.scene.sceneRect().toRect())
|
||||
|
||||
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
||||
self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio)
|
||||
#self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio)
|
||||
self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
|
||||
self.show()
|
||||
|
||||
#self.menuboard.diff_display.diffClicked.connect(self.freeze_game)
|
||||
self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus)
|
||||
|
||||
def freeze_game(self, freeze):
|
||||
self.menuboard.show_difficulty(freeze)
|
||||
|
|
Loading…
Reference in New Issue