Python interface: creating methods on the fly

Jeremy Sanders jeremy at jeremysanders.net
Sat Jan 24 14:30:28 PST 2009


Hi - I'm trying to create methods on the fly in my Python (PyQt) program, 
as the dbus method names are obtained from elsewhere in he code. I've 
tried to hack code like this, but it doesn't work.

class DBusActionObject(dbus.service.Object):
     def __init__(self, toolbar):
         dbus.service.Object.__init__(self,
                                      sessionbus,
                                      '/Test')

     def addAction(self, name, action):
         def fn(selfparam):
             action.trigger()
         fn.__name__ = name
         # didn't work either
         # fn = new.instancemethod(fn, self, DBusActionObject)
         fn = dbus.service.method(
             dbus_interface=dbus.interface,
             in_signature='', out_signature='')(fn)
         setattr(self, name, fn)

What I would like to happen is to make a method "name" which calls the 
function action.trigger() (to trigger a PyQt QAction).

Is there any way to do this with the current python dbus interface?

Thanks

Jeremy

-- 
Jeremy Sanders <jeremy at jeremysanders.net>
http://www.jeremysanders.net/                Cambridge, UK
Public Key Server PGP Key ID: E1AAE053


More information about the dbus mailing list