forked from openlp/openlp
Clean up exit code so plugins can be called
Clean up Alerts Tab so can be called from UI and Remote via events Start to get events to be called sequentially not nested Fix up merge issues
This commit is contained in:
parent
6fa6b78e35
commit
161973eef6
@ -39,12 +39,14 @@ class EventManager(object):
|
||||
"""
|
||||
self.endpoints = []
|
||||
log.info(u'Initialising')
|
||||
self.processing = False
|
||||
self.events = []
|
||||
|
||||
def register(self, plugin):
|
||||
"""
|
||||
Called by plugings who wish to receive event notifications
|
||||
"""
|
||||
log.debug(u'plugin %s registered with EventManager', plugin)
|
||||
log.debug(u'Class %s registered with EventManager', plugin)
|
||||
self.endpoints.append(plugin)
|
||||
|
||||
def post_event(self, event):
|
||||
@ -56,5 +58,12 @@ class EventManager(object):
|
||||
|
||||
"""
|
||||
log.debug(u'post event called for event %s', event.event_type)
|
||||
for point in self.endpoints:
|
||||
point.handle_event(event)
|
||||
self.events.append(event)
|
||||
if not self.processing:
|
||||
self.processing = True
|
||||
while len(self.events) > 0:
|
||||
pEvent = self.events[0]
|
||||
for point in self.endpoints:
|
||||
point.handle_event(pEvent)
|
||||
self.events.remove(pEvent)
|
||||
self.processing = False
|
||||
|
@ -243,7 +243,7 @@ class Plugin(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
def shutdown(self):
|
||||
def finalise(self):
|
||||
"""
|
||||
Called by the plugin Manager to cleanup things
|
||||
"""
|
||||
|
@ -174,10 +174,10 @@ class PluginManager(object):
|
||||
for plugin in self.plugins:
|
||||
plugin.initialise()
|
||||
|
||||
def cleanup_plugins(self):
|
||||
def finalise_plugins(self):
|
||||
"""
|
||||
Loop through all the plugins and give them an opportunity to
|
||||
clean themselves up
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
plugin.cleanup()
|
||||
plugin.finalise()
|
||||
|
@ -93,11 +93,5 @@ class AlertForm(QtGui.QDialog):
|
||||
self.DisplayButton.setText(translate(u'AlertForm', u'Display'))
|
||||
self.CancelButton.setText(translate(u'AlertForm', u'Cancel'))
|
||||
|
||||
def load_settings(self):
|
||||
pass
|
||||
|
||||
def save_settings(self):
|
||||
pass
|
||||
|
||||
def onDisplayClicked(self):
|
||||
self.parent.mainDisplay.alert(self.parent.settingsForm.AlertsTab, self.AlertEntryEditItem.text())
|
||||
self.parent.mainDisplay.displayAlert(self.AlertEntryEditItem.text())
|
||||
|
@ -17,16 +17,19 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
import logging
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from time import sleep
|
||||
from openlp.core.lib import translate
|
||||
from openlp.core.lib import translate, EventManager, Event, EventType
|
||||
|
||||
class MainDisplay(QtGui.QWidget):
|
||||
"""
|
||||
This is the form that is used to display things on the projector.
|
||||
"""
|
||||
global log
|
||||
log=logging.getLogger(u'MainDisplay')
|
||||
log.info(u'MainDisplay Loaded')
|
||||
|
||||
def __init__(self, parent, screens):
|
||||
"""
|
||||
@ -38,7 +41,9 @@ class MainDisplay(QtGui.QWidget):
|
||||
``screens``
|
||||
The list of screens.
|
||||
"""
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
log.debug(u'Initilisation started')
|
||||
QtGui.QWidget.__init__(self, None)
|
||||
self.parent = parent
|
||||
self.setWindowTitle(u'OpenLP Display')
|
||||
self.screens = screens
|
||||
self.layout = QtGui.QVBoxLayout(self)
|
||||
@ -51,9 +56,15 @@ class MainDisplay(QtGui.QWidget):
|
||||
self.displayBlank = False
|
||||
self.blankFrame = None
|
||||
self.alertactive = False
|
||||
self.alerttext = u''
|
||||
self.alertTab = None
|
||||
self.timer_id = 0
|
||||
# Register the main form as an event consumer.
|
||||
self.parent.EventManager.register(self)
|
||||
|
||||
def handle_event(self, event):
|
||||
log.debug(u'MainDisplay received event %s with payload %s'%(event.event_type, event.payload))
|
||||
if event.event_type == EventType.TriggerAlert:
|
||||
self.displayAlert(event.payload)
|
||||
|
||||
def setup(self, screenNumber):
|
||||
"""
|
||||
@ -116,42 +127,35 @@ class MainDisplay(QtGui.QWidget):
|
||||
self.displayBlank = False
|
||||
self.frameView(self.frame)
|
||||
|
||||
def alert(self, alertTab, text):
|
||||
def displayAlert(self, text=u''):
|
||||
"""
|
||||
Called from the Alert Tab to display an alert
|
||||
``alertTab``
|
||||
details from AlertTab
|
||||
|
||||
``text``
|
||||
display text
|
||||
"""
|
||||
self.alerttext = text
|
||||
self.alertTab = alertTab
|
||||
if len(text) > 0:
|
||||
self.displayAlert()
|
||||
|
||||
def displayAlert(self):
|
||||
alertTab = self.parent.settingsForm.AlertsTab
|
||||
alertframe = QtGui.QPixmap.fromImage(self.frame)
|
||||
painter = QtGui.QPainter(alertframe)
|
||||
top = alertframe.rect().height() * 0.9
|
||||
painter.fillRect(
|
||||
QtCore.QRect(0, top, alertframe.rect().width(), alertframe.rect().height() - top),
|
||||
QtGui.QColor(self.alertTab.bg_color))
|
||||
QtGui.QColor(alertTab.bg_color))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily(self.alertTab.font_face)
|
||||
font.setFamily(alertTab.font_face)
|
||||
font.setBold(True)
|
||||
font.setPointSize(40)
|
||||
painter.setFont(font)
|
||||
painter.setPen(QtGui.QColor(self.alertTab.font_color))
|
||||
painter.setPen(QtGui.QColor(alertTab.font_color))
|
||||
x, y = (0, top)
|
||||
metrics = QtGui.QFontMetrics(font)
|
||||
painter.drawText(
|
||||
x, y + metrics.height() - metrics.descent() - 1, self.alerttext)
|
||||
x, y + metrics.height() - metrics.descent() - 1, text)
|
||||
painter.end()
|
||||
self.display.setPixmap(alertframe)
|
||||
# check to see if we have a timer running
|
||||
if self.timer_id == 0:
|
||||
self.timer_id = self.startTimer(int(self.alertTab.timeout) * 1000)
|
||||
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
|
||||
|
||||
def timerEvent(self, event):
|
||||
if event.timerId() == self.timer_id:
|
||||
|
@ -404,8 +404,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.screenList = screens
|
||||
self.oosNotSaved = False
|
||||
self.settingsmanager = SettingsManager(screens)
|
||||
self.mainDisplay = MainDisplay(None, screens)
|
||||
self.EventManager = EventManager()
|
||||
self.mainDisplay = MainDisplay(self, screens)
|
||||
self.generalConfig = PluginConfig(u'General')
|
||||
self.alertForm = AlertForm(self)
|
||||
self.aboutForm = AboutForm()
|
||||
@ -476,11 +476,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
# Call the initialise method to setup plugins.
|
||||
log.info(u'initialise plugins')
|
||||
self.plugin_manager.initialise_plugins()
|
||||
# Register the main form as an event consumer.
|
||||
self.EventManager.register(self)
|
||||
# Once all components are initialised load the Themes
|
||||
log.info(u'Load Themes')
|
||||
self.ThemeManagerContents.loadThemes()
|
||||
# Register the main form as an event consumer.
|
||||
self.EventManager.register(self)
|
||||
|
||||
def getMonitorNumber(self):
|
||||
"""
|
||||
@ -552,7 +552,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
def cleanUp(self):
|
||||
# Call the cleanup method to shutdown plugins.
|
||||
log.info(u'cleanup plugins')
|
||||
self.plugin_manager.initialise_plugins()
|
||||
self.plugin_manager.finalise_plugins()
|
||||
|
||||
def OosChanged(self, reset=False, oosName=None):
|
||||
"""
|
||||
|
@ -65,7 +65,7 @@ class SlideController(QtGui.QWidget):
|
||||
"""
|
||||
self.toolbarList = {}
|
||||
self.previewList = {}
|
||||
QtGui.QWidget.__init__(self, parent.mainWindow)
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.isLive = isLive
|
||||
self.parent = parent
|
||||
self.Panel = QtGui.QWidget(parent.ControlSplitter)
|
||||
|
@ -46,8 +46,8 @@ class RemotesPlugin(Plugin):
|
||||
|
||||
def handle_datagram(self, datagram):
|
||||
pos = datagram.find(u':')
|
||||
event = datagram[:pos]
|
||||
payyload = datagram[pos + 1:]
|
||||
event = unicode(datagram[:pos])
|
||||
payyload = unicode(datagram[pos + 1:])
|
||||
if event == u'Alert':
|
||||
self.event_manager.post_event(Event(EventType.TriggerAlert, payyload))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user