|
7 | 7 |
|
8 | 8 | from PySide6.QtGui import QGuiApplication
|
9 | 9 | from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterSingletonType
|
10 |
| -from PySide6.QtCore import qInstallMessageHandler |
11 | 10 |
|
12 | 11 | # It is usually assumed that the EasyApp package is already installed in the desired python environment.
|
13 | 12 | # If this is not the case, and if the example is run from the EasyApp repository, one need to add the path to the
|
|
16 | 15 | EASYAPP_DIR = CURRENT_DIR / '..' / '..' / '..' / '..' / 'src' # path to qml components of the easyapp module
|
17 | 16 | sys.path.append(str(EASYAPP_DIR))
|
18 | 17 |
|
19 |
| -from EasyApp.Logic.Logging import console |
20 |
| - |
21 | 18 | from Backends.real_backend import Backend
|
22 | 19 |
|
23 | 20 |
|
24 | 21 | if __name__ == '__main__':
|
25 |
| - qInstallMessageHandler(console.qmlMessageHandler) |
26 |
| - console.debug('Custom Qt message handler defined') |
| 22 | + # Register the Backend class as a singleton type for QML |
| 23 | + # This singleton object will be accessible in QML as follows: |
| 24 | + # import Backends 1.0 as Backends OR import Backends as Backends |
| 25 | + # property var activeBackend: Backends.PyBackend |
| 26 | + qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') |
27 | 27 |
|
| 28 | + # Create Qt application |
28 | 29 | app = QGuiApplication(sys.argv)
|
29 |
| - console.debug(f'Qt Application created {app}') |
30 | 30 |
|
| 31 | + # Create the QML application engine |
31 | 32 | engine = QQmlApplicationEngine()
|
32 |
| - console.debug(f'QML application engine created {engine}') |
33 |
| - |
34 |
| - qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') |
35 |
| - console.debug('Backend class is registered to be accessible from QML via the name PyBackend') |
36 | 33 |
|
37 |
| - engine.addImportPath(EASYAPP_DIR) |
| 34 | + # Add the paths where QML searches for components |
38 | 35 | engine.addImportPath(CURRENT_DIR)
|
39 |
| - console.debug('Paths added where QML searches for components') |
| 36 | + engine.addImportPath(EASYAPP_DIR) |
40 | 37 |
|
| 38 | + # Load the main QML component |
41 | 39 | engine.load(CURRENT_DIR / 'main.qml')
|
42 |
| - console.debug('Main QML component loaded') |
43 | 40 |
|
44 |
| - console.debug('Application event loop is about to start') |
| 41 | + # Start the application event loop |
45 | 42 | if not engine.rootObjects():
|
46 | 43 | sys.exit(-1)
|
47 | 44 | sys.exit(app.exec())
|
0 commit comments