From 8355b3dc9ae9d37204877d0abd2c2c022a936f22 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Fri, 19 Jul 2024 00:03:43 -0600 Subject: [PATCH] Mods --- cromulant/config.py | 6 ++++-- cromulant/game.py | 44 +++++++++++++++++++++++++++++++++++--------- cromulant/window.py | 17 +++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/cromulant/config.py b/cromulant/config.py index d4c2cd5..ad66a71 100644 --- a/cromulant/config.py +++ b/cromulant/config.py @@ -7,7 +7,7 @@ import appdirs # type: ignore class Config: title: str = "Cromulant" - width: int = 1000 + width: int = 900 height: int = 800 max_ants: int = 100 here: Path @@ -22,7 +22,9 @@ class Config: image_size: int = 80 space_1: int = 25 max_messages: int = 120 - loop_delay: int = 2_000 + loop_delay_fast: int = 3_000 + loop_delay_normal: int = 20_000 + loop_delay_slow: int = 60_000 @staticmethod def prepare() -> None: diff --git a/cromulant/game.py b/cromulant/game.py index e6d3526..ee6242f 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -7,6 +7,7 @@ from PySide6.QtCore import Qt # type: ignore from PySide6.QtWidgets import QHBoxLayout # type: ignore from PySide6.QtWidgets import QVBoxLayout from PySide6.QtWidgets import QLabel +from PySide6.QtWidgets import QWidget from PySide6.QtGui import QPixmap # type: ignore from PySide6.QtCore import QTimer @@ -34,7 +35,7 @@ class Game: container.addWidget(image_label) container.addSpacing(Config.space_1) - container.addLayout(right_container) + container.addWidget(right_container) Game.add_view_container(container) @staticmethod @@ -45,7 +46,7 @@ class Game: container.addWidget(image_label) container.addSpacing(Config.space_1) - container.addLayout(right_container) + container.addWidget(right_container) Game.add_view_container(container) @staticmethod @@ -60,15 +61,25 @@ class Game: Window.delete_layout(item.layout()) @staticmethod - def make_right_container(title: str, message: str) -> QVBoxLayout: + def make_right_container(title: str, message: str) -> QWidget: + root = QWidget() container = QVBoxLayout() container.setAlignment(Qt.AlignmentFlag.AlignTop) + title_label = QLabel(title) title_label.setStyleSheet("font-weight: bold;") + title_label.setWordWrap(True) + Window.expand(title_label) + message_label = QLabel(message) + message_label.setWordWrap(True) + Window.expand(message_label) + container.addWidget(title_label) container.addWidget(message_label) - return container + root.setLayout(container) + + return root @staticmethod def get_image(image_path: Path, border_color: tuple[int, int, int]) -> QLabel: @@ -83,13 +94,15 @@ class Game: ) image_label.setPixmap(scaled_pixmap) - image_label.setFixedSize( - scaled_pixmap.size() - ) # Set QLabel size to match QPixmap size + + image_label.setFixedSize(scaled_pixmap.size()) + border_rgb = Utils.get_rgb(border_color) + image_label.setStyleSheet( f"bpyside6. how do i make this start at the top. top alignedorder: 2px solid {border_rgb};" ) + return image_label @staticmethod @@ -136,7 +149,20 @@ class Game: @staticmethod def start_loop() -> None: - interval_ms = Config.loop_delay + speed = Window.speed.currentText() + + if speed == "Fast": + delay = Config.loop_delay_fast + elif speed == "Normal": + delay = Config.loop_delay_normal + else: + delay = Config.loop_delay_slow + Game.timer = QTimer() Game.timer.timeout.connect(Game.get_status) - Game.timer.start(interval_ms) + Game.timer.start(delay) + + @staticmethod + def update_speed() -> None: + Game.timer.stop() + Game.start_loop() diff --git a/cromulant/window.py b/cromulant/window.py index 7d12e92..67e6831 100644 --- a/cromulant/window.py +++ b/cromulant/window.py @@ -8,7 +8,9 @@ from PySide6.QtWidgets import QVBoxLayout from PySide6.QtWidgets import QPushButton from PySide6.QtWidgets import QHBoxLayout from PySide6.QtWidgets import QScrollArea +from PySide6.QtWidgets import QComboBox from PySide6.QtWidgets import QLayout +from PySide6.QtWidgets import QSizePolicy from PySide6.QtGui import QIcon # type: ignore from PySide6.QtCore import Qt # type: ignore @@ -21,6 +23,7 @@ class Window: root: QVBoxLayout view: QVBoxLayout view_scene: QGraphicsScene + speed: QComboBox @staticmethod def prepare() -> None: @@ -48,17 +51,27 @@ class Window: @staticmethod def add_buttons() -> None: + from .game import Game + btn_hatch = QPushButton("Hatch") btn_terminate = QPushButton("Terminate") + btn_close = QPushButton("Close") btn_hatch.clicked.connect(Window.hatch) btn_terminate.clicked.connect(Window.terminate) + + Window.speed = QComboBox() + Window.speed.addItems(["Fast", "Normal", "Slow"]) + Window.speed.setCurrentIndex(1) + Window.speed.currentIndexChanged.connect(Game.update_speed) + btn_close.clicked.connect(Window.close) layout = QHBoxLayout() layout.addWidget(btn_hatch) layout.addWidget(btn_terminate) + layout.addWidget(Window.speed) layout.addWidget(btn_close) Window.root.addLayout(layout) @@ -108,3 +121,7 @@ class Window: Window.delete_layout(item.layout()) layout.deleteLater() + + @staticmethod + def expand(widget: QWidget) -> None: + widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)