Add comments

master
En Yi 2018-07-10 19:49:33 +08:00
parent 7aace4df50
commit 77f693b7b7
5 changed files with 38 additions and 19 deletions

View File

@ -11,22 +11,25 @@ from general import extras
class BoxBoard(QGraphicsWidget):
"""
A generic board that draws an animated rectangular border
"""
# Initialisation
def __init__(self, width, height, parent=None):
super().__init__(parent)
self.width = width
self.height = height
self.half_circumference = width+height
self.freeze = False
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.setHeightForWidth(True)
self.setSizePolicy(self.size_policy)
# Set up pens for drawing
# Set up a default pen for drawing
self.default_pen = QPen()
self.default_pen.setColor(Qt.white)
self.default_pen.setWidth(5)
@ -49,8 +52,6 @@ class BoxBoard(QGraphicsWidget):
self.anim.setKeyValueAt(t / 10, self.half_circumference * t/10)
self.anim.setEndValue(self.half_circumference)
self.freeze = False
# Toggle the animation to be play forward or backward
def toggle_anim(self, toggling):
if toggling:
@ -66,7 +67,7 @@ class BoxBoard(QGraphicsWidget):
for line in self.line_order:
if line.length() > 1:
painter.drawLine(line)
super().paint(painter, style, widget)
#super().paint(painter, style, widget)
# Defining the length to be drawn as a pyqtProperty
@pyqtProperty(float)
@ -92,6 +93,10 @@ class BoxBoard(QGraphicsWidget):
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)
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.numring = sdk_grap.NumberRing(parent=self)
self.playmenu = sdk_grap.PlayMenu(parent=self)
self.show_grid(False)
self.show_playmenu(False)
@ -141,7 +147,10 @@ class GameBoard(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):
super().__init__(width, height, parent)

View File

@ -1,3 +1,7 @@
"""
This module contains all kinds of animated buttons
"""
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
from PyQt5.Qt import QApplication, QTimer
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsView, QGraphicsItem,

View File

@ -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.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,

View File

@ -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.QtWidgets import QGraphicsItem, QGraphicsObject
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
@ -234,8 +237,6 @@ class NumberRing(BaseSudokuItem):
# Reimplemented paint
def paint(self, painter, style, widget=None):
#painter.setPen(self.default_pen)
#painter.drawRect(self.boundingRect())
pass
def connect_button_signals(self, func):

19
main.py
View File

@ -11,41 +11,42 @@ from graphic_components import board
class SudokuWindow(QGraphicsView):
"""
The main window that shows the graphical components.
Contains the Sudoku Board and the Menu Board.
"""
def __init__(self):
super().__init__()
# Set up the Scene to manage the GraphicItems
self.scene = QGraphicsScene(0, 0, 500, 600, self)
self.setScene(self.scene)
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.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.menuboard)
self.layout.setSpacing(50)
self.layout.setContentsMargins(50, 50, 50, 0)
self.form.setLayout(self.layout)
self.scene.addItem(self.form)
# Setting the view
self.setBackgroundBrush(QBrush(Qt.black))
self.setRenderHint(QPainter.Antialiasing)
#self.setGeometry(self.scene.sceneRect().toRect())
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
self.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)
self.show()
# Cross-Board signal connections
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__":
app = 0