From 1bdc2f5df646efda05e39d15f19f6341bb359be6 Mon Sep 17 00:00:00 2001 From: Nico Opiyo Date: Fri, 1 Mar 2019 16:22:34 +0300 Subject: [PATCH] Refactored the hex_to_rgb method in the alerts manager class --- openlp/plugins/alerts/lib/alertsmanager.py | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index f33f2e8c1..c996d8996 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -85,13 +85,18 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties): not Settings().value('core/display on monitor')): return text = self.alert_list.pop(0) - # Put alert settings together for dict + + # Get the rgb color format of the font & background hex colors from settings + rgb_font_color = self.hex_to_rgb(QtGui.QColor(Settings().value('alerts/font color'))) + rgb_background_color = self.hex_to_rgb(QtGui.QColor(Settings().value('alerts/background color'))) + + # Put alert settings together in dict that will be passed to Display in Javascript alert_settings = { - 'background_color': self.hex_to_rgb(Settings().value('alerts/background color')), + 'background_color': rgb_background_color, 'location': Settings().value('alerts/location'), 'font_face': Settings().value('alerts/font face'), 'font_size': Settings().value('alerts/font size'), - 'font_color': self.hex_to_rgb(Settings().value('alerts/font color')), + 'font_color': rgb_font_color, 'timeout': Settings().value('alerts/timeout') } self.live_controller.displays[0].alert(text, json.dumps(alert_settings)) @@ -112,9 +117,12 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties): self.timer_id = 0 self.generate_alert() - def hex_to_rgb(self, hex_color): - rgb_values = QtGui.QColor(hex_color) - rgb_color = 'rgb(' + str(rgb_values.red()) + ", " \ - + str(rgb_values.green()) + ", " + \ - str(rgb_values.blue()) + ")" - return rgb_color + def hex_to_rgb(self, rgb_values): + """ + Converts rgb color values from QColor to rgb string + + :param rgb_values: + :return: rgb color string + :rtype: string + """ + return "rgb(" + rgb_values.red() + ", " + rgb_values.green() + ", " + rgb_values.blue() + ")" \ No newline at end of file