from PyQt6.QtCore import QObject, pyqtSlot

from time import time


class Controller(QObject):
    def __init__(self, window, parent=None):
        super().__init__(parent)
        self.window = window
        self.last_close_press = 0
        self.successful_clicks = 0

    @pyqtSlot()
    def close_application(self):
        now = time()
        if now - self.last_close_press < 0.2:
            self.successful_clicks += 1
        else:
            self.successful_clicks = 0

        if self.successful_clicks > 1:
            self.window.running = False

        self.last_close_press = now

    @pyqtSlot(int)
    def select_scene(self, scene: int):
        self.window.selected_scene = scene