File: //usr/lib/python3.9/site-packages/dasbus/server/__pycache__/template.cpython-39.opt-1.pyc
a
װ_� � @ sH d dl mZ d dlmZ ddgZG dd� ded�ZG dd� dee�ZdS ) � )�ABCMeta)�PropertiesInterface�BasicInterfaceTemplate�InterfaceTemplatec @ s, e Zd ZdZdd� Zedd� �Zdd� ZdS ) r al 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.
.. code-block:: python
@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)
c C s || _ | �� dS )znCreate a publishable DBus object.
:param implementation: an implementation of this interface
N)�_implementation�connect_signals��self�implementation� r �:/usr/lib/python3.9/site-packages/dasbus/server/template.py�__init__@ s zBasicInterfaceTemplate.__init__c C s | j S )zYReturn the implementation of this interface.
:return: an implementation
)r �r r r r r
H s z%BasicInterfaceTemplate.implementationc C s dS )z�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.
Nr r r r r r P s z&BasicInterfaceTemplate.connect_signalsN)�__name__�
__module__�__qualname__�__doc__r
�propertyr
r r r r r r s
)� metaclassc @ s e Zd ZdZdd� Zdd� ZdS )r a} Template for a DBus interface.
The interface provides the support for the standard interface
org.freedesktop.DBus.Properties.
Usage:
.. code-block:: python
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)
c C s t �| � t�| |� d S �N)r r
r r r r r r
v s
zInterfaceTemplate.__init__c s( �j �� � � �fdd�}|�|� dS )z�Watch a DBus property.
Report a change when the property is changed.
:param property_name: a name of a DBus property
:param signal: a signal that emits when the property is changed
c s �� � � d S r )Zreport_changed_property)�args�kwargs��
property_namer r r �callback� s z2InterfaceTemplate.watch_property.<locals>.callbackN)Z_properties_changesZcheck_propertyZconnect)r r �signalr r r r �watch_propertyz s z InterfaceTemplate.watch_propertyN)r r r r r
r r r r r r [ s N)�abcr Zdasbus.server.propertyr �__all__r r r r r r �<module> s �<