Add some focusing event
parent
f3625b8abd
commit
bed8f5a303
Binary file not shown.
|
@ -1,2 +1,5 @@
|
||||||
def bound_value(lower, val, higher):
|
def bound_value(lower, val, higher):
|
||||||
return min(max(val, lower), higher)
|
return min(max(val, lower), higher)
|
||||||
|
|
||||||
|
def print_rect_info(rect):
|
||||||
|
print(rect.x(), rect.y(), rect.width(), rect.height())
|
|
@ -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 sudoku_graphics as sdk_grap
|
||||||
from graphic_components import menu_graphics as menu_grap
|
from graphic_components import menu_graphics as menu_grap
|
||||||
|
from general import extras
|
||||||
|
|
||||||
class BoxBoard(QGraphicsWidget):
|
class BoxBoard(QGraphicsWidget):
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ class BoxBoard(QGraphicsWidget):
|
||||||
|
|
||||||
|
|
||||||
class GameBoard(BoxBoard):
|
class GameBoard(BoxBoard):
|
||||||
|
boxClicked = pyqtSignal(bool)
|
||||||
|
|
||||||
def __init__(self, width, height, parent=None):
|
def __init__(self, width, height, parent=None):
|
||||||
super().__init__(width, height, parent)
|
super().__init__(width, height, parent)
|
||||||
|
@ -80,6 +82,15 @@ class GameBoard(BoxBoard):
|
||||||
self.gamegrid.replace_cell_number(int(val))
|
self.gamegrid.replace_cell_number(int(val))
|
||||||
self.show_number_ring()
|
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):
|
class MenuBoard(BoxBoard):
|
||||||
# TODO: Create the components for the menu: A timer and a difficulty selector
|
# 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.layout.setItemSpacing(1, 0)
|
||||||
|
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
def show_difficulty(self, state):
|
||||||
|
print(state)
|
||||||
|
self.diff_display.selected = state
|
||||||
|
self.diff_display.update()
|
||||||
|
|
|
@ -56,6 +56,8 @@ class animBox(QGraphicsObject):
|
||||||
self.anim.setKeyValueAt(t / 10, self.logistic_func(t / 10))
|
self.anim.setKeyValueAt(t / 10, self.logistic_func(t / 10))
|
||||||
self.anim.setEndValue(self.circumference)
|
self.anim.setEndValue(self.circumference)
|
||||||
|
|
||||||
|
self.freeze = False
|
||||||
|
|
||||||
# Toggle the animation to be play forward or backward
|
# Toggle the animation to be play forward or backward
|
||||||
def toggle_anim(self, toggling):
|
def toggle_anim(self, toggling):
|
||||||
if toggling:
|
if toggling:
|
||||||
|
@ -125,18 +127,19 @@ class animBox(QGraphicsObject):
|
||||||
|
|
||||||
# Reimplemented hoverEvents to detect the mouse and toggle the animation
|
# Reimplemented hoverEvents to detect the mouse and toggle the animation
|
||||||
def hoverEnterEvent(self, event):
|
def hoverEnterEvent(self, event):
|
||||||
if ~self.detected:
|
if ~self.detected and ~self.freeze:
|
||||||
self.hoverEnter.emit()
|
self.hoverEnter.emit()
|
||||||
self.detected = True
|
self.detected = True
|
||||||
self.toggle_anim(True)
|
self.toggle_anim(True)
|
||||||
super().hoverEnterEvent(event)
|
super().hoverEnterEvent(event)
|
||||||
|
|
||||||
def hoverLeaveEvent(self, event):
|
def hoverLeaveEvent(self, event):
|
||||||
if self.detected:
|
if self.detected and ~self.freeze:
|
||||||
self.hoverExit.emit()
|
self.hoverExit.emit()
|
||||||
self.detected = False
|
self.detected = False
|
||||||
self.toggle_anim(False)
|
self.toggle_anim(False)
|
||||||
super().hoverLeaveEvent(event)
|
super().hoverLeaveEvent(event)
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
|
if ~self.freeze:
|
||||||
self.buttonClicked.emit(self.text)
|
self.buttonClicked.emit(self.text)
|
|
@ -38,6 +38,7 @@ class TimerDisplayer(QGraphicsWidget):
|
||||||
|
|
||||||
|
|
||||||
class DifficultyDisplayer(QGraphicsWidget):
|
class DifficultyDisplayer(QGraphicsWidget):
|
||||||
|
diffClicked = pyqtSignal(bool)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
@ -74,13 +75,14 @@ class DifficultyDisplayer(QGraphicsWidget):
|
||||||
painter.drawRect(self.diff_box)
|
painter.drawRect(self.diff_box)
|
||||||
painter.drawText(self.diff_box, Qt.AlignCenter, "Normal")
|
painter.drawText(self.diff_box, Qt.AlignCenter, "Normal")
|
||||||
|
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
self.selected = not self.selected
|
self.selected = not self.selected
|
||||||
for btn in self.diff_buttons:
|
for btn in self.diff_buttons:
|
||||||
btn.setVisible(self.selected)
|
btn.setVisible(self.selected)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
self.diffClicked.emit(self.selected)
|
||||||
|
|
||||||
#def boundingRect(self):
|
#def boundingRect(self):
|
||||||
# return QRectF(-20, -(self.height+10)*4 -20, self.width+40, (self.height+20) * 5)
|
# return QRectF(-20, -(self.height+10)*4 -20, self.width+40, (self.height+20) * 5)
|
||||||
|
|
||||||
|
|
|
@ -126,9 +126,9 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
# TODO: Possibly draw the fixed cell here
|
# TODO: Possibly draw the fixed cell here
|
||||||
|
|
||||||
def hoverMoveEvent(self, event):
|
def hoverMoveEvent(self, event):
|
||||||
|
if not self.freeze:
|
||||||
box_w = bound_value(0, int(event.pos().x()/self.cell_width), 8)
|
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)
|
box_h = bound_value(0, int(event.pos().y() / self.cell_height), 8)
|
||||||
if not self.freeze:
|
|
||||||
if box_w != self.mouse_w or box_h != self.mouse_h:
|
if box_w != self.mouse_w or box_h != self.mouse_h:
|
||||||
self.mouse_w = box_w
|
self.mouse_w = box_w
|
||||||
self.mouse_h = box_h
|
self.mouse_h = box_h
|
||||||
|
@ -136,11 +136,14 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
|
if not self.freeze:
|
||||||
w = (self.mouse_w + 0.5) * self.cell_width - 5
|
w = (self.mouse_w + 0.5) * self.cell_width - 5
|
||||||
h = (self.mouse_h + 0.5) * self.cell_height + 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:
|
if not self.sudoku_grid.get_cell_status(self.mouse_h, self.mouse_w) == sdk.FIXED:
|
||||||
self.buttonClicked.emit(w, h)
|
self.buttonClicked.emit(w, h)
|
||||||
|
else:
|
||||||
|
self.buttonClicked.emit(0, 0)
|
||||||
|
|
||||||
|
|
||||||
class NumberRing(BaseSudokuItem):
|
class NumberRing(BaseSudokuItem):
|
||||||
|
@ -180,3 +183,7 @@ class NumberRing(BaseSudokuItem):
|
||||||
def connect_button_signals(self, func):
|
def connect_button_signals(self, func):
|
||||||
for btn in self.cell_buttons:
|
for btn in self.cell_buttons:
|
||||||
btn.buttonClicked.connect(func)
|
btn.buttonClicked.connect(func)
|
||||||
|
|
||||||
|
def freeze_buttons(self, state):
|
||||||
|
for btn in self.cell_buttons:
|
||||||
|
btn.freeze = state
|
||||||
|
|
10
main.py
10
main.py
|
@ -42,8 +42,14 @@ class SudokuWindow(QGraphicsView):
|
||||||
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
||||||
self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio)
|
self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio)
|
||||||
self.show()
|
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__":
|
if __name__ == "__main__":
|
||||||
app = 0
|
app = 0
|
||||||
|
|
Loading…
Reference in New Issue