P

PySide with Qt 5.15

Темы: Qt Python
Use PySide2 with Qt 5.15 on the Aurora OS.

PySide With Qt 5.15 Application

This document in Russian / Перевод этого документа на русский язык

Contents

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:

  1. Install the Qt 5.15 in the build environment using the manual.
  2. Build the Python interpreter for the required target and, if necessary, install additional packages.
  3. Build for the required target the PySide2 module.
  4. Develop a PySide application.
  5. Set up the RPM package build process.
  6. 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:

  1. 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 .py file that serves as the entry point for the PySide application, followed by the arguments received from the main function. The sequence of arguments ends with NULL.
char *args[] = { <path_to_python_interpreter>, <path_to_pyside_application>, <args_from_main>, NULL };
  1. Retrieve the list of environment variables, for example, through the global variable environ.
extern char **environ;
  1. Execute the PySide application using the execve system 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:

  1. Go to the PySide With Qt 5.15 Application project root directory. The directory contains the build_python3.sh script.
  2. Go to Build Engine via sfdk:
<path_to_Aurora_SDK_install_directory>/AuroraOS/bin/sfdk engine exec
  1. Run the build_python3.sh script 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:

  1. 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 CMakeLists file:
install(DIRECTORY <path_to_built_interpreter>/
    DESTINATION /usr/libexec/${PROJECT_NAME}/python3)
  1. 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
  ...
)
  1. Add the interpreter files to the %files section of the spec file and grant execution permissions to the files in the bin directory:
%{_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:

  1. Sets the required dependencies in the target environment.
  2. Clones the source code of the Python 3 interpreter from GitHub.
  3. Clones the source code of the PySide2 module from GitHub.
  4. Builds the Python 3 interpreter.
  5. Builds the PySide2 modules.
  6. Installs the Python package Requests using pip.
  7. 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

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.

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.