diff --git a/ChangeLog b/ChangeLog index 1e5e0e25a..6a16df854 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2005-04-01 Richard Taylor + * src/GrampsDBCallback.py: Don't check callbacks if the dict is empty. + 2005-04-04 Don Allingham * src/GrampsDbBase.py: add "request_rebuild" to encapsulate rebuild requests in the database instance diff --git a/src/GrampsDBCallback.py b/src/GrampsDBCallback.py index a321a5a2c..5bd948766 100644 --- a/src/GrampsDBCallback.py +++ b/src/GrampsDBCallback.py @@ -170,18 +170,20 @@ class GrampsDBCallback(object): sys.stderr.write("arg passed was: %s type should be: %s" % (args[i],repr(arg_types[i]))) return - - for cb in self.__callback_map[signal_name]: - try: - if type(cb) == tuple: # call class method - cb[0](cb[1],*args) - elif type(cb) == types.FunctionType or \ - type(cb) == types.MethodType: # call func - cb(*args) - else: - sys.stderr.write("Warning: badly formed entry in callback map") - except: - sys.stderr.write("Warning: exception occured in callback function.") + + if signal_name in self.__callback_map.keys(): + # Don't bother if there are no callbacks. + for cb in self.__callback_map[signal_name]: + try: + if type(cb) == tuple: # call class method + cb[0](cb[1],*args) + elif type(cb) == types.FunctionType or \ + type(cb) == types.MethodType: # call func + cb(*args) + else: + sys.stderr.write("Warning: badly formed entry in callback map") + except: + sys.stderr.write("Warning: exception occured in callback function.") # # instance signals control methods @@ -235,6 +237,26 @@ if __name__ == "__main__": 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 rl[0] == 1, "Wrong argument recieved"