[Interest] DBus PropertiesChanged signal with PySide6/Python

Matthias Nacke matthias at nacke-online.net
Mon Dec 18 08:58:49 CET 2023


Hello,

I try to connect the DBus PropertiesChanged Signal with Qt and 
PySide6/Python, the signal has the following signature:

org.freedesktop.DBus.Properties.PropertiesChanged (STRING interface_name,
                                                    ARRAY of 
DICT_ENTRY<STRING,VARIANT> changed_properties,
ARRAY<STRING> invalidated_properties);

Concrete I need the signal and PropertiesChanged metadata of the MPRIS 
standard (https://specifications.freedesktop.org/mpris-spec/latest/, 
https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/), 
the meta data has a dictionary in the propertieschanged dictionary and 
the inner dictionary has arrays as values on some entries, I can see the 
data by setting the environment variable "QDBUS_DEBUG": "1" or on a 
cross check using sdbus:

('org.mpris.MediaPlayer2.Player',
{'Metadata': ('a{sv}', {'xesam:albumArtist': ('as', ['Daft Punk', 
'Pharrell Williams', 'Nile Rodgers']),
             'mpris:trackid': ('o', 
'/spotify/track/2Foc5Q5nqNiosCNqttzHof'),
             'xesam:title': ('s', 'Get Lucky (Radio Edit) [feat. 
Pharrell Williams and Nile Rodgers]'),
             'xesam:album': ('s', 'Get Lucky (Radio Edit) [feat. 
Pharrell Williams and Nile Rodgers]'),
             'xesam:trackNumber': ('u', 1), 'xesam:discNumber': ('i', 1),
             'mpris:artUrl': ('s', 
'https://i.scdn.co/image/ab67616d0000b2731d5cf960a92bb8b03fc2be7f'),
             'xesam:url': ('s', 
'https://open.spotify.com/track/2Foc5Q5nqNiosCNqttzHof'),
             'mpris:length': ('x', 248413000), 'xesam:autoRating': ('d', 
0.82),
             'xesam:artist': ('as', ['Daft Punk', 'Pharrell Williams', 
'Nile Rodgers'])}),
             'PlaybackStatus': ('s', 'Playing')},
[])

I test it currently with the DBus NetworkManager, it is simpler as it 
has no inner dictionary, but some arrays of objects as value and I can 
force the signal by enabling and disabling my network connection on 
Ubuntu, these are 2 example outputs:

('org.freedesktop.NetworkManager', {'ActiveConnections': ('ao', 
['/org/freedesktop/NetworkManager/ActiveConnection/8'])}, [])
('org.freedesktop.NetworkManager', {'State': ('u', 40)}, [])

But for neither of the 2 I can't get the connected slot method to run, I 
also don't get any error.

I managed to connect to DBus signals with simple data types, but I can't 
get it to work with PropertiesChanged, whith the dictionaries and arrays.

I have uploaded demos on github with a Visual Studio Code project: 
https://github.com/Drexel2k/qdbus

This is the NetworkManager demo I want to get to work first: 
https://github.com/Drexel2k/qdbus/blob/main/qdbusdemo_netmanpropertieschanged.py
This is a working cross check with sdbus: 
https://github.com/Drexel2k/qdbus/blob/main/sdbusdemo.py
This is a working demo with the simple data types: 
https://github.com/Drexel2k/qdbus/blob/main/qdbusdemo_dbusnameownerchanged.py

For all of the 3 a debug config exists, currently for the Qt modules the 
QDBUS_DEBUG environment variable is set to 0, but it can be easily 
enabled by setting it to 1.

The documentation (https://doc.qt.io/qt-6/qdbustypesystem.html) also says:
Extending the Type System
In order to use one's own type with Qt D-Bus, the type has to be 
declared as a Qt meta-type with the Q_DECLARE_METATYPE() macro and 
registered with the qDBusRegisterMetaType() function. The streaming 
operators operator>> and operator<< will be automatically found by the 
registration system.

and:

Warning: You may not use any type that is not on the list above, 
including typedefs to the types listed. This also includes 
QList<QVariant> and QMap<QString,QVariant>.

I saw some C++ examples also using QDBusArgument and overloading the 
streaming operators, I don't know if this would be the solution, but I 
also don't know how to do this in Python.

Any help is appreciated, thank you in advance!

Best regards
Matthias



More information about the Interest mailing list