summaryrefslogtreecommitdiff
path: root/kodereviewer/app.py
blob: 204b73ee415cf5713a8a56073f8598157c433cbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3

import os
import sys
import signal

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 kodereviewer.models.file import FileModel
from kodereviewer.network_manager import NetworkManager
from kodereviewer.models import CommentModel, LabelModel, LineModel, PullRequestModel, ProjectModel
import logging
from rich.logging import RichHandler

FORMAT = "%(message)s"
logging.basicConfig(
    level="INFO", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)


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(LabelModel, "org.deprecated.kodereviewer", 1, 0, "LabelModel")
    qmlRegisterType(LineModel, "org.deprecated.kodereviewer", 1, 0, "LineModel")
    qmlRegisterType(PullRequestModel, "org.deprecated.kodereviewer", 1, 0, "PullRequestModel")
    qmlRegisterType(NetworkManager, "org.deprecated.kodereviewer", 1, 0, "NetworkManager")

    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()