This commit is contained in:
Auric Vente 2024-07-21 06:00:22 -06:00
parent 3d8ff1f167
commit b96a3f3057
4 changed files with 20 additions and 1 deletions

View File

@ -52,6 +52,7 @@ class Config:
settings_json: Path
countries_json: Path
filter_width: int = 150
filter_debouncer_delay: int = 200
@staticmethod
def prepare() -> None:

View File

@ -2,17 +2,33 @@ from __future__ import annotations
from PySide6.QtWidgets import QWidget # type: ignore
from PySide6.QtGui import QKeyEvent # type: ignore
from PySide6.QtCore import QTimer
from .config import Config
from .window import Window
class Filter:
debouncer: QTimer
@staticmethod
def prepare() -> None:
Filter.debouncer = QTimer()
Filter.debouncer.setSingleShot(True)
Filter.debouncer.setInterval(Config.filter_debouncer_delay)
Filter.debouncer.timeout.connect(Filter.do_filter)
@staticmethod
def get_value() -> str:
return str(Window.filter.text()).lower().strip()
@staticmethod
def filter(event: QKeyEvent | None = None) -> None:
Filter.debouncer.stop()
Filter.debouncer.start()
@staticmethod
def do_filter() -> None:
value = Filter.get_value()
for i in range(Window.view.count()):

View File

@ -273,7 +273,7 @@ class Game:
@staticmethod
def restart() -> None:
opts = ["25", "50", "100", "200", "300", "400", "500"]
opts = ["25", "50", "100", "200", "300"]
opts = [f"{opt} ants" for opt in opts]
size = Window.prompt_combobox("Size of the population", opts, 2)

View File

@ -6,6 +6,7 @@ from .ants import Ants
from .window import Window
from .game import Game
from .settings import Settings
from .filter import Filter
def main() -> None:
@ -14,6 +15,7 @@ def main() -> None:
Window.prepare()
Ants.prepare()
Settings.prepare()
Filter.prepare()
Game.prepare()
Game.start_loop()
Window.start()