2005-04-01 Richard Taylor <rjt-gramps@thegrindstone.me.uk>

* src/GrampsDBCallback.py: Don't check callbacks if the dict is empty.


svn: r4293
This commit is contained in:
Richard Taylor 2005-04-04 19:28:55 +00:00
parent 1504585907
commit 0594e406d7
2 changed files with 37 additions and 12 deletions

View File

@ -1,3 +1,6 @@
2005-04-01 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/GrampsDBCallback.py: Don't check callbacks if the dict is empty.
2005-04-04 Don Allingham <don@gramps-project.org> 2005-04-04 Don Allingham <don@gramps-project.org>
* src/GrampsDbBase.py: add "request_rebuild" to encapsulate rebuild * src/GrampsDbBase.py: add "request_rebuild" to encapsulate rebuild
requests in the database instance requests in the database instance

View File

@ -171,17 +171,19 @@ class GrampsDBCallback(object):
% (args[i],repr(arg_types[i]))) % (args[i],repr(arg_types[i])))
return return
for cb in self.__callback_map[signal_name]: if signal_name in self.__callback_map.keys():
try: # Don't bother if there are no callbacks.
if type(cb) == tuple: # call class method for cb in self.__callback_map[signal_name]:
cb[0](cb[1],*args) try:
elif type(cb) == types.FunctionType or \ if type(cb) == tuple: # call class method
type(cb) == types.MethodType: # call func cb[0](cb[1],*args)
cb(*args) elif type(cb) == types.FunctionType or \
else: type(cb) == types.MethodType: # call func
sys.stderr.write("Warning: badly formed entry in callback map") cb(*args)
except: else:
sys.stderr.write("Warning: exception occured in callback function.") sys.stderr.write("Warning: badly formed entry in callback map")
except:
sys.stderr.write("Warning: exception occured in callback function.")
# #
# instance signals control methods # instance signals control methods
@ -235,6 +237,26 @@ if __name__ == "__main__":
t.emit('test-signal',(1,)) t.emit('test-signal',(1,))
assert len(rl) == 1, "No signal emitted"
assert rl[0] == 1, "Wrong argument recieved"
def test_noargs(self):
class TestSignals(GrampsDBCallback):
__signals__ = {
'test-noargs' : None
}
rl = []
def fn(r=rl):
rl.append(1)
t = TestSignals()
t.connect('test-noargs',fn)
t.emit('test-noargs')
assert len(rl) == 1, "No signal emitted" assert len(rl) == 1, "No signal emitted"
assert rl[0] == 1, "Wrong argument recieved" assert rl[0] == 1, "Wrong argument recieved"