From 46cf6c763c799c321f7835ea9774ecd7ab89e3f1 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 12 Aug 2009 05:57:24 +0100 Subject: [PATCH] Clean up event structure and add calling names Clean up Remote client to remove qt dependancy --- openlp/core/lib/event.py | 2 +- openlp/core/lib/eventmanager.py | 7 +++++-- openlp/core/lib/plugin.py | 3 +++ openlp/core/ui/maindisplay.py | 5 +++++ openlp/core/ui/servicemanager.py | 2 +- openlp/core/ui/thememanager.py | 2 +- openlp/plugins/bibles/bibleplugin.py | 2 +- openlp/plugins/custom/customplugin.py | 2 +- openlp/plugins/remotes/remoteclient-cli.py | 14 ++++++++------ openlp/plugins/remotes/remoteplugin.py | 4 ++-- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/songsplugin.py | 2 +- 12 files changed, 30 insertions(+), 17 deletions(-) diff --git a/openlp/core/lib/event.py b/openlp/core/lib/event.py index d6801654f..adb2fc527 100644 --- a/openlp/core/lib/event.py +++ b/openlp/core/lib/event.py @@ -45,7 +45,7 @@ class Event(object): """ Provides an Event class to encapsulate events within openlp.org. """ - def __init__(self, event_type=EventType.Default, payload=None, sender=None): + def __init__(self, event_type, sender, payload=None): self.event_type = event_type self.payload = payload self.sender = sender diff --git a/openlp/core/lib/eventmanager.py b/openlp/core/lib/eventmanager.py index 0cd12862b..15edf02d8 100644 --- a/openlp/core/lib/eventmanager.py +++ b/openlp/core/lib/eventmanager.py @@ -57,13 +57,16 @@ class EventManager(object): The event type to be triggered """ - log.debug(u'post event called for event %s', event.event_type) + log.debug(u'post event called for event %s (%s)', event.event_type, event.sender) 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) + status = point.handle_event(pEvent) + #if call returns true message is finished with + if status is not None and status : + break self.events.remove(pEvent) self.processing = False diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 4eeec4123..e9b402085 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -191,11 +191,14 @@ class Plugin(object): if event.event_type == EventType.LoadServiceItem and event.payload == self.dnd_id: log.debug(u'Load Service Item received') self.media_item.onAddClick() + return True if event.event_type == EventType.PreviewShow and event.payload == self.dnd_id: log.debug(u'Load Preview Item received') self.media_item.onPreviewClick() + return True if event.event_type == EventType.LiveShow and event.payload == self.dnd_id: log.debug(u'Load Live Show Item received') + return True self.media_item.onLiveClick() def about(self): diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 0476d0d97..78f0caa2b 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -62,9 +62,14 @@ class MainDisplay(QtGui.QWidget): self.parent.EventManager.register(self) def handle_event(self, event): + """ + Accept Events for the system and If It's for Alert + action it and Return true to stop futher processing + """ 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) + return True def setup(self, screenNumber): """ diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 9f8f03959..75421e4ad 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -488,7 +488,7 @@ class ServiceManager(QtGui.QWidget): link = event.mimeData() if link.hasText(): plugin = event.mimeData().text() - self.parent.EventManager.post_event(Event(EventType.LoadServiceItem, plugin)) + self.parent.EventManager.post_event(Event(EventType.LoadServiceItem, u'ServiceManager', plugin)) def updateThemeList(self, theme_list): """ diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 5b7e669c4..4d7312b38 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -184,7 +184,7 @@ class ThemeManager(QtGui.QWidget): self.pushThemes() def pushThemes(self): - self.parent.EventManager.post_event(Event(EventType.ThemeListChanged)) + self.parent.EventManager.post_event(Event(EventType.ThemeListChanged,u'ThemeManager')) def getThemes(self): return self.themelist diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 4dd42b9e9..7c7591a42 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -82,4 +82,4 @@ class BiblePlugin(Plugin): if event.event_type == EventType.ThemeListChanged: log.debug(u'New Theme request received') self.bibles_tab.updateThemeList(self.theme_manager.getThemes()) - Plugin.handle_event(self, event) + return Plugin.handle_event(self, event) diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 2efa30f1e..209ef69bc 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -58,4 +58,4 @@ class CustomPlugin(Plugin): if event.event_type == EventType.ThemeListChanged: log.debug(u'New Theme request received') self.edit_custom_form.loadThemes(self.theme_manager.getThemes()) - Plugin.handle_event(self, event) + return Plugin.handle_event(self, event) diff --git a/openlp/plugins/remotes/remoteclient-cli.py b/openlp/plugins/remotes/remoteclient-cli.py index ff4999b59..a21687d60 100755 --- a/openlp/plugins/remotes/remoteclient-cli.py +++ b/openlp/plugins/remotes/remoteclient-cli.py @@ -20,21 +20,23 @@ Place, Suite 330, Boston, MA 02111-1307 USA """ import sys import logging -from PyQt4 import QtNetwork, QtGui, QtCore +import socket logging.basicConfig(level=logging.DEBUG, format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s', - datefmt=u'%m-%d %H:%M:%S', filename=u'openlp-cli.log', filemode=u'w') + datefmt=u'%m-%d %H:%M:%S', filename=u'remoteclient-cli.log', filemode=u'w') class OpenLPRemoteCli(): global log log = logging.getLogger(u'OpenLP Remote Application') - log.info(u'Application Loaded') def __init__(self, argv): log.debug(u'Initialising') + host = u'localhost' + port = 4316 + self.addr = (host, port) try: - self.tcpsocket = QtNetwork.QUdpSocket() + self.UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) self.sendData() except: log.error(u'Errow thrown %s', sys.exc_info()[1]) @@ -42,8 +44,8 @@ class OpenLPRemoteCli(): def sendData(self): text = "Alert:Wave to Zak, Superfly" - print self.tcpsocket - print self.tcpsocket.writeDatagram(text, QtNetwork.QHostAddress(QtNetwork.QHostAddress.Broadcast), 4316) + print self.UDPSock + print self.UDPSock.sendto(text, self.addr) def run(self): pass diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index b0d546488..bd062ca71 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -47,9 +47,9 @@ class RemotesPlugin(Plugin): def handle_datagram(self, datagram): pos = datagram.find(u':') event = unicode(datagram[:pos]) - payyload = unicode(datagram[pos + 1:]) + payload = unicode(datagram[pos + 1:]) if event == u'Alert': - self.event_manager.post_event(Event(EventType.TriggerAlert, payyload)) + self.event_manager.post_event(Event(EventType.TriggerAlert, u'RemotePlugin', payload)) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 0c4a1d6b2..8d5176f9e 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -356,7 +356,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.processTitle() self.songmanager.save_song(self.song) if self.title_change: - self.eventmanager.post_event(Event(EventType.LoadSongList)) + self.eventmanager.post_event(Event(EventType.LoadSongList), u'EditSongForm') self.close() def processLyrics(self): diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index b79fce223..06bed8290 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -140,4 +140,4 @@ class SongsPlugin(Plugin): if event.event_type == EventType.LoadSongList : log.debug(u'Load Load Song List Item received') self.media_item.displayResultsSong(self.songmanager.get_songs()) - Plugin.handle_event(self, event) + return Plugin.handle_event(self, event)