diff --git a/general/__pycache__/extras.cpython-35.pyc b/general/__pycache__/extras.cpython-35.pyc deleted file mode 100644 index c2e932d..0000000 Binary files a/general/__pycache__/extras.cpython-35.pyc and /dev/null differ diff --git a/general/extras.py b/general/extras.py index c6bddc6..ba95dcf 100644 --- a/general/extras.py +++ b/general/extras.py @@ -1,2 +1,5 @@ def bound_value(lower, val, higher): - return min(max(val, lower), higher) \ No newline at end of file + return min(max(val, lower), higher) + +def print_rect_info(rect): + print(rect.x(), rect.y(), rect.width(), rect.height()) \ No newline at end of file diff --git a/graphic_components/board.py b/graphic_components/board.py index 7fc3b0e..1f31612 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -7,6 +7,7 @@ from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLin from graphic_components import sudoku_graphics as sdk_grap from graphic_components import menu_graphics as menu_grap +from general import extras class BoxBoard(QGraphicsWidget): @@ -55,6 +56,7 @@ class BoxBoard(QGraphicsWidget): class GameBoard(BoxBoard): + boxClicked = pyqtSignal(bool) def __init__(self, width, height, parent=None): super().__init__(width, height, parent) @@ -80,6 +82,15 @@ 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) + class MenuBoard(BoxBoard): # TODO: Create the components for the menu: A timer and a difficulty selector @@ -98,3 +109,8 @@ class MenuBoard(BoxBoard): self.layout.setItemSpacing(1, 0) self.setLayout(self.layout) + + def show_difficulty(self, state): + print(state) + self.diff_display.selected = state + self.diff_display.update() diff --git a/graphic_components/buttons.py b/graphic_components/buttons.py index 574001d..23a89fb 100644 --- a/graphic_components/buttons.py +++ b/graphic_components/buttons.py @@ -56,6 +56,8 @@ class animBox(QGraphicsObject): self.anim.setKeyValueAt(t / 10, self.logistic_func(t / 10)) self.anim.setEndValue(self.circumference) + self.freeze = False + # Toggle the animation to be play forward or backward def toggle_anim(self, toggling): if toggling: @@ -125,18 +127,19 @@ class animBox(QGraphicsObject): # Reimplemented hoverEvents to detect the mouse and toggle the animation def hoverEnterEvent(self, event): - if ~self.detected: + if ~self.detected and ~self.freeze: self.hoverEnter.emit() self.detected = True self.toggle_anim(True) super().hoverEnterEvent(event) def hoverLeaveEvent(self, event): - if self.detected: + if self.detected and ~self.freeze: self.hoverExit.emit() self.detected = False self.toggle_anim(False) super().hoverLeaveEvent(event) def mousePressEvent(self, event): - self.buttonClicked.emit(self.text) \ No newline at end of file + if ~self.freeze: + self.buttonClicked.emit(self.text) diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py index 90b05c8..2f9d295 100644 --- a/graphic_components/menu_graphics.py +++ b/graphic_components/menu_graphics.py @@ -38,6 +38,7 @@ class TimerDisplayer(QGraphicsWidget): class DifficultyDisplayer(QGraphicsWidget): + diffClicked = pyqtSignal(bool) def __init__(self, parent=None): super().__init__(parent) @@ -74,13 +75,14 @@ class DifficultyDisplayer(QGraphicsWidget): painter.drawRect(self.diff_box) painter.drawText(self.diff_box, Qt.AlignCenter, "Normal") - def mousePressEvent(self, event): self.selected = not self.selected for btn in self.diff_buttons: btn.setVisible(self.selected) self.update() + self.diffClicked.emit(self.selected) + #def boundingRect(self): # return QRectF(-20, -(self.height+10)*4 -20, self.width+40, (self.height+20) * 5) diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index 0360a14..202d576 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -126,9 +126,9 @@ class SudokuGrid(BaseSudokuItem): # TODO: Possibly draw the fixed cell here def hoverMoveEvent(self, event): - box_w = bound_value(0, int(event.pos().x()/self.cell_width), 8) - box_h = bound_value(0, int(event.pos().y() / self.cell_height), 8) if not self.freeze: + box_w = bound_value(0, int(event.pos().x()/self.cell_width), 8) + box_h = bound_value(0, int(event.pos().y() / self.cell_height), 8) if box_w != self.mouse_w or box_h != self.mouse_h: self.mouse_w = box_w self.mouse_h = box_h @@ -136,11 +136,14 @@ class SudokuGrid(BaseSudokuItem): self.update() def mousePressEvent(self, event): - w = (self.mouse_w + 0.5) * self.cell_width - 5 - h = (self.mouse_h + 0.5) * self.cell_height + 5 + if not self.freeze: + w = (self.mouse_w + 0.5) * self.cell_width - 5 + h = (self.mouse_h + 0.5) * self.cell_height + 5 - if not self.sudoku_grid.get_cell_status(self.mouse_h, self.mouse_w) == sdk.FIXED: - self.buttonClicked.emit(w, h) + if not self.sudoku_grid.get_cell_status(self.mouse_h, self.mouse_w) == sdk.FIXED: + self.buttonClicked.emit(w, h) + else: + self.buttonClicked.emit(0, 0) class NumberRing(BaseSudokuItem): @@ -180,3 +183,7 @@ class NumberRing(BaseSudokuItem): def connect_button_signals(self, func): for btn in self.cell_buttons: btn.buttonClicked.connect(func) + + def freeze_buttons(self, state): + for btn in self.cell_buttons: + btn.freeze = state diff --git a/main.py b/main.py index dba9a3e..ffd013b 100644 --- a/main.py +++ b/main.py @@ -42,8 +42,14 @@ class SudokuWindow(QGraphicsView): #self.ensureVisible(self.scene.sceneRect(), 50, 50) self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio) self.show() - print(self.menuboard.geometry().height()) - print(self.gameboard.boundingRect().height()) + + self.menuboard.diff_display.diffClicked.connect(self.freeze_game) + + def freeze_game(self, freeze): + self.menuboard.show_difficulty(freeze) + self.gameboard.freeze_gameboard(freeze) + + if __name__ == "__main__": app = 0