Add comments
parent
7aace4df50
commit
77f693b7b7
|
@ -11,22 +11,25 @@ from general import extras
|
||||||
|
|
||||||
|
|
||||||
class BoxBoard(QGraphicsWidget):
|
class BoxBoard(QGraphicsWidget):
|
||||||
|
"""
|
||||||
|
A generic board that draws an animated rectangular border
|
||||||
|
"""
|
||||||
|
|
||||||
# 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
|
||||||
self.half_circumference = width+height
|
self.half_circumference = width+height
|
||||||
|
self.freeze = False
|
||||||
|
|
||||||
self.setMinimumSize(QSizeF(width, height))
|
self.setMinimumSize(QSizeF(width, height))
|
||||||
self.setMaximumSize(QSizeF(width, height))
|
#self.setMaximumSize(QSizeF(width, height))
|
||||||
|
|
||||||
self.size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
self.size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||||
self.size_policy.setHeightForWidth(True)
|
self.size_policy.setHeightForWidth(True)
|
||||||
self.setSizePolicy(self.size_policy)
|
self.setSizePolicy(self.size_policy)
|
||||||
|
|
||||||
# Set up pens for drawing
|
# Set up a default pen for drawing
|
||||||
self.default_pen = QPen()
|
self.default_pen = QPen()
|
||||||
self.default_pen.setColor(Qt.white)
|
self.default_pen.setColor(Qt.white)
|
||||||
self.default_pen.setWidth(5)
|
self.default_pen.setWidth(5)
|
||||||
|
@ -49,8 +52,6 @@ class BoxBoard(QGraphicsWidget):
|
||||||
self.anim.setKeyValueAt(t / 10, self.half_circumference * t/10)
|
self.anim.setKeyValueAt(t / 10, self.half_circumference * t/10)
|
||||||
self.anim.setEndValue(self.half_circumference)
|
self.anim.setEndValue(self.half_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:
|
||||||
|
@ -66,7 +67,7 @@ class BoxBoard(QGraphicsWidget):
|
||||||
for line in self.line_order:
|
for line in self.line_order:
|
||||||
if line.length() > 1:
|
if line.length() > 1:
|
||||||
painter.drawLine(line)
|
painter.drawLine(line)
|
||||||
super().paint(painter, style, widget)
|
#super().paint(painter, style, widget)
|
||||||
|
|
||||||
# Defining the length to be drawn as a pyqtProperty
|
# Defining the length to be drawn as a pyqtProperty
|
||||||
@pyqtProperty(float)
|
@pyqtProperty(float)
|
||||||
|
@ -92,6 +93,10 @@ class BoxBoard(QGraphicsWidget):
|
||||||
|
|
||||||
|
|
||||||
class GameBoard(BoxBoard):
|
class GameBoard(BoxBoard):
|
||||||
|
"""
|
||||||
|
The Board in which the main game takes place.
|
||||||
|
It is intended to swap the interface depending on whether the game is ongoing
|
||||||
|
"""
|
||||||
boxClicked = pyqtSignal(bool)
|
boxClicked = pyqtSignal(bool)
|
||||||
|
|
||||||
def __init__(self, width, height, parent=None):
|
def __init__(self, width, height, parent=None):
|
||||||
|
@ -100,6 +105,7 @@ class GameBoard(BoxBoard):
|
||||||
self.gamegrid = sdk_grap.SudokuGrid(self.width, self.height, parent=self)
|
self.gamegrid = sdk_grap.SudokuGrid(self.width, self.height, parent=self)
|
||||||
self.numring = sdk_grap.NumberRing(parent=self)
|
self.numring = sdk_grap.NumberRing(parent=self)
|
||||||
self.playmenu = sdk_grap.PlayMenu(parent=self)
|
self.playmenu = sdk_grap.PlayMenu(parent=self)
|
||||||
|
|
||||||
self.show_grid(False)
|
self.show_grid(False)
|
||||||
self.show_playmenu(False)
|
self.show_playmenu(False)
|
||||||
|
|
||||||
|
@ -141,7 +147,10 @@ class GameBoard(BoxBoard):
|
||||||
|
|
||||||
|
|
||||||
class MenuBoard(BoxBoard):
|
class MenuBoard(BoxBoard):
|
||||||
# TODO: Create the components for the menu: A timer and a difficulty selector
|
"""
|
||||||
|
The Board that contains menu options. Also contains the timer.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, width, height, parent=None):
|
def __init__(self, width, height, parent=None):
|
||||||
super().__init__(width, height, parent)
|
super().__init__(width, height, parent)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
"""
|
||||||
|
This module contains all kinds of animated buttons
|
||||||
|
"""
|
||||||
|
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.Qt import QApplication, QTimer
|
from PyQt5.Qt import QApplication, QTimer
|
||||||
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsView, QGraphicsItem,
|
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsView, QGraphicsItem,
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
"""
|
||||||
|
This module contains the components that make up the menu Board
|
||||||
|
"""
|
||||||
|
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
||||||
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
# Put all Sudoku related graphics here
|
"""
|
||||||
|
This module contains the components that make up the Sudoku Board
|
||||||
|
"""
|
||||||
|
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
|
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
|
||||||
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
|
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
|
||||||
|
@ -234,8 +237,6 @@ class NumberRing(BaseSudokuItem):
|
||||||
|
|
||||||
# Reimplemented paint
|
# Reimplemented paint
|
||||||
def paint(self, painter, style, widget=None):
|
def paint(self, painter, style, widget=None):
|
||||||
#painter.setPen(self.default_pen)
|
|
||||||
#painter.drawRect(self.boundingRect())
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def connect_button_signals(self, func):
|
def connect_button_signals(self, func):
|
||||||
|
|
19
main.py
19
main.py
|
@ -11,41 +11,42 @@ from graphic_components import board
|
||||||
|
|
||||||
|
|
||||||
class SudokuWindow(QGraphicsView):
|
class SudokuWindow(QGraphicsView):
|
||||||
|
"""
|
||||||
|
The main window that shows the graphical components.
|
||||||
|
Contains the Sudoku Board and the Menu Board.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# Set up the Scene to manage the GraphicItems
|
# Set up the Scene to manage the GraphicItems
|
||||||
self.scene = QGraphicsScene(0, 0, 500, 600, self)
|
self.scene = QGraphicsScene(0, 0, 500, 600, self)
|
||||||
|
|
||||||
self.setScene(self.scene)
|
self.setScene(self.scene)
|
||||||
self.setSceneRect(self.scene.sceneRect())
|
self.setSceneRect(self.scene.sceneRect())
|
||||||
self.gameboard = board.GameBoard(400, 400)
|
|
||||||
self.menuboard = board.MenuBoard(400, 80)
|
|
||||||
|
|
||||||
|
# Add the Boards to the form with a vertical layout
|
||||||
self.form = QGraphicsWidget()
|
self.form = QGraphicsWidget()
|
||||||
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
||||||
|
self.gameboard = board.GameBoard(400, 400)
|
||||||
|
self.menuboard = board.MenuBoard(400, 80)
|
||||||
self.layout.addItem(self.gameboard)
|
self.layout.addItem(self.gameboard)
|
||||||
self.layout.addItem(self.menuboard)
|
self.layout.addItem(self.menuboard)
|
||||||
self.layout.setSpacing(50)
|
self.layout.setSpacing(50)
|
||||||
self.layout.setContentsMargins(50, 50, 50, 0)
|
self.layout.setContentsMargins(50, 50, 50, 0)
|
||||||
self.form.setLayout(self.layout)
|
self.form.setLayout(self.layout)
|
||||||
|
|
||||||
self.scene.addItem(self.form)
|
self.scene.addItem(self.form)
|
||||||
|
|
||||||
|
# Setting the view
|
||||||
self.setBackgroundBrush(QBrush(Qt.black))
|
self.setBackgroundBrush(QBrush(Qt.black))
|
||||||
self.setRenderHint(QPainter.Antialiasing)
|
self.setRenderHint(QPainter.Antialiasing)
|
||||||
#self.setGeometry(self.scene.sceneRect().toRect())
|
#self.setGeometry(self.scene.sceneRect().toRect())
|
||||||
|
|
||||||
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
||||||
self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
|
self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
# Cross-Board signal connections
|
||||||
self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus)
|
self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus)
|
||||||
|
|
||||||
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