From fc630644411ef0a267f716554aa5a460b543e7ae Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Thu, 25 Jul 2024 09:56:44 -0600 Subject: [PATCH] Mods --- cromulant/game.py | 8 ++++++++ cromulant/window.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cromulant/game.py b/cromulant/game.py index e09e8a1..c6fe667 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -561,3 +561,11 @@ class Game: ] Window.alert("\n\n".join(lines)) + + @staticmethod + def slowdown() -> None: + Game.change_speed("slow") + + @staticmethod + def change_speed(speed: str) -> None: + Window.speed.setCurrentText(speed.capitalize()) diff --git a/cromulant/window.py b/cromulant/window.py index 0f715e1..eb05d04 100644 --- a/cromulant/window.py +++ b/cromulant/window.py @@ -46,6 +46,19 @@ class SpecialButton(QPushButton): # type: ignore super().mousePressEvent(e) +class SpecialComboBox(QComboBox): # type: ignore + middleClicked = Signal() + + def __init__(self, *args: Any, **kwargs: Any) -> None: + super().__init__(*args, **kwargs) + + def mousePressEvent(self, e: QMouseEvent) -> None: + if e.button() == Qt.MiddleButton: + self.middleClicked.emit() + else: + super().mousePressEvent(e) + + class FilterLineEdit(QLineEdit): # type: ignore def keyPressEvent(self, e: QKeyEvent) -> None: if e.key() == Qt.Key_Escape: @@ -249,7 +262,7 @@ class Window: btn_menu.clicked.connect(Game.menu) btn_menu.middleClicked.connect(Game.force_update) - Window.speed = QComboBox() + Window.speed = SpecialComboBox() tooltip = "The speed of the updates\n" tooltip += f"Fast: {Utils.get_seconds(Config.loop_delay_fast)}\n" tooltip += f"Normal: {Utils.get_seconds(Config.loop_delay_normal)}\n" @@ -258,6 +271,7 @@ class Window: Window.speed.addItems(["Fast", "Normal", "Slow", "Paused"]) Window.speed.setCurrentIndex(1) Window.speed.currentIndexChanged.connect(Game.update_speed) + Window.speed.middleClicked.connect(Game.slowdown) Window.filter = FilterLineEdit() Window.filter.setPlaceholderText("Filter")