This commit is contained in:
Auric Vente 2024-07-19 00:03:43 -06:00
parent 4f4c2b00e0
commit 8355b3dc9a
3 changed files with 56 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import appdirs # type: ignore
class Config: class Config:
title: str = "Cromulant" title: str = "Cromulant"
width: int = 1000 width: int = 900
height: int = 800 height: int = 800
max_ants: int = 100 max_ants: int = 100
here: Path here: Path
@ -22,7 +22,9 @@ class Config:
image_size: int = 80 image_size: int = 80
space_1: int = 25 space_1: int = 25
max_messages: int = 120 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 @staticmethod
def prepare() -> None: def prepare() -> None:

View File

@ -7,6 +7,7 @@ from PySide6.QtCore import Qt # type: ignore
from PySide6.QtWidgets import QHBoxLayout # type: ignore from PySide6.QtWidgets import QHBoxLayout # type: ignore
from PySide6.QtWidgets import QVBoxLayout from PySide6.QtWidgets import QVBoxLayout
from PySide6.QtWidgets import QLabel from PySide6.QtWidgets import QLabel
from PySide6.QtWidgets import QWidget
from PySide6.QtGui import QPixmap # type: ignore from PySide6.QtGui import QPixmap # type: ignore
from PySide6.QtCore import QTimer from PySide6.QtCore import QTimer
@ -34,7 +35,7 @@ class Game:
container.addWidget(image_label) container.addWidget(image_label)
container.addSpacing(Config.space_1) container.addSpacing(Config.space_1)
container.addLayout(right_container) container.addWidget(right_container)
Game.add_view_container(container) Game.add_view_container(container)
@staticmethod @staticmethod
@ -45,7 +46,7 @@ class Game:
container.addWidget(image_label) container.addWidget(image_label)
container.addSpacing(Config.space_1) container.addSpacing(Config.space_1)
container.addLayout(right_container) container.addWidget(right_container)
Game.add_view_container(container) Game.add_view_container(container)
@staticmethod @staticmethod
@ -60,15 +61,25 @@ class Game:
Window.delete_layout(item.layout()) Window.delete_layout(item.layout())
@staticmethod @staticmethod
def make_right_container(title: str, message: str) -> QVBoxLayout: def make_right_container(title: str, message: str) -> QWidget:
root = QWidget()
container = QVBoxLayout() container = QVBoxLayout()
container.setAlignment(Qt.AlignmentFlag.AlignTop) container.setAlignment(Qt.AlignmentFlag.AlignTop)
title_label = QLabel(title) title_label = QLabel(title)
title_label.setStyleSheet("font-weight: bold;") title_label.setStyleSheet("font-weight: bold;")
title_label.setWordWrap(True)
Window.expand(title_label)
message_label = QLabel(message) message_label = QLabel(message)
message_label.setWordWrap(True)
Window.expand(message_label)
container.addWidget(title_label) container.addWidget(title_label)
container.addWidget(message_label) container.addWidget(message_label)
return container root.setLayout(container)
return root
@staticmethod @staticmethod
def get_image(image_path: Path, border_color: tuple[int, int, int]) -> QLabel: 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.setPixmap(scaled_pixmap)
image_label.setFixedSize(
scaled_pixmap.size() image_label.setFixedSize(scaled_pixmap.size())
) # Set QLabel size to match QPixmap size
border_rgb = Utils.get_rgb(border_color) border_rgb = Utils.get_rgb(border_color)
image_label.setStyleSheet( image_label.setStyleSheet(
f"bpyside6. how do i make this start at the top. top alignedorder: 2px solid {border_rgb};" f"bpyside6. how do i make this start at the top. top alignedorder: 2px solid {border_rgb};"
) )
return image_label return image_label
@staticmethod @staticmethod
@ -136,7 +149,20 @@ class Game:
@staticmethod @staticmethod
def start_loop() -> None: 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 = QTimer()
Game.timer.timeout.connect(Game.get_status) 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()

View File

@ -8,7 +8,9 @@ from PySide6.QtWidgets import QVBoxLayout
from PySide6.QtWidgets import QPushButton from PySide6.QtWidgets import QPushButton
from PySide6.QtWidgets import QHBoxLayout from PySide6.QtWidgets import QHBoxLayout
from PySide6.QtWidgets import QScrollArea from PySide6.QtWidgets import QScrollArea
from PySide6.QtWidgets import QComboBox
from PySide6.QtWidgets import QLayout from PySide6.QtWidgets import QLayout
from PySide6.QtWidgets import QSizePolicy
from PySide6.QtGui import QIcon # type: ignore from PySide6.QtGui import QIcon # type: ignore
from PySide6.QtCore import Qt # type: ignore from PySide6.QtCore import Qt # type: ignore
@ -21,6 +23,7 @@ class Window:
root: QVBoxLayout root: QVBoxLayout
view: QVBoxLayout view: QVBoxLayout
view_scene: QGraphicsScene view_scene: QGraphicsScene
speed: QComboBox
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
@ -48,17 +51,27 @@ class Window:
@staticmethod @staticmethod
def add_buttons() -> None: def add_buttons() -> None:
from .game import Game
btn_hatch = QPushButton("Hatch") btn_hatch = QPushButton("Hatch")
btn_terminate = QPushButton("Terminate") btn_terminate = QPushButton("Terminate")
btn_close = QPushButton("Close") btn_close = QPushButton("Close")
btn_hatch.clicked.connect(Window.hatch) btn_hatch.clicked.connect(Window.hatch)
btn_terminate.clicked.connect(Window.terminate) 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) btn_close.clicked.connect(Window.close)
layout = QHBoxLayout() layout = QHBoxLayout()
layout.addWidget(btn_hatch) layout.addWidget(btn_hatch)
layout.addWidget(btn_terminate) layout.addWidget(btn_terminate)
layout.addWidget(Window.speed)
layout.addWidget(btn_close) layout.addWidget(btn_close)
Window.root.addLayout(layout) Window.root.addLayout(layout)
@ -108,3 +121,7 @@ class Window:
Window.delete_layout(item.layout()) Window.delete_layout(item.layout())
layout.deleteLater() layout.deleteLater()
@staticmethod
def expand(widget: QWidget) -> None:
widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)