-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.py
43 lines (33 loc) · 1.09 KB
/
main2.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
import sys
import urllib.request
import json
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import QStringListModel
from PySide6.QtGui import QGuiApplication
if __name__ == '__main__':
# get our data
url = "http://country.io/names.json"
response = urllib.request.urlopen(url)
data = json.loads(response.read().decode('utf-8'))
# Format and sort the data
# data_list = list(data.values())
# data_list.sort()
# Set up the application window
app = QGuiApplication(sys.argv)
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)
# Expose the list to the Qml code
# my_model = QStringListModel()
# my_model.setStringList(data_list)
view.setInitialProperties({"countryModel": data})
# Load the QML file
# Add the current directory to the import paths and load the main module.
view.engine().addImportPath(sys.path[0])
view.loadFromModule("ui", "main2")
# Show the window
if view.status() == QQuickView.Error:
sys.exit(-1)
view.show()
# execute and cleanup
app.exec()
del view