jklmnn
jklmnn

Reputation: 501

Not getting dbus message arguments

I have set up a piece of code that reads dbus messages:

def nf(bus, message):
  print(message)
  args = message.get_args_list()
  for arg in message.get_args_list():
    print("arg:" + arg)

DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("interface='org.freedesktop.Notifications',eavesdrop='true',member='Notify'")
bus.add_message_filter(nf)
mainloop = gobject.MainLoop()
mainloop.run()

When I start it I get the start message <dbus.lowlevel.SignalMessage path: /org/freedesktop/DBus, iface: org.freedesktop.DBus, member: NameAcquired, dest: :1.215> and the argument 1.215.
But when I send a message with notify-send I also get the message <dbus.lowlevel.MethodCallMessage path: /org/freedesktop/Notifications, iface: org.freedesktop.Notifications, member: Notify dest: :1.212> but I don't get any arguments. When I try this with dbus-monitor I get all arguments. What am I missing?

Upvotes: 1

Views: 719

Answers (1)

Toqoz
Toqoz

Reputation: 131

For some reason, arg does not like being put in a print statement with something else. It seems that python does not convert list items to strings automatically like it would if you were just printing something like arg[0].

Change

print('arg:' + arg)

To

print('arg:' + str(arg))

Or even

print('%s %s' % ('arg:', arg))

Upvotes: 1

Related Questions