本文介绍了在Python 3中从dbus迁移到GDbus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用GDbus在python中编写服务文件.但是,只有在我想使用C的情况下,我才能找到一个很好的教程.由于我想将GDbus包含在现有的Python代码中,所以我不知道该怎么做.

I have tried to write a service file in python using GDbus. But I could not find a good tutorial, only if i want to use C. Since I want to include GDbus in an existing Python code i have no idea how to do that.

我可以使用dbus编写服务文件,并且可以使用GDbus客户端访问该服务文件.

It was possible for me to write a service file using dbus and I could access that service file with a GDbus client.

如果有人在Python中有一个很好的例子,我将非常高兴.非常感谢,多米尼克

I would be very happy if somebody had a good example in Python.Thanks a lot,Dominik

推荐答案

虽然您可以使用Python中的GDBus,但它可能不是最好的(大多数Pythonic)API,因为它是经过机械内省和公开的C API到Python.

While you can use GDBus from Python, it might not be the nicest (most Pythonic) API to use, since it’s a C API which is mechanically introspected and exposed to Python.

使用 pydbus ,这可能是更好的选择,这是为D.Bus客户端库编写的Python.其文档中有大量使用Python的示例.

You might be better off using pydbus, which is a modern D-Bus client library written for Python. Its documentation has plenty of examples in Python.

如果必须使用GDBus,下面是一些Python示例:

If you must use GDBus, here are some Python examples:

  • https://wiki.gnome.org/HowDoI/GDBusPython
  • https://github.com/hexchat/hexchat/blob/master/src/common/dbus/example.py

这是Python的GDBus API参考(通过C API机械生成):

And here’s the GDBus API reference for Python (mechanically generated from the C API):

这篇关于在Python 3中从dbus迁移到GDbus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:35