Allow overwriting functions in registry, and use it when registring MainDisplay. Fixes bug 1397287

Fixes: https://launchpad.net/bugs/1397287
This commit is contained in:
Tomas Groth 2014-12-01 15:08:13 +00:00
parent e9410de13c
commit 1c71efc532
2 changed files with 6 additions and 5 deletions

View File

@ -105,7 +105,7 @@ class Registry(object):
if key in self.service_list:
del self.service_list[key]
def register_function(self, event, function):
def register_function(self, event, function, overwrite=False):
"""
Register an event and associated function to be called
@ -113,8 +113,9 @@ 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 event in self.functions_list:
if not overwrite and event in self.functions_list:
self.functions_list[event].append(function)
else:
self.functions_list[event] = [function]

View File

@ -153,9 +153,9 @@ 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)
Registry().register_function('live_display_show', self.show_display)
Registry().register_function('update_display_css', self.css_changed)
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)
def set_transparency(self, enabled):
"""