PySide With Qt 5.15 Application
This document in Russian / Перевод этого документа на русский язык
Contents
- Application description
- Build and use features
- Installation and build
- Screenshots
- Use cases
- Known errors
- Compatibility
- Project Structure
- Terms of Use and Participation
Application description
Aurora OS application to demonstrate the PySide2 with Qt 5.15 usage.
Build and use features
Working with PySide2 on the Aurora OS
To use PySide2 with Qt 5.15 on the Aurora OS, follow these steps:
- Install the Qt 5.15 in the build environment using the manual.
- Build the Python interpreter for the required target and, if necessary, install additional packages.
- Build for the required target the PySide2 module.
- Develop a PySide application.
- Set up the RPM package build process.
- Execute the PySide application using the wrapper application.
Wrapper Application
A wrapper application written in C++ is used to launch the PySide application. Within the wrapper application, the following steps need to be performed:
- Configure the arguments for launching the PySide application. The first argument is the path to the Python interpreter, the second is the path to the
.pyfile that serves as the entry point for the PySide application, followed by the arguments received from themainfunction. The sequence of arguments ends withNULL.
char *args[] = { <path_to_python_interpreter>, <path_to_pyside_application>, <args_from_main>, NULL };
- Retrieve the list of environment variables, for example, through the global variable
environ.
extern char **environ;
- Execute the PySide application using the
execvesystem call, passing the new arguments and the retrieved environment variables.
execve(<path_to_python_interpreter>, <args>, <environment_vars>);
Updating Translation Files in a PySide Application
To update translation files in a PySide application, you can use the pyside2-lupdate utility, which is bundled with PySide2.
Since pyside2-lupdate does not support working with QML files, translation updates need to be organized separately: standard tools should be used for QML files, while pyside2-lupdate should be used for PySide files.
Installation and build
Python interpreter and PySide2 module building
The project contains the build_python3.sh bash-script to build the python3 interpreter and PySide2 module for the Aurora OS.
The build_python3.sh script should be runned inside the Aurora OS Build Engine.
To build the python3 interpreter it needs to perform the next steps:
- Go to the
PySide With Qt 5.15 Applicationproject root directory. The directory contains thebuild_python3.shscript. - Go to Build Engine via
sfdk:
<path_to_Aurora_SDK_install_directory>/AuroraOS/bin/sfdk engine exec
- Run the
build_python3.shscript to build the interpreter:
./build_python3.sh -t <TARGET>
TARGET — Aurora OS build target. Use the following command inside the Build Engine to see the list of available targets:
sdk-mamage target list
For the correct script work, it needs to pass the name of the build target to it without the ".default" suffix. For example, "AuroraOS-5.1.1.60-base-aarch64".
After building the python3 interpreter the project root folder should contain the python3/ folder with a subfolder of the built interpreter for the choosen target. Result forlders tree after building the interpreter for all targets:
python-application-launcher/
├─ python3/
│ ├─ aarch64/
│ ├─ armv7l/
│ ├─ x86_64/
RPM package building
After successful building of the python interpreter, the application can be built in the usual way using the Aurora SDK.
For the build, it is important that the Python interpreter and PySide application files are correctly located in the rpm package. The built Python interpreter with PySide2 module must be located in the directory /usr/libexec/<aurora_application_name>/. To achieve this:
- During the cmake execution stage, copy the interpreter to the RPM package build directory, specifying the required path. To do this, add the following to the
CMakeListsfile:
install(DIRECTORY <path_to_built_interpreter>/
DESTINATION /usr/libexec/${PROJECT_NAME}/python3)
- During copying, discard the examples that are collected together with PySide 2, because they use forbidden modules in the Aurora OS.
install(DIRECTORY <path_to_built_interpreter> /
...
REGEX "python3/${CMAKE_SYSTEM_PROCESSOR}/lib/python3\\.[0-9]+/site-packages/PySide2/examples" EXCLUDE
REGEX "python3/${CMAKE_SYSTEM_PROCESSOR}/lib/python3\\.[0-9]+/site-packages/PySide2/.*\\.qml" EXCLUDE
...
)
- Add the interpreter files to the
%filessection of the spec file and grant execution permissions to the files in thebindirectory:
%{_libexecdir}/%{name}/python3/lib
%{_libexecdir}/%{name}/python3/share
%{_libexecdir}/%{name}/python3/scripts
%defattr(755,root,root,-)
%{_libexecdir}/%{name}/python3/bin/
Only Python executable files should remain in the bin directory of the built interpreter. All other files must be moved to different directories. In this example, file relocation is performed during the build script build_python3.sh execution at the cleanup stage.
PySide application files can be placed alongside Aurora application files in /usr/share/<aurora_application_name>/. To do this, simply add the following to CMakeLists:
install(DIRECTORY <path_to_pyside_application>
DESTINATION share/${PROJECT_NAME}
)
Python Interpreter and PySide2 module Build Script
To simplify and automate the process of building Python and PySide2 module for different targets, the build_python3.sh script was created.
The script starts by processing the provided options (lines 82-101). The entire script is structured into functions, and during the option processing phase, these functions are invoked.
The script performs the following actions:
- Sets the required dependencies in the target environment.
- Clones the source code of the Python 3 interpreter from GitHub.
- Clones the source code of the PySide2 module from GitHub.
- Builds the Python 3 interpreter.
- Builds the PySide2 modules.
- Installs the Python package
Requestsusingpip. - Cleans up the build directories.
You can specify a different target version of the Python interpreter by modifying the $python_version variable in the script.
You can specify a different set of Python packages to be installed by updating the $python_packages variable in the script. To install multiple packages, list them separated by spaces.
You can specify a different target version of the PySide2 module by modifying the $pyside_version variable in the script.
You can specify a different set of PySide2 modules to be installed by updating the $pyside_modules variable in the script.
Screenshots
Use cases
Make HTTP request
- You can click the button on the main page to make a HTTP request. You can also see the current status of the request.
Known errors
No known errors have been found in the project.
Compatibility
The project is compatible with with version 5 of the Aurora OS.
Project Structure
The project has a standard structure of an application based on C++, Python and QML for Aurora OS.
- CMakeLists.txt file describes the project structure for the CMake build system.
- icons directory contains application icons for different screen resolutions.
-
qml directory contains the QML source code and the UI resources.
- cover directory contains the application cover implementations.
- icons directory contains the custom UI icons.
- pages directory contains the application pages.
- PySideWithQt5.15Application.qml file provides the application window implementation.
-
rpm directory contains the rpm-package build settings.
- ru.auroraos.PySideWithQt5.15Application.spec file is used by rpmbuild tool.
- scripts directory contains the PySide application source code.
-
src directory contains the C++ source code.
- main.cpp file is the application entry point.
- translations directory contains the UI translation files.
- ru.auroraos.PySideWithQt5.15Application.desktop file defines the display and parameters for launching the application.
Terms of Use and Participation
The source code of the project is provided under the license, which allows its use in third-party applications.
The contributor agreement documents the rights granted by contributors of the Open Mobile Platform.
Information about the contributors is specified in the AUTHORS file.
Code of conduct is a current set of rules of the Open Mobile Platform which informs you how we expect the members of the community will interact while contributing and communicating.
