Joe
Joe

Reputation: 346

Python DBUS - `PropertiesChanged` listener on interface with extra arguments

With the Python 3 DBUS module, the default arguments which a signal handler takes for the PropertiesChanged signal are as follows:

def handler(interface, changed_properties, invalidated_properties): something...

With the listener setup something like below:

dbus.Interface.connect_to_signal("PropertiesChanged", handler)

How can I add an extra argument on the end, so that I can have a signal handler with a structure like this:

def handler(interface, changed_properties, invalidated_properties, extra_argument): something...

Upvotes: 0

Views: 3107

Answers (1)

LEW21
LEW21

Reputation: 190

PropertiesChanged is a part of org.freedesktop.DBus.Properties interface, and you shouldn't modify its signature. Other programs assume, that it's implemented exactly as specified in the DBus specification. It is used by multiple DBus bindings to automatically update properties of proxy objects when they get changed.

You can create your own signal with your own custom arguments:

With python-dbus (deprecated):

class Example(object):
    @dbus.service.signal(dbus_interface='com.example.Sample',
                        signature='us')
    def NumberOfBottlesChanged(self, number, contents):
        pass

With pydbus:

from pydbus.generic import signal

class Example(object):
    """
      <node>
        <interface name='com.example.Sample'>
          <signal name='NumberOfBottlesChanged'>
            <arg type='u' name='number'/>
            <arg type='s' name='contents'/>
          </signal>
        </interface>
      </node>
    """
    NumberOfBottlesChanged = signal()

Upvotes: 1

Related Questions