Skip to content

Commit

Permalink
Rename examples (more simple structure)
Browse files Browse the repository at this point in the history
* BasicMinimalPy to BasicPy
* BasicMinimalC++ to BasicC++
* BasicPy to IntermediatePy
* IntermediatePy to AdvancedPy
  • Loading branch information
AndrewSazonov committed Aug 30, 2024
1 parent b869b5d commit 0cab3cf
Show file tree
Hide file tree
Showing 110 changed files with 155 additions and 155 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ jobs:
export PATH=$PATH:${{ github.workspace }}/Qt/6.7.2/wasm_singlethread/bin
qmake -v
- name: Build WASM from BasicMinimalC++ example
- name: Build WASM from BasicC++ example
shell: bash
run: |
source ${{ github.workspace }}/emsdk/emsdk_env.sh
export PATH=$PATH:${{ github.workspace }}/Qt/6.7.2/wasm_singlethread/bin
cd examples/BasicMinimalC++/src
qmake BasicMinimalC++.pro -spec wasm-emscripten
cd examples/BasicC++/src
qmake BasicC++.pro -spec wasm-emscripten
make -j
- name: Copy the built WASM to the build/wasm folder
shell: bash
run: |
mkdir -p build/wasm
cp examples/BasicMinimalC++/src/*.wasm build/wasm
cp examples/BasicMinimalC++/src/*.html build/wasm
cp examples/BasicMinimalC++/src/*.js build/wasm
cp examples/BasicMinimalC++/src/*.svg build/wasm
cp examples/BasicC++/src/*.wasm build/wasm
cp examples/BasicC++/src/*.html build/wasm
cp examples/BasicC++/src/*.js build/wasm
cp examples/BasicC++/src/*.svg build/wasm
- name: Upload the zipped wasm folder
uses: actions/upload-artifact@v4
Expand Down
18 changes: 9 additions & 9 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Different types of examples are provided. All examples have a frontend implement
| Example | Type | Frontend | Backend | Runtime |
| -------------- | ---- | -------- | -------- | -------------------- |
| BasicQml | I | QML | Mock QML | `qml` tool |
| BasicMinimalPy | II | QML | Mock QML | `python` interpreter |
| BasicPy | III | QML | Python | `python` interpreter |
| BasicPy | II | QML | Mock QML | `python` interpreter |
| IntermediatePy | III | QML | Python | `python` interpreter |
| AdvancedPy | III | QML | Python | `python` interpreter |
| BasicC++ | IV | QML | Mock QML | need to be compiled |


Expand Down Expand Up @@ -40,7 +40,7 @@ Different types of examples are provided. All examples have a frontend implement
* Install the Qt for Python `PySide6` package via PIP

```
pip install PySide6
pip install --force-reinstall "PySide6>=6.6,<6.7"
```

### Integrated development environment (IDE)
Expand Down Expand Up @@ -104,9 +104,9 @@ This example is located in `examples/BasicQml` and the source code is in the sub
* _Note: Showing the entire `main.qml` application window in live mode works best when the open `main.qml` is moved to another monitor and does not overlap with the `Qt Creator` window_.
* When the desired GUI component appears, you can click the `Edit` button at the top of the left sidebar of `Qt Creator` to return to the source code of that qml component and still see it live in a separate window.

### Type II Examples: BasicMinimalPy (Python runtime with QML backend)
### Type II Examples: BasicPy (Python runtime with QML backend)

This example is located in `examples/BasicMinimalPy` with the source code in `src/BasicMinimalPy`. This example serves to demonstrate how an application with a QML frontend and a QML backend (similar to the Type I example) can be executed from Python. The entry point for the Python program is `main.py` file. To execute this do the following:
This example is located in `examples/BasicPy` with the source code in `src/BasicPy`. This example serves to demonstrate how an application with a QML frontend and a QML backend (similar to the Type I example) can be executed from Python. The entry point for the Python program is `main.py` file. To execute this do the following:

#### Run using the Python interpreter

Expand All @@ -115,7 +115,7 @@ This example is located in `examples/BasicMinimalPy` with the source code in `sr
* Go to the example folder, e.g.,

```sh
$ cd examples/BasicMinimalPy/src/BasicMinimalPy
$ cd examples/BasicPy/src/BasicPy
```
* Run using Python (provided that the required python environment is activated as explained above)

Expand All @@ -126,7 +126,7 @@ This example is located in `examples/BasicMinimalPy` with the source code in `sr
#### Run via the Qt Creator IDE (_alternative to run from the terminal_)

* Run Qt Creator
* Open the python project file from the example folder `examples/BasicMinimalPy/src/BasicMinimalPy.pyproject`
* Open the python project file from the example folder `examples/BasicPy/src/BasicPy.pyproject`
* Select the desired python environment with the Qt `PySide6` module installed
* Click Run (Green play button)

Expand All @@ -136,9 +136,9 @@ This example is located in `examples/BasicMinimalPy` with the source code in `sr
* Click on the debug extension and select which example to execute
![Debug dropdown window](resources/images/vscode_debug.jpg)

### Type III Examples: BasicPy and IntermediatePy (Python runtime with Python backend)
### Type III Examples: IntermediatePy and AdvancedPy (Python runtime with Python backend)

These examples demonstrate how to use a Python runtime to execute the QML frontend and the Python backend located in `Logic/Py/backend_proxy.py`. These examples can be run through Python in the same way as Type II described above. These examples have a Python-based backend (proxy object), which gets created in `main.py` and then exposed to QML. The Qt QML frontend then acceses the backend by calling methods exposed by the proxy object in the `Py` folder.
These examples demonstrate how to use a Python runtime to execute the QML frontend and the Python backend located in `Backends/real_backend.py`. These examples can be run through Python in the same way as Type II described above. These examples have a Python-based backend (proxy object), which gets created in `main.py` and then exposed to QML. The Qt QML GUI then acceses the backend by calling methods exposed by the proxy object in the `Backends/real_py` folder.

#### Possible Issues

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ EasyApp is currently being used as the basis for the graphical interface in the

More simple examples of using EasyApp are described in [EXAMPLES.md](EXAMPLES.md).

If you want to see what EasyApp looks like, you can try the web demo at https://easyscience.github.io/EasyApp/BasicMinimalC++.html.
If you want to see what EasyApp looks like, you can try the web demo at https://easyscience.github.io/EasyApp/BasicC++.html.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## Structure of the _IntermediatePy_ example
## Structure of the _AdvancedPy_ example

### Without the full structure of the application pages

```sh
🗂️ IntermediatePy # Current example
🗂️ AdvancedPy # Current example
├── LICENSE
├── pyproject.toml # Configuration file used to build the Python package
├── README.md # Current file that introduces and explains a project
└── 🗂️ src # Source code
├── IntermediatePy.qmlproject # QML project for the Qt Creator IDE
├── IntermediatePy.pyproject # Python project for the Qt Creator IDE
├── AdvancedPy.qmlproject # QML project for the Qt Creator IDE
├── AdvancedPy.pyproject # Python project for the Qt Creator IDE
└── 🗂️ IntermediatePy # Directory with the name of the current Python package
└── 🗂️ AdvancedPy # Directory with the name of the current Python package
├── __init__.py # Executed when the current Python package is imported
├── main.qml # Root QML component
├── main.py # Root Python file
Expand Down Expand Up @@ -50,7 +50,7 @@
│ └── 🗂️ Report # Components of the application page 'Report'
└── 🗂️ Resources
└── 🗂️ Logos # Logos of the application and contributors
└── 🗂️ Logos # Logos of the application and contributors

(*) Full structure of the 'Pages' directory is shown below
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ requires = ['hatchling']
build-backend = 'hatchling.build'

[project]
name = 'intermediatepy'
name = 'advancedpy'
version = '1.0.0'
description = 'Example of a desktop application of intermediate complexity with a Python backend and EasyApp-based GUI'
description = 'Example of a desktop application of advanced complexity with Python backend and EasyApp-based GUI'
authors = [
{name = 'Andrew Sazonov', email = 'andrew.sazonov@ess.eu'}
]
Expand All @@ -29,8 +29,8 @@ ci = [
]

[project.urls]
homepage = 'https://github.com/EasyScience/EasyApp/tree/master/examples/IntermediatePy'
homepage = 'https://github.com/EasyScience/EasyApp/tree/master/examples/AdvancedPy'

[tool.hatch.build.targets.wheel]
packages = ['src/IntermediatePy']
packages = ['src/AdvancedPy']
#artifacts = ['*.py', '*.qml', 'qmldir']
2 changes: 2 additions & 0 deletions examples/AdvancedPy/scripts/install_from_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "\033[0;34m:::::: Installing python wheel from 'dist/wheel'\033[0m"
python3 -m pip install advancedpy --force-reinstall --find-links=dist/wheel
File renamed without changes.
44 changes: 44 additions & 0 deletions examples/AdvancedPy/src/AdvancedPy.pyproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"files": [
"AdvancedPy.qmlproject",
"AdvancedPy/main.py",
"AdvancedPy/main.qml",
"AdvancedPy/Gui/qmldir",
"AdvancedPy/Gui/ApplicationWindow.qml",
"AdvancedPy/Gui/StatusBar.qml",
"AdvancedPy/Gui/Globals/qmldir",
"AdvancedPy/Gui/Globals/ApplicationInfo.qml",
"AdvancedPy/Gui/Globals/BackendWrapper.qml",
"AdvancedPy/Gui/Globals/References.qml",
"AdvancedPy/Gui/Pages/Home/Content.qml",
"AdvancedPy/Gui/Pages/Home/Popups/About.qml",
"AdvancedPy/Gui/Pages/Project/Layout.qml",
"AdvancedPy/Gui/Pages/Project/MainArea/Description.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Layout.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Groups/Examples.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Groups/GetStarted.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Groups/Recent.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Popups/OpenCifFile.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Basic/Popups/ProjectDescription.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Extra/Layout.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Extra/Groups/Scrolling.qml",
"AdvancedPy/Gui/Pages/Project/Sidebar/Text/Layout.qml",
"AdvancedPy/Gui/Pages/Report/Layout.qml",
"AdvancedPy/Gui/Pages/Report/MainArea/Summary.qml",
"AdvancedPy/Gui/Pages/Report/Sidebar/Basic/Layout.qml",
"AdvancedPy/Gui/Pages/Report/Sidebar/Basic/Groups/Export.qml",
"AdvancedPy/Gui/Pages/Report/Sidebar/Extra/Layout.qml",
"AdvancedPy/Gui/Pages/Report/Sidebar/Extra/Groups/Empty.qml",
"AdvancedPy/Backends/qmldir",
"AdvancedPy/Backends/MockBackend.qml",
"AdvancedPy/Backends/MockQml/Project.qml",
"AdvancedPy/Backends/MockQml/Report.qml",
"AdvancedPy/Backends/MockQml/Status.qml",
"AdvancedPy/Backends/MockQml/qmldir",
"AdvancedPy/Backends/real_backend.py",
"AdvancedPy/Backends/real_py/helpers.py",
"AdvancedPy/Backends/real_py/project.py",
"AdvancedPy/Backends/real_py/report.py",
"AdvancedPy/Backends/real_py/status.py"
]
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import QmlProject 1.1

Project {
mainFile: "BasicMinimalPy/main.qml"
mainFile: "AdvancedPy/main.qml"

// List of module and plugin directories passed to QML runtime
importPaths: [
"BasicMinimalPy",
"AdvancedPy",
"../../../src", // EasyApp
]

// Include .qml files from specified directory and its subdirectories
QmlFiles {
directory: "BasicMinimalPy"
directory: "AdvancedPy"
}
QmlFiles {
directory: "../../../src/EasyApp"
}

// Include .js files from specified directory and its subdirectories
JavaScriptFiles {
directory: "BasicMinimalPy"
directory: "AdvancedPy"
}
JavaScriptFiles {
directory: "../../../src/EasyApp"
Expand All @@ -28,7 +28,7 @@ Project {
// Include Module Definition Files (qmldir), as well as .ts and .qrc
// from specified directory and its subdirectories
Files {
directory: "BasicMinimalPy"
directory: "AdvancedPy"
filter: "qmldir;*.ts;*.qrc;*.html"
recursive: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import QtQuick
QtObject {

readonly property var about: {
'name': 'BasicMinimalPy',
'namePrefix': 'BasicMinimal',
'name': 'AdvancedPy',
'namePrefix': 'Advanced',
'nameSuffix': 'Py',
'namePrefixForLogo': 'basicminimal',
'namePrefixForLogo': 'advanced',
'nameSuffixForLogo': 'py',
'homePageUrl': 'https://github.com/EasyScience/EasyExample',
'issuesUrl': 'https://github.com/EasyScience/EasyExample/issues',
Expand All @@ -23,7 +23,7 @@ QtObject {
'date': new Date().toISOString().slice(0,10),
'developerYearsFrom': '2019',
'developerYearsTo': '2024',
'description': 'An example of how to build the basic application using EasyApp module.',
'description': 'Example of a desktop application of advanced complexity with Python backend and EasyApp-based GUI',
'developerIcons': [
{
'url': 'https://ess.eu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import sys

from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
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
Expand All @@ -15,18 +16,32 @@
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__':
# Create application
qInstallMessageHandler(console.qmlMessageHandler)
console.debug('Custom Qt message handler defined')

app = QGuiApplication(sys.argv)
console.debug(f'Qt Application created {app}')

# Create 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)
engine.addImportPath(CURRENT_DIR)
console.debug('Paths added where QML searches for components')

engine.load(CURRENT_DIR / 'main.qml')
console.debug('Main QML component loaded')

# Event loop
console.debug('Application event loop is about to start')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import Gui as Gui

Gui.ApplicationWindow {

id: applicationWindow // Global access
id: applicationWindow // applicationWindow is globally accessible

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

filename = 'src/BasicMinimalC++/resources.qrc'
filename = 'src/BasicC++/resources.qrc'
with open(filename, 'r') as f:
content = f.read()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TEMPLATE = app

# Application name
TARGET = BasicMinimalC++
TARGET = BasicC++

CONFIG += c++17

Expand All @@ -11,16 +11,16 @@ DEFINES += QT_DEPRECATED_WARNINGS
QT += core quick qml

SOURCES += \
BasicMinimalC++/main.cpp
BasicC++/main.cpp

RESOURCES += BasicMinimalC++/resources.qrc
RESOURCES += BasicC++/resources.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH += \
BasicMinimalC++ \
BasicC++ \
../../../src/EasyApp

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH += \
BasicMinimalC++ \
BasicC++ \
../../../src/EasyApp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import QmlProject 1.1

Project {
mainFile: "BasicMinimalC++/main.qml"
mainFile: "BasicC++/main.qml"

// List of module and plugin directories passed to QML runtime
importPaths: [
"BasicMinimalC++",
"BasicC++",
"../../../src", // EasyApp
]

// Include .qml files from specified directory and its subdirectories
QmlFiles {
directory: "BasicMinimalC++"
directory: "BasicC++"
}
QmlFiles {
directory: "../../../src/EasyApp"
}

// Include .js files from specified directory and its subdirectories
JavaScriptFiles {
directory: "BasicMinimalC++"
directory: "BasicC++"
}
JavaScriptFiles {
directory: "../../../src/EasyApp"
Expand All @@ -28,7 +28,7 @@ Project {
// Include Module Definition Files (qmldir), as well as .ts and .qrc
// from specified directory and its subdirectories
Files {
directory: "BasicMinimalC++"
directory: "BasicC++"
filter: "qmldir;*.ts;*.qrc;*.html"
recursive: true
}
Expand Down
Loading

0 comments on commit 0cab3cf

Please sign in to comment.