from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine

from src.controller.controller import Controller
from src.projection.screen import Screen


class ControlWindow:
    def __init__(self):
        self.app = QGuiApplication([])
        self.running = True

        self.engine = QQmlApplicationEngine(self.app)
        self.controller = Controller(self)
        self.engine.quit.connect(self.app.quit)
        self.engine.rootContext().setContextProperty("controller_backend", self.controller)
        self.engine.load("resources/main_window.qml")


    def process_events(self):
        return self.app.processEvents()

    def is_running(self):
        return self.running

    def close(self):
        self.app.quit()
        self.app.exit(0)
        self.app.processEvents()