cromulant/cromulant/window.py

85 lines
2.3 KiB
Python
Raw Normal View History

2024-07-18 06:51:11 +00:00
from __future__ import annotations
2024-07-18 07:20:36 +00:00
from PySide6.QtWidgets import QApplication # type: ignore
from PySide6.QtWidgets import QMainWindow
from PySide6.QtWidgets import QWidget
from PySide6.QtWidgets import QGraphicsView
from PySide6.QtWidgets import QGraphicsScene
from PySide6.QtWidgets import QVBoxLayout
from PySide6.QtWidgets import QPushButton
from PySide6.QtWidgets import QHBoxLayout
2024-07-18 08:14:03 +00:00
from PySide6.QtWidgets import QTextEdit
2024-07-18 06:51:11 +00:00
2024-07-18 08:14:03 +00:00
from .config import Config
2024-07-18 06:51:11 +00:00
class Window:
app: QApplication
window: QMainWindow
2024-07-18 08:14:03 +00:00
root: QHBoxLayout
2024-07-18 07:20:36 +00:00
view: QGraphicsView
2024-07-18 08:14:03 +00:00
log: QTextEdit
2024-07-18 06:51:11 +00:00
@staticmethod
def make() -> None:
Window.app = QApplication([])
Window.window = QMainWindow()
2024-07-18 07:20:36 +00:00
Window.window.setWindowTitle(Config.title)
Window.window.resize(Config.width, Config.height)
2024-07-18 08:14:03 +00:00
Window.root = QHBoxLayout()
central_widget = QWidget()
Window.root = QVBoxLayout()
central_widget.setLayout(Window.root)
Window.window.setCentralWidget(central_widget)
2024-07-18 06:51:11 +00:00
@staticmethod
def add_buttons() -> None:
2024-07-18 08:14:03 +00:00
btn_hatch = QPushButton("Hatch")
2024-07-18 06:51:11 +00:00
btn_terminate = QPushButton("Terminate")
2024-07-18 08:14:03 +00:00
btn_update = QPushButton("Update")
2024-07-18 06:51:11 +00:00
btn_hatch.clicked.connect(Window.hatch)
btn_terminate.clicked.connect(Window.terminate)
2024-07-18 08:14:03 +00:00
btn_update.clicked.connect(Window.update_view)
2024-07-18 06:51:11 +00:00
layout = QHBoxLayout()
layout.addWidget(btn_hatch)
layout.addWidget(btn_terminate)
2024-07-18 08:14:03 +00:00
layout.addWidget(btn_update)
2024-07-18 06:51:11 +00:00
2024-07-18 08:14:03 +00:00
Window.root.addLayout(layout)
2024-07-18 06:51:11 +00:00
@staticmethod
def add_view() -> None:
Window.view = QGraphicsView()
2024-07-18 07:20:36 +00:00
scene = QGraphicsScene()
Window.view.setScene(scene)
2024-07-18 08:14:03 +00:00
Window.root.addWidget(Window.view)
@staticmethod
def add_log() -> None:
Window.log = QTextEdit()
Window.log.setReadOnly(True)
Window.log.setFixedHeight(100)
Window.root.addWidget(Window.log)
@staticmethod
def update_view() -> None:
from .game import Game
Game.update_view()
2024-07-18 06:51:11 +00:00
@staticmethod
def hatch() -> None:
2024-07-18 08:14:03 +00:00
from .ants import Ants
2024-07-18 06:51:11 +00:00
Ants.hatch()
@staticmethod
def terminate() -> None:
2024-07-18 08:14:03 +00:00
from .ants import Ants
2024-07-18 06:51:11 +00:00
Ants.terminate()
@staticmethod
def start() -> None:
Window.window.show()
Window.app.exec()