0

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...

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

3 Comments

I'm using the freedesktop dbus module for Python 3, I think that's the same as the first example above. My goal is ultimately to create a signal receiver, but with which I can pass the self object of a class (so I can modify the class's members) - I only need to change it for this program, as it's only going to be used once.
Couldn't you simply use a lambda as the handler, and use self from its lexical scope?
that might be a solution, I'll try it out :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.