Replies: 3 comments 14 replies
-
|
Hello @darkipod Does the service you are trying to call have an introspection? You can use the D-Spy to browse the D-Bus clients. If it has introspection when you use the interface generator to generate the Python class. If not you will have to write the class by hand. See examples directory: Interface definition: https://github.com/python-sdbus/python-sdbus/blob/master/examples/simple/example_interface.py Client: https://github.com/python-sdbus/python-sdbus/blob/master/examples/simple/client.py Also see NetworkManager examples: https://github.com/python-sdbus/python-sdbus-networkmanager/tree/master/examples/2.0.0 |
Beta Was this translation helpful? Give feedback.
-
|
Here is an example of a blocking interface method and property: from __future__ import annotations
import sdbus
# WARN: D-Bus daemon interface is already available under
# `sdbus_block.dbus_daemon` and `sdbus_async.dbus_daemon`.
# This is just an example of implementing it from scratch.
class DaemonExampleInterface(
sdbus.DbusInterfaceCommon,
interface_name="org.freedesktop.DBus",
):
@sdbus.dbus_method(
input_signature="", # Method takes no arguments
result_signature="as", # Method returns a list of strings
method_name="GetId", # Override default method name converter
)
def get_dbus_id(self) -> list[str]:
raise NotImplementedError # The function's body is never used
@sdbus.dbus_property(
property_signature="as", # Property type is a list of strings
# Automatic name converter will convert Python name "interfaces" to
# D-Bus name "Interfaces"
# Uncomment following line to force D-Bus name to a specific value.
# property_name="Interfaces",
)
def interfaces(self) -> list[str]:
raise NotImplementedError # The function's body is never used
def main() -> None:
user_dbus = sdbus.sd_bus_open_user() # Use sd_bus_open_system to open system bus
sdbus.set_default_bus(user_dbus)
daemon = DaemonExampleInterface(
# Service name and object path defined by D-Bus specification
# https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-messages
service_name="org.freedesktop.DBus",
object_path="/org/freedesktop/DBus",
# Other services will have their own paths. Consult their documentation
# and implementation.
)
# Using method
print("D-Bus id:", daemon.get_dbus_id())
# Using property:
print("Interfaces:", daemon.interfaces)
if __name__ == "__main__":
main()It implements the D-Bus daemon interface that should be available on any D-Bus. |
Beta Was this translation helpful? Give feedback.
-
|
I added a blocking variant of the simple example: https://github.com/python-sdbus/python-sdbus/blob/master/examples/simple/client_blocking.py |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am struggling to get a blocking method to work, the example code for the blocking portion of the API doesn't currently call from the example server code and I am unable to figure out how to get it to do so. I also have been unable to find any other examples of anyone doing something similar. My use case is thus:
I have a GTK app (using PyGObject which does not have support for DBus calls natively that I can find) that needs to send user input over DBus to a DBus server. I thought I could build a simple proof of concept for this but I cannot get blocking to do anything. I would rather not use async for this because I dont want to deal with multiple threads (or queues) for no reason. The app does not need to get a response, it only needs to send hello world to the server via a method...
Beta Was this translation helpful? Give feedback.
All reactions