From 8b57f06e0c04f5c9b87a3c76618230d757412076 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 24 May 2016 15:14:53 +0200 Subject: python: Support status callbacks. * lang/python/helpers.c (pyStatusCb): New function. (pygpgme_set_status_cb): Likewise. * lang/python/helpers.h (pygpgme_set_status_cb): New prototype. * lang/python/pyme/core.py (Context.__init__): Initialize 'last_statuscb'. (Context._free_statuscb): New function. (Context.set_status_cb): Likewise. * lang/python/tests/t-callbacks.py: Test status callbacks. Signed-off-by: Justus Winter --- lang/python/pyme/core.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lang/python/pyme') diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py index 43a24131..f15444be 100644 --- a/lang/python/pyme/core.py +++ b/lang/python/pyme/core.py @@ -64,6 +64,7 @@ class Context(GpgmeWrapper): super().__init__(wrapped) self.last_passcb = None self.last_progresscb = None + self.last_statuscb = None def __del__(self): if not pygpgme: @@ -91,6 +92,14 @@ class Context(GpgmeWrapper): pygpgme.delete_PyObject_p_p(self.last_progresscb) self.last_progresscb = None + def _free_statuscb(self): + if self.last_statuscb != None: + if pygpgme.pygpgme_clear_generic_cb: + pygpgme.pygpgme_clear_generic_cb(self.last_statuscb) + if pygpgme.delete_PyObject_p_p: + pygpgme.delete_PyObject_p_p(self.last_statuscb) + self.last_statuscb = None + def op_keylist_all(self, *args, **kwargs): self.op_keylist_start(*args, **kwargs) key = self.op_keylist_next() @@ -195,6 +204,29 @@ class Context(GpgmeWrapper): hookdata = (self, func, hook) pygpgme.pygpgme_set_progress_cb(self.wrapped, hookdata, self.last_progresscb) + def set_status_cb(self, func, hook=None): + """Sets the status callback to the function specified by FUNC. If + FUNC is None, the callback will be cleared. + + The function will be called with two arguments, keyword and + args. If HOOK is not None, it will be supplied as third + argument. + + Please see the GPGME manual for more information. + + """ + self._free_statuscb() + if func == None: + hookdata = None + else: + self.last_statuscb = pygpgme.new_PyObject_p_p() + if hook == None: + hookdata = (self, func) + else: + hookdata = (self, func, hook) + pygpgme.pygpgme_set_status_cb(self.wrapped, hookdata, + self.last_statuscb) + def get_engine_info(self): """Returns this context specific engine info""" return pygpgme.gpgme_ctx_get_engine_info(self.wrapped) -- cgit v1.2.3