Add timer
parent
df3d6a2deb
commit
4017cb1dec
|
@ -1,3 +1,4 @@
|
||||||
venv/
|
venv/
|
||||||
demos/
|
demos/
|
||||||
.idea/
|
.idea/
|
||||||
|
*.pyc
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,12 +1,12 @@
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem,
|
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem,
|
||||||
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
||||||
QGraphicsItemGroup, QGraphicsPathItem)
|
QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLinearLayout)
|
||||||
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
||||||
QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF)
|
QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF)
|
||||||
|
|
||||||
from graphic_components import sudoku_graphics as sdk_grap
|
from graphic_components import sudoku_graphics as sdk_grap
|
||||||
|
from graphic_components import menu_graphics as menu_grap
|
||||||
|
|
||||||
class BoxBoard(QGraphicsWidget):
|
class BoxBoard(QGraphicsWidget):
|
||||||
|
|
||||||
|
@ -40,9 +40,10 @@ 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)
|
||||||
|
#painter.drawRect(self.geometry())
|
||||||
|
|
||||||
def sizeHint(self, which, constraint=None):
|
def sizeHint(self, which, constraint=None):
|
||||||
return QSizeF(self.width+10, self.height+10)
|
return QSizeF(self.width, self.height)
|
||||||
|
|
||||||
|
|
||||||
class GameBoard(BoxBoard):
|
class GameBoard(BoxBoard):
|
||||||
|
@ -76,3 +77,17 @@ class MenuBoard(BoxBoard):
|
||||||
# TODO: Create the components for the menu: A timer and a difficulty selector
|
# TODO: Create the components for the menu: A timer and a difficulty selector
|
||||||
def __init__(self, width, height, parent=None):
|
def __init__(self, width, height, parent=None):
|
||||||
super().__init__(width, height, parent)
|
super().__init__(width, height, parent)
|
||||||
|
|
||||||
|
self.layout = QGraphicsLinearLayout(Qt.Horizontal)
|
||||||
|
self.layout.setMaximumWidth(width)
|
||||||
|
self.layout.setMaximumHeight(height)
|
||||||
|
|
||||||
|
self.timer_display = menu_grap.TimerDisplayer(parent=self)
|
||||||
|
self.timer_display2 = menu_grap.TimerDisplayer(parent=self)
|
||||||
|
self.timer_display3 = menu_grap.TimerDisplayer(parent=self)
|
||||||
|
self.layout.addItem(self.timer_display)
|
||||||
|
self.layout.addItem(self.timer_display2)
|
||||||
|
self.layout.addItem(self.timer_display3)
|
||||||
|
self.layout.setSpacing(0)
|
||||||
|
|
||||||
|
self.setLayout(self.layout)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
|
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem,
|
||||||
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
||||||
|
QGraphicsItemGroup, QGraphicsLayoutItem)
|
||||||
|
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
||||||
|
QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF)
|
||||||
|
|
||||||
|
|
||||||
|
class TimerDisplayer(QGraphicsWidget):
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.width = 100
|
||||||
|
self.height = 50
|
||||||
|
|
||||||
|
self.box_pen = QPen()
|
||||||
|
self.box_pen.setColor(Qt.white)
|
||||||
|
self.pen_width = 3
|
||||||
|
self.box_pen.setWidth(self.pen_width)
|
||||||
|
|
||||||
|
|
||||||
|
self.timer_box = QRectF(0, 0, self.width, self.height)
|
||||||
|
#self.setGeometry(self.timer_box)
|
||||||
|
#print(self.geometry().width())
|
||||||
|
|
||||||
|
def paint(self, painter, style, widget=None):
|
||||||
|
box = self.geometry()
|
||||||
|
#print(self.size().width())
|
||||||
|
painter.setPen(self.box_pen)
|
||||||
|
painter.drawRect(box)
|
||||||
|
painter.drawText(box, Qt.AlignCenter, "00:00")
|
||||||
|
|
||||||
|
def boundingRect(self):
|
||||||
|
return QRectF(QPointF(0, 0), self.geometry().size())
|
||||||
|
|
||||||
|
def sizeHint(self, which, constraint=None):
|
||||||
|
return QSizeF(self.width, self.height)
|
||||||
|
#print(self.geometry().size().width(), self.geometry().size().height())
|
||||||
|
#return self.geometry().size()
|
||||||
|
|
||||||
|
def setGeometry(self, rect):
|
||||||
|
self.prepareGeometryChange()
|
||||||
|
QGraphicsLayoutItem.setGeometry(self, rect)
|
||||||
|
self.setPos(rect.topLeft())
|
|
@ -177,6 +177,3 @@ class NumberRing(QGraphicsItem):
|
||||||
def connect_button_signals(self, func):
|
def connect_button_signals(self, func):
|
||||||
for btn in self.cell_buttons:
|
for btn in self.cell_buttons:
|
||||||
btn.buttonClicked.connect(func)
|
btn.buttonClicked.connect(func)
|
||||||
|
|
||||||
#def mousePressEvent(self, event):
|
|
||||||
# print('Yes')
|
|
12
main.py
12
main.py
|
@ -21,7 +21,7 @@ class SudokuWindow(QGraphicsView):
|
||||||
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.gameboard = board.GameBoard(400, 400)
|
||||||
self.menuboard = board.BoxBoard(400, 50)
|
self.menuboard = board.MenuBoard(400, 80)
|
||||||
|
|
||||||
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
||||||
self.layout.addItem(self.gameboard)
|
self.layout.addItem(self.gameboard)
|
||||||
|
@ -39,6 +39,16 @@ class SudokuWindow(QGraphicsView):
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
print('menuboard')
|
||||||
|
menubox = self.menuboard.geometry()
|
||||||
|
print(menubox.left(), menubox.top())
|
||||||
|
print(menubox.width(), menubox.height())
|
||||||
|
|
||||||
|
print('menuboard')
|
||||||
|
gamebox = self.gameboard.geometry()
|
||||||
|
print(gamebox.left(), gamebox.top())
|
||||||
|
print(gamebox.width(), gamebox.height())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = 0
|
app = 0
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
Loading…
Reference in New Issue