In
my last post I said «The next step is to make my
Player class to export its methods via
DBus and that's it!». Well, tell you what: is not that
easy. If you try to inherit from QObject and
dbus.service.Object you get this error:
In [3]: class Klass (QtCore.QObject, dbus.service.Object): pass
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a
(non-strict) subclass of the metaclasses of all its bases
This occurs when both ancestors have their own metaclasses.
Unluckily Python doesn't resolve it for you. The
answer is to create a intermediate metaclass which inherits from
both metaclasses (which we can obtain with type()) and
make it the metaclass of our class. In code:
class MetaPlayer (type (QObject), type (dbus.service.Object)):
"""Dummy metaclass that allows us to inherit from both QObject and
d.s.Object"""
pass
class Player (QObject, dbus.service.Object):
__metaclass__= MetaPlayer
[...]
Is that it now? Can I go and do my code? Unfortunately no. See this:
qdbus org.kde.satyr
/
/player
Cannot introspect object /player at org.kde.satyr:
org.freedesktop.DBus.Python.KeyError (Traceback (most recent call last):
File "/usr/lib/pymodules/python2.5/dbus/service.py", line 702, in _message_cb
retval = candidate_method(self, *args, **keywords)
File "/usr/lib/pymodules/python2.5/dbus/service.py", line 759, in Introspect
interfaces = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__]
KeyError: '__main__.Player'
)
This is the class dbus.service.Object complaining
something else. It's getting late here and I'm tired, so I'll
continue tomorrow.