DBusProxy#
Added in version 2.26.
Superclasses: Object
Implemented Interfaces: AsyncInitable, DBusInterface, Initable
Provide comfortable and pythonic method calls.
This marshalls the method arguments into a GVariant, invokes the call_sync() method on the DBusProxy object, and unmarshalls the result GVariant back into a Python tuple.
The first argument always needs to be the D-Bus signature tuple of the method call. Example:
proxy = Gio.DBusProxy.new_sync(…) result = proxy.MyMethod(‘(is)’, 42, ‘hello’)
The exception are methods which take no arguments, like proxy.MyMethod(‘()’). For these you can omit the signature and just write proxy.MyMethod().
Optional keyword arguments:
timeout: timeout for the call in milliseconds (default to D-Bus timeout)
flags: Combination of Gio.DBusCallFlags.*
- result_handler: Do an asynchronous method call and invoke
result_handler(proxy_object, result, user_data) when it finishes.
error_handler: If the asynchronous call raises an exception, error_handler(proxy_object, exception, user_data) is called when it finishes. If error_handler is not given, result_handler is called with the exception object as result instead.
user_data: Optional user data to pass to result_handler for asynchronous calls.
Example for asynchronous calls:
- def mymethod_done(proxy, result, user_data):
- if isinstance(result, Exception):
# handle error
- else:
# do something with result
- proxy.MyMethod(‘(is)’, 42, ‘hello’,
result_handler=mymethod_done, user_data=’data’)
Constructors#
- class DBusProxy
- classmethod new_finish(res: AsyncResult) DBusProxy#
Finishes creating a
DBusProxy.Added in version 2.26.
- Parameters:
res – A
AsyncResultobtained from theAsyncReadyCallbackfunction passed tonew().
- classmethod new_for_bus_finish(res: AsyncResult) DBusProxy#
Finishes creating a
DBusProxy.Added in version 2.26.
- Parameters:
res – A
AsyncResultobtained from theAsyncReadyCallbackfunction passed tonew_for_bus().
- classmethod new_for_bus_sync(bus_type: BusType, flags: DBusProxyFlags, info: DBusInterfaceInfo | None, name: str, object_path: str, interface_name: str, cancellable: Cancellable | None = None) DBusProxy#
Like
new_sync()but takes aBusTypeinstead of aDBusConnection.DBusProxyis used in this [example][gdbus-wellknown-proxy].Added in version 2.26.
- Parameters:
bus_type – A
BusType.flags – Flags used when constructing the proxy.
info – A
DBusInterfaceInfospecifying the minimal interface thatproxyconforms to orNone.name – A bus name (well-known or unique).
object_path – An object path.
interface_name – A D-Bus interface name.
cancellable – A
CancellableorNone.
- classmethod new_sync(connection: DBusConnection, flags: DBusProxyFlags, info: DBusInterfaceInfo | None, name: str | None, object_path: str, interface_name: str, cancellable: Cancellable | None = None) DBusProxy#
Creates a proxy for accessing
interface_nameon the remote object atobject_pathowned bynameatconnectionand synchronously loads D-Bus properties unless theDO_NOT_LOAD_PROPERTIESflag is used.If the
DO_NOT_CONNECT_SIGNALSflag is not set, also sets up match rules for signals. Connect to theDBusProxy::g-signal signal to handle signals from the remote object.If both
DO_NOT_LOAD_PROPERTIESandDO_NOT_CONNECT_SIGNALSare set, this constructor is guaranteed to return immediately without blocking.If
nameis a well-known name and theDO_NOT_AUTO_STARTandDO_NOT_AUTO_START_AT_CONSTRUCTIONflags aren’t set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.This is a synchronous failable constructor. See
new()andnew_finish()for the asynchronous version.DBusProxyis used in this [example][gdbus-wellknown-proxy].Added in version 2.26.
- Parameters:
connection – A
DBusConnection.flags – Flags used when constructing the proxy.
info – A
DBusInterfaceInfospecifying the minimal interface thatproxyconforms to orNone.name – A bus name (well-known or unique) or
Noneifconnectionis not a message bus connection.object_path – An object path.
interface_name – A D-Bus interface name.
cancellable – A
CancellableorNone.
Methods#
- class DBusProxy
- async call(self, method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int) Variant#
This is the awaitable version of
call().Added in version 2.26.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
- call(method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously invokes the
method_namemethod onproxy.If
method_namecontains any dots, thennameis split into interface and method name parts. This allows usingproxyfor invoking methods on other interfaces.If the
DBusConnectionassociated withproxyis closed then the operation will fail withCLOSED. Ifcancellableis canceled, the operation will fail withCANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withINVALID_ARGUMENT.If the
parametersVariantis floating, it is consumed. This allows convenient ‘inline’ use ofnew(), e.g.:g_dbus_proxy_call (proxy, "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) two_strings_done, &data);
If
proxyhas an expected interface (seeDBusProxy:g-interface-info) andmethod_nameis referenced by it, then the return value is checked against the return type.This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this method from. You can then callcall_finish()to get the result of the operation. Seecall_sync()for the synchronous version of this method.If
callbackisNonethen the D-Bus method call message will be sent with theNO_REPLY_EXPECTEDflag set.Added in version 2.26.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
cancellable – A
CancellableorNone.callback – A
AsyncReadyCallbackto call when the request is satisfied orNoneif you don’t care about the result of the method invocation.user_data – The data to pass to
callback.
- call_finish(res: AsyncResult) Variant#
Finishes an operation started with
call().Added in version 2.26.
- Parameters:
res – A
AsyncResultobtained from theAsyncReadyCallbackpassed tocall().
- call_sync(method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int, cancellable: Cancellable | None = None) Variant#
Synchronously invokes the
method_namemethod onproxy.If
method_namecontains any dots, thennameis split into interface and method name parts. This allows usingproxyfor invoking methods on other interfaces.If the
DBusConnectionassociated withproxyis disconnected then the operation will fail withCLOSED. Ifcancellableis canceled, the operation will fail withCANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withINVALID_ARGUMENT.If the
parametersVariantis floating, it is consumed. This allows convenient ‘inline’ use ofnew(), e.g.:g_dbus_proxy_call_sync (proxy, "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
The calling thread is blocked until a reply is received. See
call()for the asynchronous version of this method.If
proxyhas an expected interface (seeDBusProxy:g-interface-info) andmethod_nameis referenced by it, then the return value is checked against the return type.Added in version 2.26.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
cancellable – A
CancellableorNone.
- async call_with_unix_fd_list(self, method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int, fd_list: UnixFDList | None = None) tuple[Variant, UnixFDList]#
This is the awaitable version of
call_with_unix_fd_list().Added in version 2.30.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
fd_list – A
UnixFDListorNone.
- call_with_unix_fd_list(method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int, fd_list: UnixFDList | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Like
call()but also takes aUnixFDListobject.This method is only available on UNIX.
Added in version 2.30.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
fd_list – A
UnixFDListorNone.cancellable – A
CancellableorNone.callback – A
AsyncReadyCallbackto call when the request is satisfied orNoneif you don’t care about the result of the method invocation.user_data – The data to pass to
callback.
- call_with_unix_fd_list_finish(res: AsyncResult) tuple[Variant, UnixFDList]#
Finishes an operation started with
call_with_unix_fd_list().Added in version 2.30.
- Parameters:
res – A
AsyncResultobtained from theAsyncReadyCallbackpassed tocall_with_unix_fd_list().
- call_with_unix_fd_list_sync(method_name: str, parameters: Variant | None, flags: DBusCallFlags, timeout_msec: int, fd_list: UnixFDList | None = None, cancellable: Cancellable | None = None) tuple[Variant, UnixFDList]#
Like
call_sync()but also takes and returnsUnixFDListobjects.This method is only available on UNIX.
Added in version 2.30.
- Parameters:
method_name – Name of method to invoke.
parameters – A
Varianttuple with parameters for the signal orNoneif not passing parameters.flags – Flags from the
DBusCallFlagsenumeration.timeout_msec – The timeout in milliseconds (with %G_MAXINT meaning “infinite”) or -1 to use the proxy default timeout.
fd_list – A
UnixFDListorNone.cancellable – A
CancellableorNone.
- do_g_properties_changed(self, changed_properties: Variant, invalidated_properties: str) None#
- Parameters:
changed_properties
invalidated_properties
- do_g_signal(self, sender_name: str, signal_name: str, parameters: Variant) None#
- Parameters:
sender_name
signal_name
parameters
- get_cached_property(property_name: str) Variant | None#
Looks up the value for a property from the cache. This call does no blocking IO.
If
proxyhas an expected interface (seeDBusProxy:g-interface-info) andproperty_nameis referenced by it, thenvalueis checked against the type of the property.Added in version 2.26.
- Parameters:
property_name – Property name.
- get_cached_property_names() list[str] | None#
Gets the names of all cached properties on
proxy.Added in version 2.26.
- get_connection() DBusConnection#
Gets the connection
proxyis for.Added in version 2.26.
- get_default_timeout() int#
Gets the timeout to use if -1 (specifying default timeout) is passed as
timeout_msecin thecall()andcall_sync()functions.See the
DBusProxy:g-default-timeout property for more details.Added in version 2.26.
- get_flags() DBusProxyFlags#
Gets the flags that
proxywas constructed with.Added in version 2.26.
- get_interface_info() DBusInterfaceInfo | None#
Returns the
DBusInterfaceInfo, if any, specifying the interface thatproxyconforms to. See theDBusProxy:g-interface-info property for more details.Added in version 2.26.
- get_name() str | None#
Gets the name that
proxywas constructed for.When connected to a message bus, this will usually be non-
None. However, it may beNonefor a proxy that communicates using a peer-to-peer pattern.Added in version 2.26.
- get_name_owner() str | None#
The unique name that owns the name that
proxyis for orNoneif no-one currently owns that name. You may connect to theObject::notify signal to track changes to theDBusProxy:g-name-owner property.Added in version 2.26.
- classmethod new(flags: DBusProxyFlags, info: DBusInterfaceInfo | None, name: str | None, object_path: str, interface_name: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Creates a proxy for accessing
interface_nameon the remote object atobject_pathowned bynameatconnectionand asynchronously loads D-Bus properties unless theDO_NOT_LOAD_PROPERTIESflag is used. Connect to theDBusProxy::g-properties-changed signal to get notified about property changes.If the
DO_NOT_CONNECT_SIGNALSflag is not set, also sets up match rules for signals. Connect to theDBusProxy::g-signal signal to handle signals from the remote object.If both
DO_NOT_LOAD_PROPERTIESandDO_NOT_CONNECT_SIGNALSare set, this constructor is guaranteed to complete immediately without blocking.If
nameis a well-known name and theDO_NOT_AUTO_STARTandDO_NOT_AUTO_START_AT_CONSTRUCTIONflags aren’t set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.This is a failable asynchronous constructor - when the proxy is ready,
callbackwill be invoked and you can usenew_finish()to get the result.See
new_sync()and for a synchronous version of this constructor.DBusProxyis used in this [example][gdbus-wellknown-proxy].Added in version 2.26.
- Parameters:
flags – Flags used when constructing the proxy.
info – A
DBusInterfaceInfospecifying the minimal interface thatproxyconforms to orNone.name – A bus name (well-known or unique) or
Noneifconnectionis not a message bus connection.object_path – An object path.
interface_name – A D-Bus interface name.
cancellable – A
CancellableorNone.callback – Callback function to invoke when the proxy is ready.
user_data – User data to pass to
callback.
- classmethod new_for_bus(flags: DBusProxyFlags, info: DBusInterfaceInfo | None, name: str, object_path: str, interface_name: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Like
new()but takes aBusTypeinstead of aDBusConnection.DBusProxyis used in this [example][gdbus-wellknown-proxy].Added in version 2.26.
- Parameters:
flags – Flags used when constructing the proxy.
info – A
DBusInterfaceInfospecifying the minimal interface thatproxyconforms to orNone.name – A bus name (well-known or unique).
object_path – An object path.
interface_name – A D-Bus interface name.
cancellable – A
CancellableorNone.callback – Callback function to invoke when the proxy is ready.
user_data – User data to pass to
callback.
- set_cached_property(property_name: str, value: Variant | None = None) None#
If
valueis notNone, sets the cached value for the property with nameproperty_nameto the value invalue.If
valueisNone, then the cached value is removed from the property cache.If
proxyhas an expected interface (seeDBusProxy:g-interface-info) andproperty_nameis referenced by it, thenvalueis checked against the type of the property.If the
valueVariantis floating, it is consumed. This allows convenient ‘inline’ use ofnew(), e.g.g_dbus_proxy_set_cached_property (proxy, "SomeProperty", g_variant_new ("(si)", "A String", 42));
Normally you will not need to use this method since
proxyis tracking changes using theorg.freedesktop.DBus.Properties.PropertiesChangedD-Bus signal. However, for performance reasons an object may decide to not use this signal for some properties and instead use a proprietary out-of-band mechanism to transmit changes.As a concrete example, consider an object with a property
ChatroomParticipantswhich is an array of strings. Instead of transmitting the same (long) array every time the property changes, it is more efficient to only transmit the delta using e.g. signalsChatroomParticipantJoined(String name)andChatroomParticipantParted(String name).Added in version 2.26.
- Parameters:
property_name – Property name.
value – Value for the property or
Noneto remove it from the cache.
- set_default_timeout(timeout_msec: int) None#
Sets the timeout to use if -1 (specifying default timeout) is passed as
timeout_msecin thecall()andcall_sync()functions.See the
DBusProxy:g-default-timeout property for more details.Added in version 2.26.
- Parameters:
timeout_msec – Timeout in milliseconds.
- set_interface_info(info: DBusInterfaceInfo | None = None) None#
Ensure that interactions with
proxyconform to the given interface. See theDBusProxy:g-interface-info property for more details.Added in version 2.26.
- Parameters:
info – Minimum interface this proxy conforms to or
Noneto unset.
Properties#
- class DBusProxy
-
- props.g_connection: DBusConnection#
The type of the None singleton.
Added in version 2.26.
- props.g_flags: DBusProxyFlags#
The type of the None singleton.
Added in version 2.26.
- props.g_interface_info: DBusInterfaceInfo#
The type of the None singleton.
Added in version 2.26.
Signals#
- class DBusProxy.signals
- g_properties_changed(changed_properties: Variant, invalidated_properties: list[str]) None#
The type of the None singleton.
Added in version 2.26.
- Parameters:
changed_properties – A
Variantcontaining the properties that changed (type:a{sv})invalidated_properties – A
Noneterminated array of properties that was invalidated
- g_signal(sender_name: str | None, signal_name: str, parameters: Variant) None#
The type of the None singleton.
Added in version 2.26.
- Parameters:
sender_name – The sender of the signal or
Noneif the connection is not a bus connection.signal_name – The name of the signal.
parameters – A
Varianttuple with parameters for the signal.