Package dbus :: Module gobject_service
[hide private]
[frames] | no frames]

Source Code for Module dbus.gobject_service

 1  """Support code for implementing D-Bus services via GObjects.""" 
 2   
 3  # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> 
 4  # 
 5  # Permission is hereby granted, free of charge, to any person 
 6  # obtaining a copy of this software and associated documentation 
 7  # files (the "Software"), to deal in the Software without 
 8  # restriction, including without limitation the rights to use, copy, 
 9  # modify, merge, publish, distribute, sublicense, and/or sell copies 
10  # of the Software, and to permit persons to whom the Software is 
11  # furnished to do so, subject to the following conditions: 
12  # 
13  # The above copyright notice and this permission notice shall be 
14  # included in all copies or substantial portions of the Software. 
15  # 
16  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
17  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
18  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
19  # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
20  # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
21  # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
22  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
23  # DEALINGS IN THE SOFTWARE. 
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      # this worked in dbus-python 1.0, so preserve the functionality 
36      from gi.repository import GObject as gobject 
37  else: 
38      # this worked in dbus-python < 1.0 
39      import gobject 
40   
41  import dbus.service 
42   
43 -class ExportedGObjectType(gobject.GObject.__class__, dbus.service.InterfaceType):
44 """A metaclass which inherits from both GObjectMeta and 45 `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`. 46 """
47 - def __init__(cls, name, bases, dct):
48 gobject.GObject.__class__.__init__(cls, name, bases, dct) 49 dbus.service.InterfaceType.__init__(cls, name, bases, dct)
50
51 -class ExportedGObject(gobject.GObject, dbus.service.Object):
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 __metaclass__ = ExportedGObjectType 60
61 - def __init__(self, conn=None, object_path=None, **kwargs):
62 """Initialize an exported GObject. 63 64 :Parameters: 65 `conn` : dbus.connection.Connection 66 The D-Bus connection or bus 67 `object_path` : str 68 The object path at which to register this object. 69 :Keywords: 70 `bus_name` : dbus.service.BusName 71 A bus name to be held on behalf of this object, or None. 72 `gobject_properties` : dict 73 GObject properties to be set on the constructed object. 74 75 Any unrecognised keyword arguments will also be interpreted 76 as GObject properties. 77 """ 78 bus_name = kwargs.pop('bus_name', None) 79 gobject_properties = kwargs.pop('gobject_properties', None) 80 81 if gobject_properties is not None: 82 kwargs.update(gobject_properties) 83 gobject.GObject.__init__(self, **kwargs) 84 dbus.service.Object.__init__(self, conn=conn, 85 object_path=object_path, 86 bus_name=bus_name)
87