From af4715dc3c2a53c7f7a836c16377af7f894e0444 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 2 Dec 2014 09:46:19 +0000 Subject: [PATCH] Remove the registered functions instead of overwriting --- openlp/core/common/registry.py | 9 ++------- openlp/core/ui/maindisplay.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index 70c2fe3bd..455c3385d 100644 --- a/openlp/core/common/registry.py +++ b/openlp/core/common/registry.py @@ -105,7 +105,7 @@ class Registry(object): if key in self.service_list: del self.service_list[key] - def register_function(self, event, function, overwrite=False): + def register_function(self, event, function): """ Register an event and associated function to be called @@ -113,9 +113,8 @@ class Registry(object): will/may need to respond to a single action and the caller does not need to understand or know about the recipients. :param function: The function to be called when the event happens. - :param overwrite: There should only be one function with the registred name. """ - if not overwrite and event in self.functions_list: + if event in self.functions_list: self.functions_list[event].append(function) else: self.functions_list[event] = [function] @@ -127,10 +126,6 @@ class Registry(object): :param event: The function description.. :param function: The function to be called when the event happens. """ - if not self.running_under_test: - trace_error_handler(log) - log.error('Invalid Method call for key %s' % event) - raise KeyError('Invalid Method call for key %s' % event) if event in self.functions_list: self.functions_list[event].remove(function) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index ceb94a2a9..d238a1f5e 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -153,9 +153,20 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.set_transparency(False) if self.is_live: - Registry().register_function('live_display_hide', self.hide_display, True) - Registry().register_function('live_display_show', self.show_display, True) - Registry().register_function('update_display_css', self.css_changed, True) + Registry().register_function('live_display_hide', self.hide_display) + Registry().register_function('live_display_show', self.show_display) + Registry().register_function('update_display_css', self.css_changed) + + def close(self): + """ + Remove registered function on close. + """ + if self.is_live: + Registry().remove_function('live_display_hide', self.hide_display) + Registry().remove_function('live_display_show', self.show_display) + Registry().remove_function('update_display_css', self.css_changed) + super().close() + def set_transparency(self, enabled): """