Add key check in grid toggle scribbling mode
parent
0a0b9fdbdb
commit
f76a23ed80
|
@ -121,22 +121,23 @@ class GameBoard(BoxBoard):
|
|||
self.numring.loseFocus.connect(self.game_refocus)
|
||||
self.toggle_anim(True)
|
||||
|
||||
def show_number_ring(self, x=0, y=0):
|
||||
def show_number_ring(self, x=0, y=0, scribbling=False):
|
||||
if not self.numring.isVisible():
|
||||
self.numring.setPos(x, y)
|
||||
self.numring.setVisible(True)
|
||||
self.numring.setFocus()
|
||||
self.numring.toggle_anim(True)
|
||||
self.numring.scribbling = scribbling
|
||||
|
||||
def select_ring_number(self, val):
|
||||
if val == 'X':
|
||||
val = 0
|
||||
self.gamegrid.replace_cell_number(int(val))
|
||||
#self.game_refocus()
|
||||
|
||||
def game_refocus(self):
|
||||
self.gamegrid.set_disabled(False)
|
||||
self.gamegrid.setFocus()
|
||||
self.gamegrid.scribbling = self.numring.scribbling
|
||||
|
||||
def show_grid(self, state):
|
||||
if state ^ self.gamegrid.isVisible():
|
||||
|
|
|
@ -5,7 +5,7 @@ This module contains the components that make up the Sudoku Board
|
|||
import numpy as np
|
||||
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
|
||||
QPropertyAnimation, pyqtProperty, pyqtSignal)
|
||||
from PyQt5.QtGui import QPen, QFont
|
||||
from PyQt5.QtGui import QPen, QFont, QKeyEvent
|
||||
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
|
||||
|
||||
from gameplay import sudoku_gameplay as sdk
|
||||
|
@ -85,7 +85,7 @@ class NumberPainter(BaseSudokuItem):
|
|||
|
||||
class SudokuGrid(BaseSudokuItem):
|
||||
# TODO: Add functions to animated the grid lines
|
||||
buttonClicked = pyqtSignal(float, float)
|
||||
buttonClicked = pyqtSignal(float, float, bool)
|
||||
finishDrawing = pyqtSignal()
|
||||
puzzleFinished = pyqtSignal()
|
||||
|
||||
|
@ -142,6 +142,8 @@ class SudokuGrid(BaseSudokuItem):
|
|||
self.anim.setKeyValueAt(t / 10, self.width * t/10)
|
||||
self.anim.setEndValue(self.width)
|
||||
|
||||
self.scribbling = False
|
||||
|
||||
self.drawn = False
|
||||
self.anim.finished.connect(self.finish_drawing)
|
||||
|
||||
|
@ -210,14 +212,26 @@ class SudokuGrid(BaseSudokuItem):
|
|||
h = (self.mouse_h + 0.5) * self.cell_height
|
||||
|
||||
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, self.scribbling)
|
||||
else:
|
||||
self.buttonClicked.emit(0, 0)
|
||||
self.buttonClicked.emit(0, 0, self.scribbling)
|
||||
|
||||
def focusInEvent(self, event):
|
||||
self.set_disabled(False)
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
self.set_disabled(True)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if not event.isAutoRepeat():
|
||||
if (event.key() == Qt.Key_M) and not self.scribbling:
|
||||
self.scribbling = True
|
||||
|
||||
def keyReleaseEvent(self, event):
|
||||
if not event.isAutoRepeat():
|
||||
if event.key() == Qt.Key_M and self.scribbling:
|
||||
self.scribbling = False
|
||||
|
||||
# Defining the length to be drawn as a pyqtProperty
|
||||
@pyqtProperty(float)
|
||||
def length(self):
|
||||
|
|
Loading…
Reference in New Issue