Fix the sudoku board layout
parent
67a15141aa
commit
371dd810ca
|
@ -15,7 +15,7 @@ import sys, math
|
||||||
class BoxBoard(QGraphicsWidget):
|
class BoxBoard(QGraphicsWidget):
|
||||||
|
|
||||||
# Initialisation
|
# Initialisation
|
||||||
def __init__(self, width, height, parent = None):
|
def __init__(self, width, height, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
@ -48,6 +48,33 @@ class BoxBoard(QGraphicsWidget):
|
||||||
def sizeHint(self, which, constraint=None):
|
def sizeHint(self, which, constraint=None):
|
||||||
return(QSizeF(self.width+10, self.height+10))
|
return(QSizeF(self.width+10, self.height+10))
|
||||||
|
|
||||||
|
|
||||||
|
class GameBoard(BoxBoard):
|
||||||
|
|
||||||
|
def __init__(self, width, height, parent=None):
|
||||||
|
super().__init__(width, height, parent)
|
||||||
|
|
||||||
|
self.gamegrid = SudokuGrid(self.width, self.height, parent=self)
|
||||||
|
self.numring = NumberRing(parent=self)
|
||||||
|
|
||||||
|
self.gamegrid.update()
|
||||||
|
self.numring.update()
|
||||||
|
|
||||||
|
def show_number_ring(self, x=0, y=0):
|
||||||
|
if not self.gamegrid.selected:
|
||||||
|
self.numring.setPos(x, y)
|
||||||
|
self.numring.setVisible(True)
|
||||||
|
self.gamegrid.selected = True
|
||||||
|
else:
|
||||||
|
self.numring.setVisible(False)
|
||||||
|
self.gamegrid.selected = False
|
||||||
|
|
||||||
|
def select_ring_number(self, val):
|
||||||
|
if val == 'X':
|
||||||
|
val = 0
|
||||||
|
self.gamegrid.replace_cell_number(int(val))
|
||||||
|
self.show_number_ring()
|
||||||
|
|
||||||
class SudokuGrid(QGraphicsObject):
|
class SudokuGrid(QGraphicsObject):
|
||||||
# Prepare the signal
|
# Prepare the signal
|
||||||
buttonClicked = pyqtSignal(float, float)
|
buttonClicked = pyqtSignal(float, float)
|
||||||
|
@ -178,8 +205,8 @@ class NumberPainter(QGraphicsItem):
|
||||||
|
|
||||||
class NumberRing(QGraphicsItem):
|
class NumberRing(QGraphicsItem):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, parent= None):
|
||||||
super().__init__()
|
super().__init__(parent = parent)
|
||||||
|
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
self.radius = 48
|
self.radius = 48
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# Put all Sudoku related graphics here
|
6
main.py
6
main.py
|
@ -21,7 +21,7 @@ class SudokuWindow(QGraphicsView):
|
||||||
|
|
||||||
self.setScene(self.scene)
|
self.setScene(self.scene)
|
||||||
self.setSceneRect(self.scene.sceneRect())
|
self.setSceneRect(self.scene.sceneRect())
|
||||||
self.gameboard = board.BoxBoard(400, 400)
|
self.gameboard = board.GameBoard(400, 400)
|
||||||
self.menuboard = board.BoxBoard(400, 50)
|
self.menuboard = board.BoxBoard(400, 50)
|
||||||
self.gamegrid = board.SudokuGrid(450, 450)
|
self.gamegrid = board.SudokuGrid(450, 450)
|
||||||
self.numring = board.NumberRing()
|
self.numring = board.NumberRing()
|
||||||
|
@ -38,8 +38,8 @@ class SudokuWindow(QGraphicsView):
|
||||||
|
|
||||||
#self.scene.addItem(self.gameboard)
|
#self.scene.addItem(self.gameboard)
|
||||||
self.scene.addItem(self.form)
|
self.scene.addItem(self.form)
|
||||||
self.scene.addItem(self.gamegrid)
|
#self.scene.addItem(self.gamegrid)
|
||||||
self.scene.addItem(self.numring)
|
#self.scene.addItem(self.numring)
|
||||||
self.setBackgroundBrush(QBrush(Qt.black))
|
self.setBackgroundBrush(QBrush(Qt.black))
|
||||||
self.setRenderHint(QPainter.Antialiasing)
|
self.setRenderHint(QPainter.Antialiasing)
|
||||||
self.setGeometry(0, 0, 600, 600)
|
self.setGeometry(0, 0, 600, 600)
|
||||||
|
|
Loading…
Reference in New Issue