From 77f693b7b7bfac1b34f1ce92485cc92430f2b7ff Mon Sep 17 00:00:00 2001 From: En Yi Date: Tue, 10 Jul 2018 19:49:33 +0800 Subject: [PATCH] Add comments --- graphic_components/board.py | 23 ++++++++++++++++------- graphic_components/buttons.py | 4 ++++ graphic_components/menu_graphics.py | 4 ++++ graphic_components/sudoku_graphics.py | 7 ++++--- main.py | 19 ++++++++++--------- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/graphic_components/board.py b/graphic_components/board.py index 9beb8ad..d3d89f5 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -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) diff --git a/graphic_components/buttons.py b/graphic_components/buttons.py index 3b22ed0..7720df0 100644 --- a/graphic_components/buttons.py +++ b/graphic_components/buttons.py @@ -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, diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py index f619f6b..50e903b 100644 --- a/graphic_components/menu_graphics.py +++ b/graphic_components/menu_graphics.py @@ -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, diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index e31f0d9..c6d2076 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -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): diff --git a/main.py b/main.py index 3efce28..895261e 100644 --- a/main.py +++ b/main.py @@ -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