回答
绝对可以在Python中实现D-Bus属性! D-Bus属性只是特定接口上的方法,即org.freedesktop.DBus.Properties
。界面定义为in the D-Bus specification;你可以实现它在你的类,就像你实现任何其他d-bus接口:
# Untested, just off the top of my head
import dbus
MY_INTERFACE = 'com.example.Foo'
class Foo(dbus.service.object):
# …
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='ss', out_signature='v')
def Get(self, interface_name, property_name):
return self.GetAll(interface_name)[property_name]
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='s', out_signature='a{sv}')
def GetAll(self, interface_name):
if interface_name == MY_INTERFACE:
return { 'Blah': self.blah,
# …
}
else:
raise dbus.exceptions.DBusException(
'com.example.UnknownInterface',
'The Foo object does not implement the %s interface'
% interface_name)
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='ssv'):
def Set(self, interface_name, property_name, new_value):
# validate the property name and value, update internal state…
self.PropertiesChanged(interface_name,
{ property_name: new_value }, [])
@dbus.service.signal(interface=dbus.PROPERTIES_IFACE,
signature='sa{sv}as')
def PropertiesChanged(self, interface_name, changed_properties,
invalidated_properties):
pass
的dbus-python的应该更容易实现的特性,但它目前是看得很轻保持在最佳。
如果有人喜欢潜水并帮助修理这类东西,他们会受到欢迎。即使将这个样板文件的扩展版本添加到文档中也是一个开始,因为这是一个经常被问到的问题。如果您有兴趣,可以将修补程序发送到D-Bus mailing list,或将其附加到filed against dbus-python on the FreeDesktop bugtracker的错误。
我为我的代码添加了属性[bug 26903](https://bugs.freedesktop.org/show_bug.cgi?id=26903)。 – Teddy 2011-02-17 18:50:03
这个例子不工作,我想是因为:
“”” 可用属性以及它们是否是可写的可以通过调用org.freedesktop.DBus.Introspectable.Introspect来确定,见一节“组织.freedesktop.DBus.Introspectable”。 ''”
和内省数据属性缺失:
我使用的dbus-python的-1.1.1
实现内省是可选的,主要是为了交互式调试:使用API的应用程序应该已经知道它期望的API。所以没有包含在内省数据中的属性并不理想,但不应该是一个主要问题。 (您可以手动扩展Introspect接口的实现以包含属性。) – wjt 2013-02-14 17:40:32
- 1. DBus接口属性
- 2. 如何使用python处理dbus接口的属性?
- 3. 如何使用Emacs的DBUS接口?
- 4. 导出Dbus对象
- 5. 如何断开python DBus连接?
- 6. 如何使用Python导出自定义dbus上的对象?
- 7. python:如何检查出口接口
- 8. 使用bluez python dbus接口连接到蓝牙LE设备
- 9. 导出接口
- 10. MEF/Prism导出/导入属性属性
- 11. 的接口属性
- 12. 属性和接口
- 13. 如何使用boost :: python暴露流畅接口的属性?
- 14. 如何访问接口的属性
- 15. 如何在接口中实现属性
- 16. 如何处理ASP.NET Web API与模型属性出任接口
- 17. 如何列出省略属性访问器的接口方法
- 18. 如何模拟接口属性是一个接口
- 19. 如何在Funscript中导出接口
- 20. 如何在python中显示特定dbus总线名称(/ org/bluez)的接口?
- 21. Magento:导出属性
- 22. 在接口中实现接口属性?
- 23. 接口扩展接口属性
- 24. 接口中的属性属性
- 25. Dbus glib接口的设计和使用
- 26. 如何使用dbus连接HAL
- 27. 如何在python的扩展类中使用dbus导出方法,继承方法?
- 28. python dbus问题
- 29. Python asyncore&dbus
- 30. DBus Python问题
究竟你 “导出接口财产” 是什么意思? – detly 2010-09-20 01:36:41
我的意思是创建一个Dbus属性。但最近我发现它不可能用python做。 – deimus 2010-09-20 20:25:56