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