diff --git a/.gitignore b/.gitignore index acf12e7..da89402 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ venv/ demos/ .idea/ +*.pyc diff --git a/gameplay/__pycache__/sudoku_gameplay.cpython-35.pyc b/gameplay/__pycache__/sudoku_gameplay.cpython-35.pyc index d7997b7..64973b3 100644 Binary files a/gameplay/__pycache__/sudoku_gameplay.cpython-35.pyc and b/gameplay/__pycache__/sudoku_gameplay.cpython-35.pyc differ diff --git a/graphic_components/__pycache__/board.cpython-35.pyc b/graphic_components/__pycache__/board.cpython-35.pyc index 530f552..54515b7 100644 Binary files a/graphic_components/__pycache__/board.cpython-35.pyc and b/graphic_components/__pycache__/board.cpython-35.pyc differ diff --git a/graphic_components/board.py b/graphic_components/board.py index 7407c45..c4fb82b 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -1,12 +1,12 @@ from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem, QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject, - QGraphicsItemGroup, QGraphicsPathItem) + QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLinearLayout) from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF, QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF) from graphic_components import sudoku_graphics as sdk_grap - +from graphic_components import menu_graphics as menu_grap class BoxBoard(QGraphicsWidget): @@ -40,9 +40,10 @@ class BoxBoard(QGraphicsWidget): for line in self.line_order: if line.length() > 1: painter.drawLine(line) + #painter.drawRect(self.geometry()) def sizeHint(self, which, constraint=None): - return QSizeF(self.width+10, self.height+10) + return QSizeF(self.width, self.height) class GameBoard(BoxBoard): @@ -76,3 +77,17 @@ class MenuBoard(BoxBoard): # TODO: Create the components for the menu: A timer and a difficulty selector def __init__(self, width, height, parent=None): 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) diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py new file mode 100644 index 0000000..70fdc76 --- /dev/null +++ b/graphic_components/menu_graphics.py @@ -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()) diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index 6c0e1b3..af340b1 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -177,6 +177,3 @@ class NumberRing(QGraphicsItem): def connect_button_signals(self, func): for btn in self.cell_buttons: btn.buttonClicked.connect(func) - - #def mousePressEvent(self, event): - # print('Yes') \ No newline at end of file diff --git a/main.py b/main.py index 7b7547f..800362a 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ class SudokuWindow(QGraphicsView): self.setScene(self.scene) self.setSceneRect(self.scene.sceneRect()) 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.addItem(self.gameboard) @@ -39,6 +39,16 @@ class SudokuWindow(QGraphicsView): 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__": app = 0 app = QApplication(sys.argv)