cromulant/window.py

65 lines
1.7 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 06:51:11 +00:00
2024-07-18 07:20:36 +00:00
from config import Config
2024-07-18 06:51:11 +00:00
from ants import Ants
class Window:
app: QApplication
window: QMainWindow
root: QWidget
2024-07-18 07:20:36 +00:00
view: QGraphicsView
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 06:51:11 +00:00
Window.root = QWidget()
Window.window.setCentralWidget(Window.root)
@staticmethod
def add_buttons() -> None:
btn_hatch = QPushButton("Hatch Ant")
btn_terminate = QPushButton("Terminate")
btn_hatch.clicked.connect(Window.hatch)
btn_terminate.clicked.connect(Window.terminate)
layout = QHBoxLayout()
layout.addWidget(btn_hatch)
layout.addWidget(btn_terminate)
Window.root.setLayout(layout)
@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 06:51:11 +00:00
layout = QVBoxLayout(Window.root)
layout.addWidget(Window.view)
@staticmethod
def hatch() -> None:
Ants.hatch()
@staticmethod
def terminate() -> None:
Ants.terminate()
@staticmethod
def start() -> None:
Window.window.show()
Window.app.exec()