dasbus.server.template module

class BasicInterfaceTemplate(implementation)[source]

Bases: object

Basic template for a DBus interface.

This template uses a software design pattern called proxy.

This class provides a recommended way how to define DBus interfaces and create publishable DBus objects. The class that defines a DBus interface should inherit this class and be decorated with @dbus_class or @dbus_interface decorator. The implementation of this interface will be provided by a separate object called implementation. Therefore the methods of this class should call the methods of the implementation, the signals should be connected to the signals of the implementation and the getters and setters of properties should access the properties of the implementation.

@dbus_interface("org.myproject.X")
class InterfaceX(BasicInterfaceTemplate):
    def DoSomething(self) -> Str:
        return self.implementation.do_something()

class X(object):
    def do_something(self):
        return "Done!"

x = X()
i = InterfaceX(x)

DBus.publish_object("/org/myproject/X", i)
connect_signals()[source]

Interconnect the signals.

You should connect the emit methods of the interface signals to the signals of the implementation. Every time the implementation emits a signal, this interface reemits the signal on DBus.

property implementation

Return the implementation of this interface.

Returns

an implementation

class InterfaceTemplate(implementation)[source]

Bases: BasicInterfaceTemplate, PropertiesInterface

Template for a DBus interface.

The interface provides the support for the standard interface org.freedesktop.DBus.Properties.

Usage:

def connect_signals(self):
    super().connect_signals()
    self.implementation.module_properties_changed.connect(
        self.flush_changes
    )
    self.watch_property("X", self.implementation.x_changed)

@property
def X(self, x) -> Int:
    return self.implementation.x

@emits_properties_changed
def SetX(self, x: Int):
    self.implementation.set_x(x)
watch_property(property_name, signal)[source]

Watch a DBus property.

Report a change when the property is changed.

Parameters
  • property_name – a name of a DBus property

  • signal – a signal that emits when the property is changed