clean up alertsmanager

- the alertsmanager does not manage the alerts anymore, they are managed by the display
- thus the list of alerts is not needed, the id is not needed, also the
  timer id is not needed
- live_display_active is not needed anymore
- there is no point in using the status message
This commit is contained in:
Andreas P 2021-10-23 15:02:46 +02:00
parent 59f625bd8f
commit ddcc7dbd4f
3 changed files with 8 additions and 47 deletions

View File

@ -413,9 +413,6 @@ class DisplayWindow(QtWidgets.QWidget, RegistryProperties, LogMixin):
if self.isHidden(): if self.isHidden():
self.setVisible(True) self.setVisible(True)
self.hide_mode = None self.hide_mode = None
# Trigger actions when display is active again.
if self.is_display:
Registry().execute('live_display_active')
def hide_display(self, mode=HideMode.Screen): def hide_display(self, mode=HideMode.Screen):
""" """

View File

@ -26,7 +26,6 @@ import json
from PyQt5 import QtCore, QtGui from PyQt5 import QtCore, QtGui
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import LogMixin, RegistryProperties from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.registry import Registry, RegistryBase from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.display.screens import ScreenList from openlp.core.display.screens import ScreenList
@ -40,9 +39,6 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties):
def __init__(self, parent): def __init__(self, parent):
super(AlertsManager, self).__init__() super(AlertsManager, self).__init__()
self.timer_id = 0
self.alert_list = []
Registry().register_function('live_display_active', self.generate_alert)
Registry().register_function('alerts_text', self.alert_text) Registry().register_function('alerts_text', self.alert_text)
self.alerts_text.connect(self.alert_text) self.alerts_text.connect(self.alert_text)
@ -65,56 +61,25 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties):
:param text: The text to display :param text: The text to display
""" """
self.log_debug('display alert called {text}'.format(text=text)) self.log_debug(f'display alert called "{text}"')
if text: if not text:
self.alert_list.append(text) return
if self.timer_id != 0: if len(ScreenList()) == 1 and not self.settings.value('core/display on monitor'):
self.main_window.show_status_message(
translate('AlertsPlugin.AlertsManager', 'Alert message created and displayed.'))
return
self.main_window.show_status_message('')
self.generate_alert()
def generate_alert(self):
"""
Format and request the Alert and start the timer.
"""
if not self.alert_list or (len(ScreenList()) == 1 and
not self.settings.value('core/display on monitor')):
return return
text = self.alert_list.pop(0)
# Get the rgb color format of the font & background hex colors from settings
rgb_font_color = self.hex_to_rgb(QtGui.QColor(self.settings.value('alerts/font color')))
rgb_background_color = self.hex_to_rgb(QtGui.QColor(self.settings.value('alerts/background color')))
# Put alert settings together in dict that will be passed to Display in Javascript # Put alert settings together in dict that will be passed to Display in Javascript
alert_settings = { alert_settings = {
'backgroundColor': rgb_background_color, 'backgroundColor': self._hex_to_rgb(QtGui.QColor(self.settings.value('alerts/background color'))),
'location': self.settings.value('alerts/location'), 'location': self.settings.value('alerts/location'),
'fontFace': self.settings.value('alerts/font face'), 'fontFace': self.settings.value('alerts/font face'),
'fontSize': self.settings.value('alerts/font size'), 'fontSize': self.settings.value('alerts/font size'),
'fontColor': rgb_font_color, 'fontColor': self._hex_to_rgb(QtGui.QColor(self.settings.value('alerts/font color'))),
'timeout': self.settings.value('alerts/timeout'), 'timeout': self.settings.value('alerts/timeout'),
'repeat': self.settings.value('alerts/repeat'), 'repeat': self.settings.value('alerts/repeat'),
'scroll': self.settings.value('alerts/scroll') 'scroll': self.settings.value('alerts/scroll')
} }
self.live_controller.displays[0].alert(text, json.dumps(alert_settings)) self.live_controller.display.alert(text, json.dumps(alert_settings))
def timerEvent(self, event): def _hex_to_rgb(self, rgb_values):
"""
Time has finished so if our time then request the next Alert if there is one and reset the timer.
:param event: the QT event that has been triggered.
"""
if event.timerId() == self.timer_id:
alert_tab = self.parent().settings_tab
self.live_controller.display.alert('', alert_tab.location)
self.killTimer(self.timer_id)
self.timer_id = 0
self.generate_alert()
def hex_to_rgb(self, rgb_values):
""" """
Converts rgb color values from QColor to rgb string Converts rgb color values from QColor to rgb string

View File

@ -483,7 +483,6 @@ def test_show_display(mocked_screenlist, mocked_registry_execute, display_window
# THEN: Should show the display and set the hide mode to none # THEN: Should show the display and set the hide mode to none
display_window.setVisible.assert_called_once_with(True) display_window.setVisible.assert_called_once_with(True)
display_window.run_javascript.assert_called_once_with('Display.show();') display_window.run_javascript.assert_called_once_with('Display.show();')
mocked_registry_execute.assert_called_once_with('live_display_active')
@patch('openlp.core.display.window.ScreenList') @patch('openlp.core.display.window.ScreenList')