-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·51 lines (40 loc) · 1.53 KB
/
main.py
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
import os
import sys
from PyQt5 import QtCore, QtQml, QtWidgets
from regatta import QRegatta, QEvent, QSailingClub, QPerson
# Fixme: I have no idea why I can't put it in a method
# def main():
osname = os.name.lower()
sysplatform = sys.platform.lower()
windows = os.name.lower() == "nt" and sysplatform.startswith("win")
# PyQt class name, QML URI, major version, minor version, QML type name
QtQml.qmlRegisterType(QRegatta, 'QRegatta', 1, 0, 'QRegatta')
QtQml.qmlRegisterType(QEvent, 'QEvent', 1, 0, 'QEvent')
QtQml.qmlRegisterType(QSailingClub, 'QSailingClub', 1, 0, 'QSailingClub')
QtQml.qmlRegisterType(QPerson, 'QPerson', 1, 0, 'QPerson')
app = QtWidgets.QApplication(sys.argv)
# Create the QML engine
engine = QtQml.QQmlEngine(app)
engine.quit.connect(app.quit)
# Load the main.qml file and create the toplevel component
component = QtQml.QQmlComponent(engine)
currentFilePath = os.path.dirname(os.path.abspath(__file__))
mainFilepath = os.path.join(currentFilePath, "regatta/main.qml")
if windows:
mainFilepath = mainFilepath.replace('\\', '/')
qmlFile = QtCore.QUrl("file:///" + mainFilepath)
component.loadUrl(qmlFile)
if component.status() != QtQml.QQmlComponent.Ready:
for error in component.errors():
print(error.toString())
sys.exit(-1)
topLevelItem = component.create()
if not topLevelItem:
for error in component.errors():
print(error.toString())
sys.exit(-1)
# Now run the main loop until the user closes the application
topLevelItem.show()
sys.exit(app.exec_())
# if __name__ == "__main__":
# main()