1 """Support code for implementing D-Bus services via GObjects."""
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import sys
26 from warnings import warn as _warn
27 _warn(DeprecationWarning("""\
28 dbus.gobject_service is deprecated, and is not available under Python 3.
29
30 Porting from gobject (PyGObject 2) to gi.repository.GObject (PyGObject 3),
31 and using dbus.gi_service instead of dbus.gobject_service, is recommended.
32 """), DeprecationWarning, stacklevel=2)
33
34 if 'gi' in sys.modules:
35
36 from gi.repository import GObject as gobject
37 else:
38
39 import gobject
40
41 import dbus.service
42
44 """A metaclass which inherits from both GObjectMeta and
45 `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`.
46 """
50
52 """A GObject which is exported on the D-Bus.
53
54 Because GObject and `dbus.service.Object` both have custom metaclasses,
55 the naive approach using simple multiple inheritance won't work. This
56 class has `ExportedGObjectType` as its metaclass, which is sufficient
57 to make it work correctly.
58
59 :undocumented: __gtype__
60 """
61 __metaclass__ = ExportedGObjectType
62
63 - def __init__(self, conn=None, object_path=None, **kwargs):
64 """Initialize an exported GObject.
65
66 :Parameters:
67 `conn` : dbus.connection.Connection
68 The D-Bus connection or bus
69 `object_path` : str
70 The object path at which to register this object.
71 :Keywords:
72 `bus_name` : dbus.service.BusName
73 A bus name to be held on behalf of this object, or None.
74 `gobject_properties` : dict
75 GObject properties to be set on the constructed object.
76
77 Any unrecognised keyword arguments will also be interpreted
78 as GObject properties.
79 """
80 bus_name = kwargs.pop('bus_name', None)
81 gobject_properties = kwargs.pop('gobject_properties', None)
82
83 if gobject_properties is not None:
84 kwargs.update(gobject_properties)
85 gobject.GObject.__init__(self, **kwargs)
86 dbus.service.Object.__init__(self, conn=conn,
87 object_path=object_path,
88 bus_name=bus_name)
89