Change to use PySide

master
En Yi 2022-07-09 13:09:57 +08:00
parent 577a8a72fe
commit a4e9ffef0d
8 changed files with 62 additions and 70 deletions

View File

@ -1,10 +1,9 @@
"""This module contains the two boards shown in the program. A base BoxBoard class provides the drawing and animation """This module contains the two boards shown in the program. A base BoxBoard class provides the drawing and animation
of the boards.""" of the boards."""
from PyQt5.QtGui import QPen from PySide2.QtGui import QPen
from PyQt5.QtWidgets import QSizePolicy, QGraphicsWidget from PySide2.QtWidgets import QSizePolicy, QGraphicsWidget
from PyQt5.QtCore import (QAbstractAnimation, Qt, QLineF, QPropertyAnimation, pyqtProperty, from PySide2.QtCore import (QAbstractAnimation, Qt, QLineF, QPropertyAnimation, Property, Signal, QSizeF, QRectF)
pyqtSignal, QSizeF, QRectF)
from . import sudoku_graphics as sdk_grap from . import sudoku_graphics as sdk_grap
from . import menu_graphics as menu_grap from . import menu_graphics as menu_grap
@ -61,8 +60,8 @@ 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)
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a Property
@pyqtProperty(float) @Property(float)
def length(self): def length(self):
"""float: The length of the box to be drawn """float: The length of the box to be drawn
@ -120,16 +119,16 @@ class GameBoard(BoxBoard):
Attributes Attributes
---------- ----------
newGameSelected: pyqtSignal(str) newGameSelected: Signal(str)
Emitted when the difficulty is selected from here. Emits the difficulty string Emitted when the difficulty is selected from here. Emits the difficulty string
gridDrawn: pyqtSignal gridDrawn: Signal
Emitted when the Sudoku grid has been drawn Emitted when the Sudoku grid has been drawn
sudokuDone: pyqtSignal sudokuDone: Signal
Emitted when the Sudoku puzzle is finished Emitted when the Sudoku puzzle is finished
""" """
newGameSelected = pyqtSignal(str) newGameSelected = Signal(str)
gridDrawn = pyqtSignal() gridDrawn = Signal()
sudokuDone = pyqtSignal() sudokuDone = Signal()
def __init__(self, width, height, parent=None): def __init__(self, width, height, parent=None):
"""Create the game area consisting of a Sudoku Grid and a Number Ring, """Create the game area consisting of a Sudoku Grid and a Number Ring,

View File

@ -4,10 +4,10 @@ by all the buttons.
import math import math
from PyQt5.QtCore import (QAbstractAnimation, Qt, QRectF, QLineF, from PySide2.QtCore import (QAbstractAnimation, Qt, QRectF, QLineF,
QPropertyAnimation, pyqtProperty, pyqtSignal) QPropertyAnimation, Property, Signal)
from PyQt5.QtGui import QPen, QColor from PySide2.QtGui import QPen, QColor
from PyQt5.QtWidgets import (QGraphicsObject) from PySide2.QtWidgets import (QGraphicsObject)
from .textbox import AnimatedText from .textbox import AnimatedText
@ -17,13 +17,13 @@ class AnimBox(QGraphicsObject):
Attributes Attributes
---------- ----------
hoverEnter: pyqtSignal hoverEnter: Signal
Emitted when the mouse hover into the box Emitted when the mouse hover into the box
hoverExit: pyqtSignal hoverExit: Signal
Emitted when the mouse hover out of the box Emitted when the mouse hover out of the box
""" """
hoverEnter = pyqtSignal() hoverEnter = Signal()
hoverExit = pyqtSignal() hoverExit = Signal()
def __init__(self, x, y, width, height, parent=None): def __init__(self, x, y, width, height, parent=None):
"""Prepares the box and animation """Prepares the box and animation
@ -134,7 +134,7 @@ class AnimBox(QGraphicsObject):
painter.setPen(self.default_pen) painter.setPen(self.default_pen)
painter.drawRect(self.btn_rect) painter.drawRect(self.btn_rect)
@pyqtProperty(float) @Property(float)
def length(self): def length(self):
"""float: The length of the highlight to be drawn. """float: The length of the highlight to be drawn.
When set, the length of the outlines are determined When set, the length of the outlines are determined
@ -198,10 +198,10 @@ class RingButton(AnimBox):
Attributes Attributes
---------- ----------
buttonClicked: pyqtSignal(str) buttonClicked: Signal(str)
Emitted when it is clicked. Sends the text of the button Emitted when it is clicked. Sends the text of the button
""" """
buttonClicked = pyqtSignal(str) buttonClicked = Signal(str)
# Initialisation # Initialisation
def __init__(self, x, y, width, height, text, parent=None): def __init__(self, x, y, width, height, text, parent=None):
@ -260,10 +260,10 @@ class MenuButton(AnimBox):
Attributes Attributes
---------- ----------
buttonClicked: pyqtSignal(str) buttonClicked: Signal(str)
Emitted when it is clicked. Sends the text of the button Emitted when it is clicked. Sends the text of the button
""" """
buttonClicked = pyqtSignal(str) buttonClicked = Signal(str)
def __init__(self, x, y, width, height, text, parent=None): def __init__(self, x, y, width, height, text, parent=None):
"""Set the text and create AnimatedText """Set the text and create AnimatedText

View File

@ -4,12 +4,9 @@ This module contains the components that make up the menu Board
import sys import sys
from PyQt5.Qt import QApplication from PySide2.QtCore import (Qt, QRectF, Signal, QSizeF, QTimer)
from PyQt5.QtCore import (Qt, QRectF, pyqtSignal, QSizeF, QTimer) from PySide2.QtGui import QPainter, QBrush, QPen
from PyQt5.QtGui import QPainter, QBrush, QPen from PySide2.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem, QGraphicsObject, QGraphicsProxyWidget, QGraphicsScene, QGraphicsView, QApplication)
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
QGraphicsObject, QGraphicsProxyWidget,
QGraphicsScene, QGraphicsView, )
from general.highscore import DIFFICULTIES from general.highscore import DIFFICULTIES
if __name__ == "__main__": if __name__ == "__main__":
@ -72,8 +69,8 @@ class TimerDisplayer(QGraphicsWidget):
class DifficultyDisplayer(QGraphicsWidget): class DifficultyDisplayer(QGraphicsWidget):
notFocus = pyqtSignal() notFocus = Signal()
difficultySelected = pyqtSignal(str) difficultySelected = Signal(str)
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
@ -142,8 +139,8 @@ class DifficultyDisplayer(QGraphicsWidget):
class DifficultyMenu(QGraphicsWidget): class DifficultyMenu(QGraphicsWidget):
menuClicked = pyqtSignal(str) menuClicked = Signal(str)
loseFocus = pyqtSignal() loseFocus = Signal()
def __init__(self, width, height, parent=None): def __init__(self, width, height, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)

View File

@ -2,9 +2,8 @@ import random
import sys import sys
import os import os
from PyQt5.Qt import QApplication from PySide2.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, Property, Signal, QTimer)
from PyQt5.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, pyqtProperty, pyqtSignal, QTimer) from PySide2.QtWidgets import (QWidget, QLineEdit, QHBoxLayout, QGridLayout, QVBoxLayout, QPushButton, QLabel, QApplication)
from PyQt5.QtWidgets import (QWidget, QLineEdit, QHBoxLayout, QGridLayout, QVBoxLayout, QPushButton, QLabel)
if not __name__ == "__main__": if not __name__ == "__main__":
current_dir = os.getcwd() current_dir = os.getcwd()
@ -25,7 +24,7 @@ FORWARD = -1
class HighScoreBoard(QWidget): class HighScoreBoard(QWidget):
highScoreSet = pyqtSignal() highScoreSet = Signal()
def __init__(self, width, height): def __init__(self, width, height):
super().__init__() super().__init__()
@ -82,7 +81,7 @@ class HighScoreBoard(QWidget):
class DifficultySwitch(QHBoxLayout): class DifficultySwitch(QHBoxLayout):
difficultySelected = pyqtSignal(str) difficultySelected = Signal(str)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -113,7 +112,7 @@ class DifficultySwitch(QHBoxLayout):
left_btn.clicked.connect(lambda: self.shift_difficulty(BACKWARD)) left_btn.clicked.connect(lambda: self.shift_difficulty(BACKWARD))
right_btn.clicked.connect(lambda: self.shift_difficulty(FORWARD)) right_btn.clicked.connect(lambda: self.shift_difficulty(FORWARD))
@pyqtProperty(int) @Property(int)
def show_pos(self): def show_pos(self):
""" """
int : The value for the animation int : The value for the animation
@ -153,7 +152,7 @@ class DifficultySwitch(QHBoxLayout):
class ScoreGrid(QGridLayout): class ScoreGrid(QGridLayout):
scoreUpdate = pyqtSignal(str) scoreUpdate = Signal(str)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -200,7 +199,7 @@ class ScoreGrid(QGridLayout):
class NameInput(QWidget): class NameInput(QWidget):
nameReceived = pyqtSignal(str) nameReceived = Signal(str)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -235,4 +234,4 @@ if __name__ == '__main__':
ex = HighScoreBoard(500, 500) ex = HighScoreBoard(500, 500)
ex.show() ex.show()
sys.exit(app.exec_()) sys.exit(app.exec_())

View File

@ -3,10 +3,9 @@ This module contains the components that make up the Sudoku Board
""" """
import numpy as np import numpy as np
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF, from PySide2.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF, QPropertyAnimation, Property, Signal)
QPropertyAnimation, pyqtProperty, pyqtSignal) from PySide2.QtGui import QPen, QFont
from PyQt5.QtGui import QPen, QFont from PySide2.QtWidgets import QGraphicsItem, QGraphicsObject
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
from gameplay import sudoku_gameplay as sdk from gameplay import sudoku_gameplay as sdk
from general.extras import bound_value from general.extras import bound_value
@ -86,9 +85,9 @@ class NumberPainter(BaseSudokuItem):
class SudokuGrid(BaseSudokuItem): class SudokuGrid(BaseSudokuItem):
buttonClicked = pyqtSignal(float, float, bool) buttonClicked = Signal(float, float, bool)
finishDrawing = pyqtSignal() finishDrawing = Signal()
puzzleFinished = pyqtSignal() puzzleFinished = Signal()
def __init__(self, width, height, parent=None): def __init__(self, width, height, parent=None):
super().__init__(parent) super().__init__(parent)
@ -251,8 +250,8 @@ class SudokuGrid(BaseSudokuItem):
if event.key() == SCRIBBLE_KEY and self.scribbling: if event.key() == SCRIBBLE_KEY and self.scribbling:
self.scribbling = False self.scribbling = False
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a Property
@pyqtProperty(float) @Property(float)
def length(self): def length(self):
return self._length return self._length
@ -277,8 +276,8 @@ class SudokuGrid(BaseSudokuItem):
class NumberRing(BaseSudokuItem): class NumberRing(BaseSudokuItem):
loseFocus = pyqtSignal() loseFocus = Signal()
keyPressed = pyqtSignal(str, bool) keyPressed = Signal(str, bool)
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
@ -400,8 +399,8 @@ class NumberRing(BaseSudokuItem):
for btn in self.cell_buttons: for btn in self.cell_buttons:
btn.set_transparent(state) btn.set_transparent(state)
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a Property
@pyqtProperty(float) @Property(float)
def radius(self): def radius(self):
return self._radius return self._radius
@ -421,7 +420,7 @@ class NumberRing(BaseSudokuItem):
class PlayMenu(BaseSudokuItem): class PlayMenu(BaseSudokuItem):
buttonClicked = pyqtSignal(str) buttonClicked = Signal(str)
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent=parent) super().__init__(parent=parent)

View File

@ -1,8 +1,8 @@
import random import random
from PyQt5.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, pyqtProperty) from PySide2.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, Property)
from PyQt5.QtGui import QPen from PySide2.QtGui import QPen
from PyQt5.QtWidgets import QGraphicsObject, QLabel from PySide2.QtWidgets import QGraphicsObject, QLabel
class AnimatedText(QGraphicsObject): class AnimatedText(QGraphicsObject):
@ -51,8 +51,8 @@ class AnimatedText(QGraphicsObject):
painter.setPen(self.default_pen) painter.setPen(self.default_pen)
painter.drawText(self.parent.boundingRect(), Qt.AlignCenter, self.shown_text) painter.drawText(self.parent.boundingRect(), Qt.AlignCenter, self.shown_text)
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a Property
@pyqtProperty(int) @Property(int)
def shown_length(self): def shown_length(self):
return self._shown_length return self._shown_length
@ -132,7 +132,7 @@ class AnimatedLabel(QLabel):
# """) # """)
self.toggle_anim(True) self.toggle_anim(True)
@pyqtProperty(int) @Property(int)
def shown_length(self): def shown_length(self):
""" """
int : The value for the animation int : The value for the animation

View File

@ -1,10 +1,9 @@
"""This is the main module to be run. Contains the program itself. """This is the main module to be run. Contains the program itself.
""" """
from PyQt5.QtGui import QPainter, QBrush from PySide2.QtGui import QPainter, QBrush
from PyQt5.Qt import QApplication from PySide2.QtWidgets import QApplication, QGraphicsScene, QGraphicsView, QGraphicsWidget, QGraphicsLinearLayout
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsWidget, QGraphicsLinearLayout from PySide2.QtCore import Qt
from PyQt5.QtCore import Qt
import sys import sys
from graphic_components import board from graphic_components import board

View File

@ -1,3 +1,2 @@
numpy==1.22.0 numpy==1.22.0
PyQt5==5.9.2 PySide2>=5.15.2
sip==4.19.6