Mods
This commit is contained in:
parent
6486cea6d8
commit
2ce7464786
|
@ -8,7 +8,6 @@ from typing import ClassVar, Any
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .utils import Utils
|
from .utils import Utils
|
||||||
from .storage import Storage
|
from .storage import Storage
|
||||||
from .window import Window
|
|
||||||
|
|
||||||
|
|
||||||
class Ant:
|
class Ant:
|
||||||
|
@ -89,33 +88,6 @@ class Ants:
|
||||||
Ants.save()
|
Ants.save()
|
||||||
Game.update_info()
|
Game.update_info()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def terminate() -> None:
|
|
||||||
from .game import Game
|
|
||||||
|
|
||||||
ant = Ants.random_ant()
|
|
||||||
|
|
||||||
if not ant:
|
|
||||||
return
|
|
||||||
|
|
||||||
Ants.ants.remove(ant)
|
|
||||||
Ants.save()
|
|
||||||
|
|
||||||
Ants.announce_terminate(ant)
|
|
||||||
Game.update_info()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def terminate_all() -> None:
|
|
||||||
from .game import Game
|
|
||||||
|
|
||||||
def action() -> None:
|
|
||||||
Ants.ants = []
|
|
||||||
Ants.save()
|
|
||||||
Window.clear_view()
|
|
||||||
Game.update_info()
|
|
||||||
|
|
||||||
Window.confirm("Terminate all ants?", action)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def random_ant(ignore: list[Ant] | None = None) -> Ant | None:
|
def random_ant(ignore: list[Ant] | None = None) -> Ant | None:
|
||||||
if ignore:
|
if ignore:
|
||||||
|
|
|
@ -57,14 +57,15 @@ class ComboBoxDialog(QDialog): # type: ignore
|
||||||
|
|
||||||
self.button_layout = QHBoxLayout()
|
self.button_layout = QHBoxLayout()
|
||||||
|
|
||||||
self.ok_button = QPushButton("OK")
|
|
||||||
self.ok_button.clicked.connect(self.accept)
|
|
||||||
self.button_layout.addWidget(self.ok_button)
|
|
||||||
|
|
||||||
self.cancel_button = QPushButton("Cancel")
|
self.cancel_button = QPushButton("Cancel")
|
||||||
self.cancel_button.clicked.connect(self.reject)
|
self.cancel_button.clicked.connect(self.reject)
|
||||||
self.button_layout.addWidget(self.cancel_button)
|
self.button_layout.addWidget(self.cancel_button)
|
||||||
|
|
||||||
|
self.ok_button = QPushButton("OK")
|
||||||
|
self.ok_button.clicked.connect(self.accept)
|
||||||
|
self.ok_button.setDefault(True)
|
||||||
|
self.button_layout.addWidget(self.ok_button)
|
||||||
|
|
||||||
self.layout.addLayout(self.button_layout)
|
self.layout.addLayout(self.button_layout)
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
@ -282,21 +283,6 @@ class Window:
|
||||||
def expand(widget: QWidget) -> None:
|
def expand(widget: QWidget) -> None:
|
||||||
widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
|
widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def confirm(message: str, action: Callable[..., Any]) -> None:
|
|
||||||
msg_box = QMessageBox()
|
|
||||||
msg_box.setIcon(QMessageBox.Icon.Question)
|
|
||||||
msg_box.setWindowTitle("Confirm")
|
|
||||||
msg_box.setText(message)
|
|
||||||
|
|
||||||
msg_box.setStandardButtons(
|
|
||||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
|
||||||
)
|
|
||||||
|
|
||||||
msg_box.setDefaultButton(QMessageBox.StandardButton.No)
|
|
||||||
msg_box.button(QMessageBox.StandardButton.Yes).clicked.connect(action)
|
|
||||||
msg_box.exec()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_view() -> None:
|
def clear_view() -> None:
|
||||||
while Window.view.count():
|
while Window.view.count():
|
||||||
|
@ -361,6 +347,7 @@ class Window:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def alert(message: str) -> None:
|
def alert(message: str) -> None:
|
||||||
msg_box = QMessageBox()
|
msg_box = QMessageBox()
|
||||||
|
msg_box.setWindowFlags(Qt.Popup)
|
||||||
msg_box.setIcon(QMessageBox.Information)
|
msg_box.setIcon(QMessageBox.Information)
|
||||||
msg_box.setText(message)
|
msg_box.setText(message)
|
||||||
msg_box.setWindowTitle("Information")
|
msg_box.setWindowTitle("Information")
|
||||||
|
@ -370,6 +357,7 @@ class Window:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prompt_combobox(message: str, options: list[str], defindex: int = 0) -> str:
|
def prompt_combobox(message: str, options: list[str], defindex: int = 0) -> str:
|
||||||
dialog = ComboBoxDialog(message, options, defindex)
|
dialog = ComboBoxDialog(message, options, defindex)
|
||||||
|
dialog.setWindowFlags(Qt.Popup)
|
||||||
|
|
||||||
if dialog.exec() == QDialog.Accepted:
|
if dialog.exec() == QDialog.Accepted:
|
||||||
return dialog.get_selection()
|
return dialog.get_selection()
|
||||||
|
|
Loading…
Reference in New Issue