#!/usr/bin/env python3 import os import sys import signal import logging from KI18n import KLocalizedContext, KLocalizedString from PySide6.QtGui import QGuiApplication from PySide6.QtCore import QUrl, QByteArray from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType from PySide6.QtQuickControls2 import QQuickStyle from rich.logging import RichHandler from kodereviewer.data import PullRequest from kodereviewer.models.file import FileModel from kodereviewer.network_manager import NetworkManager from kodereviewer.models import ( CommentModel, TreeFileModel, LabelModel, LineModel, PullRequestModel, ProjectModel, ReviewerModel, ReviewModel ) from kodereviewer.review import ReviewHelper FORMAT = "%(message)s" logging.basicConfig( level="INFO", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()] ) logger = logging.getLogger(__name__) def main(): """Initializes and manages the application execution""" app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() # KLocalizedString::setApplicationDomain("tutorial"); KLocalizedString.setApplicationDomain(QByteArray(b"kodereviewer")) app.setOrganizationName("Deprecated") app.setOrganizationDomain("deprecated.org") app.setApplicationName("Kode Reviewer") app.setDesktopFileName("kodereviewer") """Needed to close the app with Ctrl+C""" signal.signal(signal.SIGINT, signal.SIG_DFL) """Needed to get proper KDE style outside of Plasma""" if not os.environ.get("QT_QUICK_CONTROLS_STYLE"): QQuickStyle.setStyle("org.kde.desktop") qmlRegisterType(ProjectModel, "org.deprecated.kodereviewer", 1, 0, "ProjectModel") qmlRegisterType(CommentModel, "org.deprecated.kodereviewer", 1, 0, "CommentModel") qmlRegisterType(FileModel, "org.deprecated.kodereviewer", 1, 0, "FileModel") qmlRegisterType(TreeFileModel, "org.deprecated.kodereviewer", 1, 0, "TreeFileModel") qmlRegisterType(LabelModel, "org.deprecated.kodereviewer", 1, 0, "LabelModel") qmlRegisterType(LineModel, "org.deprecated.kodereviewer", 1, 0, "LineModel") qmlRegisterType(PullRequestModel, "org.deprecated.kodereviewer", 1, 0, "PullRequestModel") qmlRegisterType(ReviewerModel, "org.deprecated.kodereviewer", 1, 0, "ReviewerModel") qmlRegisterType(ReviewModel, "org.deprecated.kodereviewer", 1, 0, "ReviewModel") qmlRegisterType(NetworkManager, "org.deprecated.kodereviewer", 1, 0, "NetworkManager") qmlRegisterType(PullRequest, "org.deprecated.kodereviewer", 1, 0, "PullRequest") qmlRegisterType(ReviewHelper, "org.deprecated.kodereviewer", 1, 0, "ReviewHelper") localized_context = KLocalizedContext() engine.rootContext().setContextObject(localized_context) base_path = os.path.abspath(os.path.dirname(__file__)) engine.addImportPath(f"file://{base_path}/qml") engine.addImportPath(f"file://{base_path}/qml/delegates") url = QUrl(f"file://{base_path}/qml/Main.qml") engine.load(url) if len(engine.rootObjects()) == 0: quit() app.exec() if __name__ == "__main__": main()