summaryrefslogtreecommitdiffstats
path: root/src/mageiawelcome.py
blob: 49330fe596596df42325d29708b617194746583f (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
70
71
72
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from PyQt6.QtGui import QIcon, QScreen
from PyQt6.QtCore import (
    QUrl,
    QLocale,
    QTranslator,
    QLibraryInfo,
    QVariant,
    Qt,
    QObject,
    QCoreApplication,
)
from PyQt6.QtWidgets import QApplication
import sys
import os
from helpers import get_desktop_name, get_desktop_name2, is_installed, NetworkState, ConfList, Autostart
from ui import SlideShowApp

# Workaround for opengl lib selection
from OpenGL import GL

translate = QCoreApplication.translate


if __name__ == "__main__":
    # old method of autostart
    old_path = os.getenv("HOME") + "/.config/mageiawelcome/norun.flag"
    if os.path.exists(old_path):
        # disable  autostart according to new method and remove old method
        Autostart().disable()
        os.remove(old_path)
        
    app = QApplication(sys.argv)
    locale = QLocale.system().name()
    qtTranslator = QTranslator()
    if qtTranslator.load(
        "qt_" + locale, QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath) 
    ):
        app.installTranslator(qtTranslator)
    appTranslator = QTranslator()
    if appTranslator.load(
        QLocale(), "mageiawelcome", "_", "/usr/share/mageiawelcome/translations"
    ):
        app.installTranslator(appTranslator)
    app.setOrganizationName("Mageia")
    app.setApplicationName("Mageiawelcome")
    direction = Qt.LayoutDirection.LeftToRight if  translate("mw-ui", "LTR") == "LTR" else Qt.LayoutDirection.RightToLeft
    app.setLayoutDirection(direction)
    app.setWindowIcon(QIcon("/usr/share/icons/hicolor/32x32/apps/mageiawelcome.png"))
    ns = NetworkState()
    cl = ConfList(ns)
    # sc = nr.startupcheck()
    factor = cl.factor(app)
    screen = app.primaryScreen()
    # if density is high, use at least factor 2 to scale the initial window. Considering high is more than 190 px/inches.
    # if screen.logicalDotsPerInch() > 190:
    #     factor = max(2.0, factor)
    # defaultHeight = min(int(700 * factor), screen.availableGeometry().height())
    # defaultWidth = min(int(1000 * factor), screen.availableGeometry().width())
    # centerPoint = screen.availableGeometry().center()
    # view.setGeometry(
    #     centerPoint.x() - defaultWidth // 2,
    #     centerPoint.y() - defaultHeight // 2,
    #     defaultWidth,
    #     defaultHeight,
    # )
    view = SlideShowApp()
    view.show()
    res = app.exec()
    del view
    sys.exit(res)