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
of the boards."""
from PyQt5.QtGui import QPen
from PyQt5.QtWidgets import QSizePolicy, QGraphicsWidget
from PyQt5.QtCore import (QAbstractAnimation, Qt, QLineF, QPropertyAnimation, pyqtProperty,
pyqtSignal, QSizeF, QRectF)
from PySide2.QtGui import QPen
from PySide2.QtWidgets import QSizePolicy, QGraphicsWidget
from PySide2.QtCore import (QAbstractAnimation, Qt, QLineF, QPropertyAnimation, Property, Signal, QSizeF, QRectF)
from . import sudoku_graphics as sdk_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.setEndValue(self.half_circumference)
# Defining the length to be drawn as a pyqtProperty
@pyqtProperty(float)
# Defining the length to be drawn as a Property
@Property(float)
def length(self):
"""float: The length of the box to be drawn
@ -120,16 +119,16 @@ class GameBoard(BoxBoard):
Attributes
----------
newGameSelected: pyqtSignal(str)
newGameSelected: Signal(str)
Emitted when the difficulty is selected from here. Emits the difficulty string
gridDrawn: pyqtSignal
gridDrawn: Signal
Emitted when the Sudoku grid has been drawn
sudokuDone: pyqtSignal
sudokuDone: Signal
Emitted when the Sudoku puzzle is finished
"""
newGameSelected = pyqtSignal(str)
gridDrawn = pyqtSignal()
sudokuDone = pyqtSignal()
newGameSelected = Signal(str)
gridDrawn = Signal()
sudokuDone = Signal()
def __init__(self, width, height, parent=None):
"""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
from PyQt5.QtCore import (QAbstractAnimation, Qt, QRectF, QLineF,
QPropertyAnimation, pyqtProperty, pyqtSignal)
from PyQt5.QtGui import QPen, QColor
from PyQt5.QtWidgets import (QGraphicsObject)
from PySide2.QtCore import (QAbstractAnimation, Qt, QRectF, QLineF,
QPropertyAnimation, Property, Signal)
from PySide2.QtGui import QPen, QColor
from PySide2.QtWidgets import (QGraphicsObject)
from .textbox import AnimatedText
@ -17,13 +17,13 @@ class AnimBox(QGraphicsObject):
Attributes
----------
hoverEnter: pyqtSignal
hoverEnter: Signal
Emitted when the mouse hover into the box
hoverExit: pyqtSignal
hoverExit: Signal
Emitted when the mouse hover out of the box
"""
hoverEnter = pyqtSignal()
hoverExit = pyqtSignal()
hoverEnter = Signal()
hoverExit = Signal()
def __init__(self, x, y, width, height, parent=None):
"""Prepares the box and animation
@ -134,7 +134,7 @@ class AnimBox(QGraphicsObject):
painter.setPen(self.default_pen)
painter.drawRect(self.btn_rect)
@pyqtProperty(float)
@Property(float)
def length(self):
"""float: The length of the highlight to be drawn.
When set, the length of the outlines are determined
@ -198,10 +198,10 @@ class RingButton(AnimBox):
Attributes
----------
buttonClicked: pyqtSignal(str)
buttonClicked: Signal(str)
Emitted when it is clicked. Sends the text of the button
"""
buttonClicked = pyqtSignal(str)
buttonClicked = Signal(str)
# Initialisation
def __init__(self, x, y, width, height, text, parent=None):
@ -260,10 +260,10 @@ class MenuButton(AnimBox):
Attributes
----------
buttonClicked: pyqtSignal(str)
buttonClicked: Signal(str)
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):
"""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
from PyQt5.Qt import QApplication
from PyQt5.QtCore import (Qt, QRectF, pyqtSignal, QSizeF, QTimer)
from PyQt5.QtGui import QPainter, QBrush, QPen
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
QGraphicsObject, QGraphicsProxyWidget,
QGraphicsScene, QGraphicsView, )
from PySide2.QtCore import (Qt, QRectF, Signal, QSizeF, QTimer)
from PySide2.QtGui import QPainter, QBrush, QPen
from PySide2.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem, QGraphicsObject, QGraphicsProxyWidget, QGraphicsScene, QGraphicsView, QApplication)
from general.highscore import DIFFICULTIES
if __name__ == "__main__":
@ -72,8 +69,8 @@ class TimerDisplayer(QGraphicsWidget):
class DifficultyDisplayer(QGraphicsWidget):
notFocus = pyqtSignal()
difficultySelected = pyqtSignal(str)
notFocus = Signal()
difficultySelected = Signal(str)
def __init__(self, parent=None):
super().__init__(parent=parent)
@ -142,8 +139,8 @@ class DifficultyDisplayer(QGraphicsWidget):
class DifficultyMenu(QGraphicsWidget):
menuClicked = pyqtSignal(str)
loseFocus = pyqtSignal()
menuClicked = Signal(str)
loseFocus = Signal()
def __init__(self, width, height, parent=None):
super().__init__(parent=parent)

View File

@ -2,9 +2,8 @@ import random
import sys
import os
from PyQt5.Qt import QApplication
from PyQt5.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, pyqtProperty, pyqtSignal, QTimer)
from PyQt5.QtWidgets import (QWidget, QLineEdit, QHBoxLayout, QGridLayout, QVBoxLayout, QPushButton, QLabel)
from PySide2.QtCore import (QAbstractAnimation, Qt, QPropertyAnimation, Property, Signal, QTimer)
from PySide2.QtWidgets import (QWidget, QLineEdit, QHBoxLayout, QGridLayout, QVBoxLayout, QPushButton, QLabel, QApplication)
if not __name__ == "__main__":
current_dir = os.getcwd()
@ -25,7 +24,7 @@ FORWARD = -1
class HighScoreBoard(QWidget):
highScoreSet = pyqtSignal()
highScoreSet = Signal()
def __init__(self, width, height):
super().__init__()
@ -82,7 +81,7 @@ class HighScoreBoard(QWidget):
class DifficultySwitch(QHBoxLayout):
difficultySelected = pyqtSignal(str)
difficultySelected = Signal(str)
def __init__(self):
super().__init__()
@ -113,7 +112,7 @@ class DifficultySwitch(QHBoxLayout):
left_btn.clicked.connect(lambda: self.shift_difficulty(BACKWARD))
right_btn.clicked.connect(lambda: self.shift_difficulty(FORWARD))
@pyqtProperty(int)
@Property(int)
def show_pos(self):
"""
int : The value for the animation
@ -153,7 +152,7 @@ class DifficultySwitch(QHBoxLayout):
class ScoreGrid(QGridLayout):
scoreUpdate = pyqtSignal(str)
scoreUpdate = Signal(str)
def __init__(self):
super().__init__()
@ -200,7 +199,7 @@ class ScoreGrid(QGridLayout):
class NameInput(QWidget):
nameReceived = pyqtSignal(str)
nameReceived = Signal(str)
def __init__(self):
super().__init__()
@ -235,4 +234,4 @@ if __name__ == '__main__':
ex = HighScoreBoard(500, 500)
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
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
QPropertyAnimation, pyqtProperty, pyqtSignal)
from PyQt5.QtGui import QPen, QFont
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
from PySide2.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF, QPropertyAnimation, Property, Signal)
from PySide2.QtGui import QPen, QFont
from PySide2.QtWidgets import QGraphicsItem, QGraphicsObject
from gameplay import sudoku_gameplay as sdk
from general.extras import bound_value
@ -86,9 +85,9 @@ class NumberPainter(BaseSudokuItem):
class SudokuGrid(BaseSudokuItem):
buttonClicked = pyqtSignal(float, float, bool)
finishDrawing = pyqtSignal()
puzzleFinished = pyqtSignal()
buttonClicked = Signal(float, float, bool)
finishDrawing = Signal()
puzzleFinished = Signal()
def __init__(self, width, height, parent=None):
super().__init__(parent)
@ -251,8 +250,8 @@ class SudokuGrid(BaseSudokuItem):
if event.key() == SCRIBBLE_KEY and self.scribbling:
self.scribbling = False
# Defining the length to be drawn as a pyqtProperty
@pyqtProperty(float)
# Defining the length to be drawn as a Property
@Property(float)
def length(self):
return self._length
@ -277,8 +276,8 @@ class SudokuGrid(BaseSudokuItem):
class NumberRing(BaseSudokuItem):
loseFocus = pyqtSignal()
keyPressed = pyqtSignal(str, bool)
loseFocus = Signal()
keyPressed = Signal(str, bool)
def __init__(self, parent=None):
super().__init__(parent=parent)
@ -400,8 +399,8 @@ class NumberRing(BaseSudokuItem):
for btn in self.cell_buttons:
btn.set_transparent(state)
# Defining the length to be drawn as a pyqtProperty
@pyqtProperty(float)
# Defining the length to be drawn as a Property
@Property(float)
def radius(self):
return self._radius
@ -421,7 +420,7 @@ class NumberRing(BaseSudokuItem):
class PlayMenu(BaseSudokuItem):
buttonClicked = pyqtSignal(str)
buttonClicked = Signal(str)
def __init__(self, parent):
super().__init__(parent=parent)

View File

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

View File

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

View File

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