diff --git a/examples/AdvancedPy/src/AdvancedPy/Gui/Globals/BackendWrapper.qml b/examples/AdvancedPy/src/AdvancedPy/Gui/Globals/BackendWrapper.qml index de8b2ec..c0d3666 100644 --- a/examples/AdvancedPy/src/AdvancedPy/Gui/Globals/BackendWrapper.qml +++ b/examples/AdvancedPy/src/AdvancedPy/Gui/Globals/BackendWrapper.qml @@ -21,10 +21,10 @@ QtObject { readonly property var activeBackend: { if (typeof Backends.PyBackend !== 'undefined') { - console.debug('Currently, the REAL python backend is in use') + console.debug('REAL python backend is in use') return Backends.PyBackend } else { - console.debug('Currently, the MOCK backend is in use') + console.debug('MOCK QML backend is in use') return Backends.MockBackend } } diff --git a/examples/AdvancedPy/src/AdvancedPy/main.py b/examples/AdvancedPy/src/AdvancedPy/main.py index d1b82b3..e6b7822 100644 --- a/examples/AdvancedPy/src/AdvancedPy/main.py +++ b/examples/AdvancedPy/src/AdvancedPy/main.py @@ -25,17 +25,20 @@ qInstallMessageHandler(console.qmlMessageHandler) console.debug('Custom Qt message handler defined') + # This singleton object will be accessible in QML as follows: + # import Backends 1.0 as Backends OR import Backends as Backends + # property var activeBackend: Backends.PyBackend + qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') + console.debug('Backend class is registered as a singleton type for QML') + app = QGuiApplication(sys.argv) console.debug(f'Qt Application created {app}') engine = QQmlApplicationEngine() console.debug(f'QML application engine created {engine}') - qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') - console.debug('Backend class is registered to be accessible from QML via the name PyBackend') - - engine.addImportPath(EASYAPP_DIR) engine.addImportPath(CURRENT_DIR) + engine.addImportPath(EASYAPP_DIR) console.debug('Paths added where QML searches for components') engine.load(CURRENT_DIR / 'main.qml') diff --git a/examples/BasicC++/src/BasicC++/Gui/Globals/BackendWrapper.qml b/examples/BasicC++/src/BasicC++/Gui/Globals/BackendWrapper.qml index de8b2ec..c0d3666 100644 --- a/examples/BasicC++/src/BasicC++/Gui/Globals/BackendWrapper.qml +++ b/examples/BasicC++/src/BasicC++/Gui/Globals/BackendWrapper.qml @@ -21,10 +21,10 @@ QtObject { readonly property var activeBackend: { if (typeof Backends.PyBackend !== 'undefined') { - console.debug('Currently, the REAL python backend is in use') + console.debug('REAL python backend is in use') return Backends.PyBackend } else { - console.debug('Currently, the MOCK backend is in use') + console.debug('MOCK QML backend is in use') return Backends.MockBackend } } diff --git a/examples/BasicC++/src/BasicC++/main.cpp b/examples/BasicC++/src/BasicC++/main.cpp index d6dd7d4..798f06e 100644 --- a/examples/BasicC++/src/BasicC++/main.cpp +++ b/examples/BasicC++/src/BasicC++/main.cpp @@ -6,21 +6,23 @@ #include #include -const QString CURRENT_DIR = "qrc:/"; // path to qml components of the easyapp module -const QString EASYAPP_DIR = "qrc:/../../../../src/EasyApp"; // path to qml components of the current project int main(int argc, char *argv[]) { - // Create application + // Create Qt application QGuiApplication app(argc, argv); - // Create QML application engine + // Create the QML application engine QQmlApplicationEngine engine; - engine.addImportPath(CURRENT_DIR); - engine.addImportPath(EASYAPP_DIR); + + // Add the paths where QML searches for components + // Use whatever is defined in the resources.qrc file + engine.addImportPath("qrc:/"); + + // Load the main QML component engine.load("qrc:/main.qml"); - // Event loop + // Start the application event loop if (engine.rootObjects().isEmpty()) return -1; return app.exec(); diff --git a/examples/BasicPy/src/BasicPy/Gui/Globals/BackendWrapper.qml b/examples/BasicPy/src/BasicPy/Gui/Globals/BackendWrapper.qml index de8b2ec..c0d3666 100644 --- a/examples/BasicPy/src/BasicPy/Gui/Globals/BackendWrapper.qml +++ b/examples/BasicPy/src/BasicPy/Gui/Globals/BackendWrapper.qml @@ -21,10 +21,10 @@ QtObject { readonly property var activeBackend: { if (typeof Backends.PyBackend !== 'undefined') { - console.debug('Currently, the REAL python backend is in use') + console.debug('REAL python backend is in use') return Backends.PyBackend } else { - console.debug('Currently, the MOCK backend is in use') + console.debug('MOCK QML backend is in use') return Backends.MockBackend } } diff --git a/examples/BasicPy/src/BasicPy/main.py b/examples/BasicPy/src/BasicPy/main.py index 63bcd55..dac3d02 100644 --- a/examples/BasicPy/src/BasicPy/main.py +++ b/examples/BasicPy/src/BasicPy/main.py @@ -17,16 +17,20 @@ if __name__ == '__main__': - # Create application + # Create Qt application app = QGuiApplication(sys.argv) - # Create QML application engine + # Create the QML application engine engine = QQmlApplicationEngine() - engine.addImportPath(EASYAPP_DIR) + + # Add the paths where QML searches for components engine.addImportPath(CURRENT_DIR) + engine.addImportPath(EASYAPP_DIR) + + # Load the main QML component engine.load(CURRENT_DIR / 'main.qml') - # Event loop + # Start the application event loop if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec()) diff --git a/examples/BasicQml/src/BasicQml/Gui/Globals/BackendWrapper.qml b/examples/BasicQml/src/BasicQml/Gui/Globals/BackendWrapper.qml index de8b2ec..c0d3666 100644 --- a/examples/BasicQml/src/BasicQml/Gui/Globals/BackendWrapper.qml +++ b/examples/BasicQml/src/BasicQml/Gui/Globals/BackendWrapper.qml @@ -21,10 +21,10 @@ QtObject { readonly property var activeBackend: { if (typeof Backends.PyBackend !== 'undefined') { - console.debug('Currently, the REAL python backend is in use') + console.debug('REAL python backend is in use') return Backends.PyBackend } else { - console.debug('Currently, the MOCK backend is in use') + console.debug('MOCK QML backend is in use') return Backends.MockBackend } } diff --git a/examples/IntermediatePy/src/IntermediatePy/Backends/real_py/project.py b/examples/IntermediatePy/src/IntermediatePy/Backends/real_py/project.py index c8f4045..7461cf9 100644 --- a/examples/IntermediatePy/src/IntermediatePy/Backends/real_py/project.py +++ b/examples/IntermediatePy/src/IntermediatePy/Backends/real_py/project.py @@ -94,7 +94,7 @@ def name(self): def name(self, new_value): if self._name == new_value: return - console.debug(IO.format_msg('main', f"Changing project name from '{self.name}' to '{new_value}'")) + print(f" py: Changing project name from '{self.name}' to '{new_value}'") self._name = new_value self.nameChanged.emit() @@ -113,19 +113,19 @@ def examples(self): @Slot() def create(self): - console.debug(IO.format_msg('main', f"Creating project '{self.name}'")) + print(f" py: Creating project '{self.name}'") self.info['creationDate'] = time.strftime("%d %b %Y %H:%M", time.localtime()) self.infoChanged.emit() self.created = True @Slot() def save(self): - console.debug(IO.format_msg('main', f"Saving project '{self.name}'")) + print(f" py: Saving project '{self.name}'") @Slot(str, str) def editInfo(self, path, new_value): if DottyDict.get(self._info, path) == new_value: return - console.debug(IO.format_msg('main', f"Changing project info.{path} from '{DottyDict.get(self._info, path)}' to '{new_value}'")) + print(f" py: Changing project info.{path} from '{DottyDict.get(self._info, path)}' to '{new_value}'") DottyDict.set(self._info, path, new_value) self.infoChanged.emit() diff --git a/examples/IntermediatePy/src/IntermediatePy/Gui/Globals/BackendWrapper.qml b/examples/IntermediatePy/src/IntermediatePy/Gui/Globals/BackendWrapper.qml index de8b2ec..c0d3666 100644 --- a/examples/IntermediatePy/src/IntermediatePy/Gui/Globals/BackendWrapper.qml +++ b/examples/IntermediatePy/src/IntermediatePy/Gui/Globals/BackendWrapper.qml @@ -21,10 +21,10 @@ QtObject { readonly property var activeBackend: { if (typeof Backends.PyBackend !== 'undefined') { - console.debug('Currently, the REAL python backend is in use') + console.debug('REAL python backend is in use') return Backends.PyBackend } else { - console.debug('Currently, the MOCK backend is in use') + console.debug('MOCK QML backend is in use') return Backends.MockBackend } } diff --git a/examples/IntermediatePy/src/IntermediatePy/main.py b/examples/IntermediatePy/src/IntermediatePy/main.py index d1b82b3..e83b0ca 100644 --- a/examples/IntermediatePy/src/IntermediatePy/main.py +++ b/examples/IntermediatePy/src/IntermediatePy/main.py @@ -7,7 +7,6 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterSingletonType -from PySide6.QtCore import qInstallMessageHandler # It is usually assumed that the EasyApp package is already installed in the desired python environment. # 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,32 +15,30 @@ EASYAPP_DIR = CURRENT_DIR / '..' / '..' / '..' / '..' / 'src' # path to qml components of the easyapp module sys.path.append(str(EASYAPP_DIR)) -from EasyApp.Logic.Logging import console - from Backends.real_backend import Backend if __name__ == '__main__': - qInstallMessageHandler(console.qmlMessageHandler) - console.debug('Custom Qt message handler defined') + # Register the Backend class as a singleton type for QML + # This singleton object will be accessible in QML as follows: + # import Backends 1.0 as Backends OR import Backends as Backends + # property var activeBackend: Backends.PyBackend + qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') + # Create Qt application app = QGuiApplication(sys.argv) - console.debug(f'Qt Application created {app}') + # Create the QML application engine engine = QQmlApplicationEngine() - console.debug(f'QML application engine created {engine}') - - qmlRegisterSingletonType(Backend, 'Backends', 1, 0, 'PyBackend') - console.debug('Backend class is registered to be accessible from QML via the name PyBackend') - engine.addImportPath(EASYAPP_DIR) + # Add the paths where QML searches for components engine.addImportPath(CURRENT_DIR) - console.debug('Paths added where QML searches for components') + engine.addImportPath(EASYAPP_DIR) + # Load the main QML component engine.load(CURRENT_DIR / 'main.qml') - console.debug('Main QML component loaded') - console.debug('Application event loop is about to start') + # Start the application event loop if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())