Qt for Python:新的6.5版本发布了!

Qt for Python: the new 6.5 version is out!

Qt for Python:新的6.5版本发布了!

April 04, 2023 by Cristián Maureira-Fredes | Comments


2023年4月4日:Cristián Maureira Fredes |评论

You may have seen the many cool things that Qt 6.5 includes, so now we want to talk about everything being developed by the Qt for Python team. 

您可能已经看到了Qt 6.5包含的许多很酷的东西,所以现在我们想谈谈Qt for Python团队正在开发的一切。

New modules and classes 

新模块和类

This time we saw an opportunity to expose a few other modules due to feedback from our users and the new capabilities of Qt 6.5. For that, we have now included QtTextToSpeech, QtSerialBus, and QtLocation. 

这一次,由于用户的反馈和Qt 6.5的新功能,我们看到了一个展示其他一些模块的机会。为此,我们现在包括了QtTextToSpeech、QtSrialBus和QtLocation。

Also, we are in the process of adapting and improving the classes from the existing modules, and so far, we have managed to include QtCore.QHashSeed, QWebEngineFileSystemAccessRequest, QOpenGLContext.getProcAddress,  QSGeometry.vertexDataAsPoint2DQSGGeometry.setVertexDataAsPoint2DQAbstractTextDocumentLayout::PaintContextQRunnable.create and QMetaMethod.fromSignal

​此外,我们正在调整和改进现有模块中的类,到目前为止,我们已经成功地包括了QtCore.QHashSeed、QWebEngineFileSystemAccessRequest、QOpenGLContext.getProcAddress、QSGeometry.vertexDataAsPoint2D、QSGGeometry.setVertexDataAsPoint2D、QAbstractTextDocumentLayout::PaintContext、QRunnable.create和QMetaMethod.fromSignal

Additionally, many shared pointer types of Qt 3D are included as well: PropertyReaderInterface, QTextureImageData, and QTextureImageDataGenerator. 

此外,还包括许多Qt 3D的共享指针类型:PropertyReaderInterface、QTextureImageData和QTextureImageDataGenerator。

The few missing modules from Qt for Python have usually been left aside for lack of use cases or because there are Python counterparts that might be chosen over Qt modules. 

Qt for Python中为数不多的缺失模块通常被搁置一边,原因是缺乏用例,或者因为可能会选择与Qt模块相对应的Python模块。

 Fine tuning: __features__ and multiple-inheritance 

微调:__features__和多重继承

Meanwhile, quite well known __feature__ switching was again totally revised. On the one hand, the switching was strongly optimized so that the Dictionary of a class must be changed only approximately every fifth time. Furthermore, the criteria for switching have been tightened so that complex cases with many context changes in expressions can be handled safely. 

​与此同时,众所周知的__feature__切换再次被完全修改。一方面,切换经过了严格优化,因此类的Dictionary必须大约每五次更改一次。此外,转换的标准已经收紧,因此可以安全地处理表达式中有许多上下文变化的复杂情况

At the same time, during this revision, a poorly understood corner was refactored, and a number of hard-to-locate errors were finally eliminated. 

与此同时,在这次修订中,对一个不太了解的角落进行了重构,并最终消除了一些难以定位的错误。

Cooperative multiple inheritance has also been a misunderstood thing for a long time. Actually, multiple inheritance in PySide has nothing to do with Python, but users expect the super() function to behave the same way when used in a PySide class as in a normal Python class. We have extended the __init__ function accordingly, as other implementations have done. But that's not the final word. In fact, you need to implement multiple inheritance quite differently so that super() behaves like normal Python everywhere, in all methods and even in metaclasses. To do this, you have to improve the super() function itself so that it behaves properly on PySide classes on its own.  

长期以来,合作多重继承也是一件被误解的事情。实际上,PySide中的多重继承与Python无关,但用户希望super()函数在PySide类中使用时的行为与在普通Python类中使用相同。我们已经相应地扩展了__init__函数,就像其他实现一样。但这还不是最终决定。事实上,需要以完全不同的方式实现多重继承,以便super()在任何地方、所有方法甚至元类中的行为都像普通Python一样。要做到这一点,必须改进super()函数本身,使其能够在PySide类上正常运行。

⭐ But we'll tell more about that in the next release. Stay tuned! 

⭐ 但我们将在下一个版本中详细介绍这一点。敬请期待!

Improving our binding generation tool: Shiboken 

改进我们的绑定生成工具:Shiboken

For each minor release, we have the option to clean a bit of the current implementation of our binding generator tool and add new features.  

对于每个小版本,我们都可以选择清理一些绑定生成器工具的当前实现,并添加新功能。

For the generated wrapper code, we used to rely on goto statements that are now safely removed and replaced for a better implementation. 

对于生成的包装器代码,我们过去依赖于goto语句,这些语句现在被安全地删除和替换,以获得更好的实现。

There is now a new option called --lean-header to generate forward declarations instead of includes into the module header, from which we can get improvements regarding the dependencies of each wrapper. Still, it might require extra additional includes for the injected code. 

现在有一个名为--lean-header的新选项来生成前向声明,而不是包含在模块头中,从中我们可以改进每个包装器的依赖性。尽管如此,它可能需要对注入的代码进行额外的包含。

To continue improving our support for shared pointers, it is now possible to specify names and namespaces for smart pointer instantiations, for example: 

为了继续改进我们对共享指针的支持,现在可以为智能指针实例化指定名称和命名空间,例如:

<smart-pointer-type name="SharedPtr" type="shared"

    getter="data" ref-count-method="useCount"

    null-check-method="isNull"

         instantiations="Integer,Smart::Integer2,Obj"/> 

Where you can see that the “Smart::Integer2” is being renamed as “SmartInteger2Ptr”. 

可以看到“Smart::Integer2”正被重命名为“SmartInteger2Ptr”。

typesystem XML element for opaque containers has been added, removing the need to repeat the container element: 

​添加了用于不透明容器的类型系统XML元素,无需重复容器元素:

<opaque-container name="QList"

    opaque-containers="QVector2D:QVector2DList

        QVector3D:QVector3DList;QVector4D:QVector4DList"/> 

Starting from 6.5.0, Shiboken has support for std::array (C++ 11). There is now experimental support for std::span (C++20). 

从6.5.0开始,Shiboken支持std::array(C++11)。现在有了对std::span(C++20)的实验支持。

Finally, we have improved the documentation by refreshing the diagrams and highlighting some of our examples. 

​最后,我们通过刷新图表和突出显示一些示例来改进文档

Modern looking Qt Quick applications UIs for your Python code

外观现代的Qt Quick应用程序UI,用于Python代码

As you might know, Qt for Python works well with Qt Widgets and also with Qt Quick. However many people has been asking us to get a nice modern-looking Qt Quick application example, which also include a tutorial that explains the details. Due to the nature of Qt Quick, you can have a backend in C++ or Python, also most of the graphical aspects are written mostly in QML.

正如您可能知道的,Qt for Python与Qt Widgets以及Qt Quick配合使用都很好。然而,许多人一直要求我们获得一个看起来很现代的Qt Quick应用程序示例,其中还包括一个解释细节的教程。由于Qt Quick的性质,可以在C++或Python中有一个后端,而且大多数图形方面大多是用QML编写的。

We are pleased to introduce the Filesystem Explorer, a new Qt Quick example that demonstrates the flexibility and adaptability of Qt Quick Controls. This example provides a user-friendly interface for browsing and visualizing the file system, allowing users to open local text files effortlessly. 

​我们很高兴介绍Filesystem Explorer,这是一个新的Qt Quick示例,展示了Qt Quick Controls的灵活性和适应性。此示例提供了一个用户友好的界面,用于浏览和可视化文件系统,允许用户轻松打开本地文本文件

This project showcases how to jazz up a Qt Quick application by personalizing and arranging its essential components to achieve a visually stunning and modern appearance. We will explore ways to refine the user interface elements and organize different parts of the application to improve usability and user experience. The primary objective is to exhibit the art of application customization and layout. Specifically, we will delve into the distribution of color schemes and frameless windows, which can enable you to design a distinct and visually appealing interface for your application. Our aim is to enable developers to create a highly personalized and specific appearance for their application, avoiding reliance on system settings and achieving a fully customized look. 

该项目展示了如何通过个性化和排列Qt Quick应用程序的基本组件来实现视觉上的惊艳和现代外观。我们将探索改进用户界面元素和组织应用程序不同部分的方法,以提高可用性和用户体验。主要目的是展示应用程序定制和布局的艺术。具体来说,我们将深入研究配色方案和无框窗口的分布,这可以使您为应用程序设计一个独特且具有视觉吸引力的界面。我们的目标是使开发人员能够为他们的应用程序创建高度个性化和特定的外观,避免对系统设置的依赖,并实现完全定制的外观。

Additionally, we have expanded upon the initial example and created the Extended Explorer tutorial. This tutorial improves the functionality by showcasing how to implement a scheme manager, enabling the ability to switch color schemes dynamically during runtime. This feature demonstrates how to modify the application's appearance on-the-fly by using QML bindings and parsing schemes in JSON format. As a result, developers are given greater flexibility and customization options when designing their applications. 

​此外,我们对最初的示例进行了扩展,并创建了Extended Explorer教程。本教程通过展示如何实现方案管理器来改进功能,从而能够在运行时动态切换配色方案。此功能演示了如何通过使用QML绑定和JSON格式的解析方案来动态修改应用程序的外观。因此,开发人员在设计应用程序时可以获得更大的灵活性和自定义选项

In case you are interested in the C++ counterpart, you can check that example here.

​如果你对C++的对应部分感兴趣,你可以在这里查看这个例子。

qtpip: a better way to install commercial wheels (in progress) 

qtpip:安装商用车轮的更好方法(正在进行中)

Many of our commercial customers have been struggling with getting the commercial packages of Qt for Python, mainly because it involves a couple of extra steps, which are a bit more complicated than the simple ‘pip install pyside6’. That is why we have been working on a simple pip wrapper to enable the installation of commercial wheels 🛞.

我们的许多商业客户一直在努力获得Qt for Python的商业包,主要是因为它涉及到几个额外的步骤,这些步骤比简单的“pip-install-pyside6”要复杂一些。这就是为什么我们一直在开发一种简单的pip包装器,以实现商用车轮的安装🛞.

Even though it is not included in this release, the tool will have its own development cycle and be available during 6.5. People will be able to get this tool independently and use it to interact with their Qt accounts

​尽管此版本中没有包含该工具,但该工具将有自己的开发周期,并在6.5期间可用。人们将能够独立获得此工具,并使用它与他们的Qt帐户进行交互

⭐ Once the tool is fully ready, we will follow up with a dedicated blog post. 

⭐ 一旦该工具完全准备就绪,我们将发布一篇专门的博客文章。

Asynchronous support 

异步支持

Qt for Python is not just Qt, and not just Python: It’s the best of both worlds! 💪 But the world of Python is more than just a language: Python users expect wide interoperability between their favorite libraries and modules of the huge Python ecosystem. 

Qt for Python不仅仅是Qt,也不仅仅是Python:这是两全其美! 💪但Python的世界不仅仅是一种语言:Python用户希望他们喜欢的库和庞大的Python生态系统的模块之间有广泛的互操作性。

Today, Python developers who want to write an application with asynchronous I/O have a choice between the asyncio and trio libraries, among others. As you surely know, like these two, Qt is also based on an event loop. This positions Qt for Python as a good choice for asynchronous program logic in combination with one of the established libraries of the Python ecosystem, enabling developers to leverage their respective strengths.  

​如今,想要编写具有异步I/O的应用程序的Python开发人员可以在asyncio和trio库之间进行选择。正如你所知道的,就像这两个一样,Qt也是基于事件循环的。这将Qt for Python定位为异步程序逻辑的良好选择,并与Python生态系统的一个已建立的库相结合,使开发人员能够利用各自的优势

We are currently exploring how to make Qt and asynchronous frameworks play well together. During the past months, we have added two examples showcasing how to combine Qt for Python with Trio via its guest run mechanism, plus two exploratory examples for an analogous implementation with asyncio.  

我们目前正在探索如何使Qt和异步框架能够很好地协同工作。在过去的几个月里,我们添加了两个示例,展示了如何通过其客户运行机制将Qt for Python与Trio相结合,以及两个探索性示例,用于异步的类似实现。

During the 6.5 release cycle, you can expect additional progress, including Qt for Python’s own implementation of asyncio’s abstract event loop, so that you can use the asyncio library with Qt’s event loop underpinning it.

在6.5发布周期中,可以期待更多的进展,包括Qt for Python自己对asyncio抽象事件循环的实现,这样您就可以使用带有Qt事件循环的asyncio库作为其基础。

Be sure to “await PySide6.more_async_support()” in the coming months. 😉 

请确保在接下来的几个月里“等待PySide6.more_async_support()”😉

Initial support for Android deployment 

对Android部署的初步支持

The much-requested and long-awaited feature of taking your PySide6 application to Android is ALMOST here. With 6.5, we release a technical preview (TP) of a new tool, 'pyside6-android-deploy' that provides a simple, easy-to-use solution to package your PySide6 application from a Linux-based desktop OS to different Android platforms. It can be run as simply as:  

将您的PySide6应用程序带到Android上,这是一个备受期待的功能。在6.5版本中,我们发布了一个新工具“pyside6 android deploy”的技术预览版(TP),该工具提供了一个简单易用的解决方案,可以将您的pyside6应用程序从基于Linux的桌面操作系统打包到不同的安卓平台。它可以简单地运行:

pyside6-android-deploy

    --wheel-pyside=<path_to_pyside6_android_wheel>

    --wheel-shiboken=<path_to_shiboken6_android_wheel>

  --name=<app_name> 

The tool internally uses a custom fork for the python-for-android project with a new bootstrap for Qt. Eventually, we hope to create a pull request and get this fork merged into the python-for-android project. 

​该工具在内部为python for android项目使用了一个自定义fork,并为Qt提供了一个新的引导程序。最终,我们希望创建一个pull请求,并将这个fork合并到python for android项目中

You may have noticed that the tool requires the path to PySide6 and Shiboken6 Android wheels. So, where do you get them? Do we provide official Android wheels now? 

您可能已经注意到,该工具需要PySide6和Shiboken6 Android轮子的路径。那么,你从哪里得到它们?我们现在提供正式的Android轮子吗?

For the time being, we don't provide official Android wheels yet, so you will have to build the Android wheels yourself. But don't worry; check out another tool to cross-compile Qt for Python wheels to a specific Android platform. However, you can't find this tool with your PySide6 version 6.5 installation. We kept the tool separate in hopes that we could have official Android wheels in the future. The tool builds CPython for the specified Android platform and uses the built CPython to cross-compile PySide6 Android wheels. 

​目前,我们还没有提供官方的Android轮子,所以你必须自己构建Android轮子。但别担心;查看另一个工具,将用于Python轮子的Qt交叉编译到特定的Android平台。但是,您在安装PySide6 6.5版本时找不到此工具。我们把这个工具分开,希望将来能有官方的Android轮子。该工具为指定的Android平台构建CPython,并使用构建的CPython交叉编译PySide6 Android轮子

python tools/cross_compile_android/main.py

    --plat-name=<android_platform>

   --ndk-path=<path_to_android_ndk>

   --qt-install-path=<path_to_local_Qt_installation>

   --sdk-path=<path_to_android_sdk> 

Ideally, the entire deployment process is a 3-step process. 

理想情况下,整个部署过程是一个三步过程。

1.Download Android NDK and SDK

1.下载Android NDK和SDK

2.Run the cross-compile tool to generate Qt for Python Android wheels

2.运行交叉编译工具为Qt for Python生成Android轮子

3.Run the 'pyside6-android-deploy' tool

3.运行“pyside6 android部署”工具

At the end of step 3, you will have an apk/aab to publish or install onto your Android device. 

在第3步结束时,您将有一个apk/aab来发布或安装到您的Android设备上。

If the few sentences above poked your interest, we are sure you will have many open questions and would love more detailed instructions on taking your PySide6 application to Android. 

如果上面的几句话引起了你的兴趣,我们相信你会有很多悬而未决的问题,并且会喜欢更多关于将PySide6应用程序带到Android的详细说明。

⭐ Stay tuned for a more detailed blog post on Android compatibility in the coming weeks. 

⭐ 请继续关注未来几周关于Android兼容性的更详细博客文章。

https://play.hubspotvideo.com/453c3a1c-4c6e-4fc8-86a8-1863ff159403

(if you have issues playing the video, you can find it here)

​(如果您在播放视频时遇到问题,可以在此处找到)

Preparing for the future of Python

为Python的未来做准备

Python 3.11 came with many improvements for the Python ecosystem, and we managed to keep up with our internal implementation to remain compatible. As you might know, 3.12 will continue in the same direction, focusing mainly on performance. 

Python 3.11对Python生态系统进行了许多改进,我们设法跟上了内部实现的步伐,以保持兼容性。正如您所知,3.12将继续朝着同样的方向发展,主要关注性能。

Being compatible requires us to revisit our internal CPython implementations, so we started testing 3.12 as soon as we could. Even though it is still not fully compatible, we managed to unblock the build process with a couple of changes. 

​要实现兼容,我们需要重新审视我们的内部CPython实现,因此我们尽快开始测试3.12。尽管它仍然不完全兼容,但我们通过一些更改成功地解除了构建过程的阻塞

Orthogonal to this topic, we have been following the latest developments in the Python community regarding the evolution of the language, particularly the latest attempts to remove the GIL from the interpreter. We also aim to provide full compatibility with the NoGIL project

​与此主题正交,我们一直在关注Python社区中关于语言进化的最新发展,特别是从解释器中删除GIL的最新尝试。我们还致力于提供与NoGIL项目的完全兼容性

The NoGIL branch is still in an unsuitable condition for inclusion into Python. We have therefore researched it only far enough until the feasibility was clear. The outlook for the future looks positive so far 🥳. PySide itself must now ensure that unprotected objects are not used more than once. But the resulting efficiency by parallel execution is very promising 🎉, and we hope that this path will be taken officially soon. 

NoGIL分支仍然处于不适合包含到Python中的状态。因此,在可行性明确之前,我们只对其进行了足够的研究。到目前为止,对未来的展望是乐观的🥳. PySide本身现在必须确保未受保护的对象不会被多次使用。但并行执行的效率非常有希望🎉, 我们希望这条道路将很快正式走上。

What’s next? 

接下来是什么?

We want to keep trying new experimental support, features, and python module integration. What should we do next? Drop us a message or open a suggestion on JIRA 👍. 

​我们希望继续尝试新的实验性支持、功能和python模块集成。我们下一步该怎么办?给我们留言或在JIRA上打开建议👍. 

We hope you enjoy the release, and as always drop by our community platforms and let us know if something is not properly working by opening bug reports in JIRA .

​我们希望您喜欢这个版本,并一如既往地访问我们的社区平台,通过在JIRA中打开错误报告来告诉我们是否有问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值