""" This file is part of Mokonnect. Mokonnect is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation. Mokonnect is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Mokonnect. If not, see . """ # # qdbus.py # quick dbus wrapper # import dbus class QDBEConnman(): def __init__(self, iface): self.iface = iface def __getitem__(self,key): # key is propery name prop = self.iface.GetProperties() return prop[key] def __setitem__(self,key,value): self.iface.SetProperty(key,value) def __getattr__(self, name): return self.iface.__getattr__(name) class QDBusObject(): def __init__(self, obj, ifaces, extra_wrap): self.obj = obj self.ifaces = ifaces self.extra_wrap = extra_wrap def __getitem__(self,key): # key is interface key name iface = key if key in self.ifaces: iface = self.ifaces[key] if None == self.extra_wrap: return dbus.Interface(self.obj, dbus_interface=iface) else: return self.extra_wrap(dbus.Interface(self.obj, dbus_interface=iface)) class QDBus(): def __init__(self, busname,mainloop = None,extra_wrap = None): self.busname = busname self.extra_wrap = extra_wrap self.bus = dbus.SystemBus(mainloop=mainloop) self.ifaces = {} def SetInterfaces(self,iface_dict): del self.ifaces self.ifaces = {} for k in iface_dict: self.ifaces[k] = iface_dict[k] def AddSignalFunction(self,func): self.bus.add_signal_receiver(func, bus_name=self.busname, interface_keyword='iface', member_keyword='signal', path_keyword='path') def DelSignalFunction(self,func): self.bus.remove_signal_receiver(func) def __getitem__(self,key): # key is object path return QDBusObject(self.bus.get_object(self.busname, key),self.ifaces,self.extra_wrap)