D-Bus#
There are several classes that can help you interact with D-Bus.
- class ignis.dbus.DBusService(name: str, object_path: str, info: gi.repository.Gio.DBusInterfaceInfo, on_name_acquired: Callable | None = None, on_name_lost: Callable | None = None)#
A class that helps create a D-Bus service.
from gi.repository import Gio, GLib from ignis.dbus import DBusService def _MyMethod(invocation: Gio.DBusMethodInvocation, prop1: str, prop2: str, *args) -> GLib.Variant: print("do something") return GLib.Variant("(is)", (42, "hello")) def _MyProperty() -> GLib.Variant: return GLib.Variant("(b)", (False,)) dbus = DBusService(...) dbus.register_dbus_method("MyMethod", _MyMethod) dbus.register_dbus_property("MyProperty", _MyProperty)
- property info: gi.repository.Gio.DBusInterfaceInfo#
required, read-only
An instance of
Gio.DBusInterfaceInfo
You can get it from XML using
load_interface_xml()
.
- property on_name_acquired: Callable#
optional, read-write
The function to call when
name
is acquired.
- property connection: gi.repository.Gio.DBusConnection#
not argument, read-only
The instance of
Gio.DBusConnection
for this service.
- property methods: dict[str, Callable]#
not argument, read-only
The dictionary of registred DBus methods. See
register_dbus_method()
.
- property properties: dict[str, Callable]#
not argument, read-only
The dictionary of registred DBus properties. See
register_dbus_property()
.
- register_dbus_method(name: str, method: Callable) None #
Register a D-Bus method for this service.
- Parameters:
- Return type:
- DBus methods:
Must accept
Gio.DBusMethodInvocation
as the first argument.Must accept all other arguments typical for this method (specified by interface info).
Must return
GLib.Variant
orNone
, as specified by interface info.
- register_dbus_property(name: str, method: Callable) None #
Register D-Bus property for this service.
- Parameters:
- Return type:
- DBus properties:
Must return
GLib.Variant
, as specified by interface info.
- emit_signal(signal_name: str, parameters: gi.repository.GLib.Variant | None = None) None #
Emit a D-Bus signal on this service.
- Parameters:
signal_name (
str
) -- The name of the signal to emit.parameters (
Variant
|None
, default:None
) -- TheGLib.Variant
containing paramaters to pass with the signal.
- Return type:
- class ignis.dbus.DBusProxy(name: str, object_path: str, interface_name: str, info: gi.repository.Gio.DBusInterfaceInfo, bus_type: Literal['session', 'system'] = 'session')#
A class to interact with D-Bus services (create a D-Bus proxy). Unlike
Gio.DBusProxy>
, this class also provides convenient pythonic property access.To call a D-Bus method, use the standart pythonic way. The first argument always needs to be the DBus signature tuple of the method call. Next arguments must match the provided D-Bus signature. If the D-Bus method does not accept any arguments, do not pass them.
from ignis.dbus import DBusProxy proxy = DBusProxy(...) result = proxy.MyMethod("(is)", 42, "hello") print(result)
To get a D-Bus property:
from ignis.dbus import DBusProxy proxy = DBusProxy(...) print(proxy.MyValue)
To set a D-Bus property:
from ignis.dbus import DBusProxy proxy = DBusProxy(...) # pass GLib.Variant as new property value proxy.MyValue = GLib.Variant("s", "Hello world!")
- property info: gi.repository.Gio.DBusInterfaceInfo#
required, read-only
A
Gio.DBusInterfaceInfo
instance.You can get it from XML using
load_interface_xml
.
- property bus_type: Literal['session', 'system']#
optional, read-only
The type of the bus.
Default:
session
.
- property proxy: gi.repository.Gio.DBusProxy#
not argument, read-only
The
Gio.DBusProxy
instance.
- property connection: gi.repository.Gio.DBusConnection#
not argument, read-only
The instance of
Gio.DBusConnection
for this proxy.
- property properties: list[str]#
not argument, read-only
A list of properties exposed by D-Bus service.
- signal_subscribe(signal_name: str, callback: Callable | None = None) int #
Subscribe to D-Bus signal.
- Parameters:
- Return type:
- Returns:
A subscription ID that can be used with
signal_unsubscribe()