From 63f67ea7562613e88afeda7489d57a22e4d8dc56 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 26 Aug 2009 06:00:19 +0100 Subject: [PATCH] EventManager Removal - complete --- openlp/core/lib/__init__.py | 3 - openlp/core/lib/event.py | 52 ---------------- openlp/core/lib/eventmanager.py | 72 ---------------------- openlp/core/lib/eventreceiver.py | 3 +- openlp/core/lib/plugin.py | 60 +----------------- openlp/core/lib/pluginmanager.py | 8 +-- openlp/core/ui/amendthemeform.py | 2 - openlp/core/ui/maindisplay.py | 16 +---- openlp/core/ui/mainwindow.py | 11 +--- openlp/core/ui/thememanager.py | 5 +- openlp/plugins/bibles/bibleplugin.py | 2 +- openlp/plugins/custom/customplugin.py | 2 +- openlp/plugins/images/imageplugin.py | 2 +- openlp/plugins/remotes/remoteplugin.py | 4 +- openlp/plugins/songs/forms/editsongform.py | 9 ++- openlp/plugins/songs/lib/mediaitem.py | 8 ++- openlp/plugins/songs/songsplugin.py | 12 +--- 17 files changed, 30 insertions(+), 241 deletions(-) delete mode 100644 openlp/core/lib/event.py delete mode 100644 openlp/core/lib/eventmanager.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index c940bd649..be1848fed 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -60,12 +60,9 @@ def contextMenuSeparator(base): from settingsmanager import SettingsManager from pluginconfig import PluginConfig from plugin import Plugin -from eventmanager import EventManager from pluginmanager import PluginManager from settingstab import SettingsTab from mediamanageritem import MediaManagerItem -from event import Event -from event import EventType from xmlrootclass import XmlRootClass from serviceitem import ServiceItem from eventreceiver import Receiver diff --git a/openlp/core/lib/event.py b/openlp/core/lib/event.py deleted file mode 100644 index 8661ad4cf..000000000 --- a/openlp/core/lib/event.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 -""" -OpenLP - Open Source Lyrics Projection - -Copyright (c) 2008 Raoul Snyman - -Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Scott Guerreri, -Carsten Tingaard, Jonathan Corwin - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -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 -""" - -class EventType(object): - """ - Types of events are stored in this class. - """ - # "Default" event - a non-event - Default = 0 - #TriggerAlert = 1 - # General application events - # Ready = 10 - # Service events - #LoadServiceItem = 20 - # Preview events - #PreviewShow = 30 - #LiveShow = 31 - #Theme Related Events - #ThemeListChanged = 40 - #Plugin Related Events - #LoadSongList = 50 - - - -class Event(object): - """ - Provides an Event class to encapsulate events within openlp.org. - """ - def __init__(self, sender, event_type=EventType.Default, 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 deleted file mode 100644 index 15edf02d8..000000000 --- a/openlp/core/lib/eventmanager.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 -""" -OpenLP - Open Source Lyrics Projection - -Copyright (c) 2008 Raoul Snyman - -Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Scott Guerreri, -Carsten Tingaard, Jonathan Corwin - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -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 os -import logging - -class EventManager(object): - """ - A mechanism to send events to all registered endpoints. The - endpoints are registered and listen with a handle_event method. - The endpoint will decide whether to do somthing with the event or - ignore it. - """ - global log - log = logging.getLogger(u'EventManager') - - def __init__(self): - """ - Defines the class and a list of endpoints - """ - 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'Class %s registered with EventManager', plugin) - self.endpoints.append(plugin) - - def post_event(self, event): - """ - Called by any part of the system which wants send events to the plugins - - ``event`` - The event type to be triggered - - """ - 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: - 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/eventreceiver.py b/openlp/core/lib/eventreceiver.py index 5c038a4ff..7d7a4c2fe 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -47,6 +47,8 @@ class EventReceiver(QtCore.QObject): send out message with new themes ``update_global_theme `` Tell the components we have a new global theme + ``load_song_list`` + Tells the the song plugin to reload the song list """ global log @@ -57,7 +59,6 @@ class EventReceiver(QtCore.QObject): def send_message(self, event, msg=None): log.debug(u'Event %s passed with payload %s' % (event, msg)) - print u'message ', event, msg self.emit(QtCore.SIGNAL(event), msg) class Receiver(): diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 11e6092b0..5f009c014 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -25,7 +25,6 @@ from openlp.core.lib import PluginConfig # why does this not work??? # from openlp.core.lib import Event, EventType # so I have to do this??? -from event import Event, EventType from eventreceiver import Receiver class Plugin(object): @@ -124,7 +123,6 @@ class Plugin(object): self.log = logging.getLogger(self.name) self.preview_controller = plugin_helpers[u'preview'] self.live_controller = plugin_helpers[u'live'] - self.event_manager = plugin_helpers[u'event'] self.render_manager = plugin_helpers[u'render'] self.service_manager = plugin_helpers[u'service'] self.settings = plugin_helpers[u'settings'] @@ -185,32 +183,8 @@ class Plugin(object): Proxy method as method is not defined early enough in the processing """ - log.debug(u'Handle event called with plugin %s' % self.name) + log.debug(u'process_add_service_event event called for plugin %s' % self.name) self.media_item.onAddClick() - def handle_event(self, event): -# """ -# Handle the event contained in the event object. If you want -# to use this default behaviour, you must set self.dnd_id equal -# to that sent by the dnd source - eg the MediaItem -# -# ``event`` -# An object describing the event. -# """ -# # default behaviour - can be overridden if desired - pass -# log.debug(u'Handle event called with event %s with payload %s'%(event.event_type, event.payload)) -# 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): """ @@ -219,38 +193,6 @@ class Plugin(object): """ pass -# def save(self, data): -# """ -# Service item data is passed to this function, which should return a -# string which can be written to the service file. -# -# ``data`` -# The data to be saved. -# """ -# pass -# -# def load(self, string): -# """ -# A string from the service file is passed in. This function parses and -# sets up the internals of the plugin. -# -# ``string`` -# The data to be loaded into the plugin. -# """ -# pass -# -# def render(self, theme, screen=None): -# """ -# Render the screenth screenful of data using theme settings in theme. -# -# ``theme`` -# The theme to use when rendering. -# -# ``screen`` -# Defaults to *None*. The screen to render to. -# """ -# pass - def initialise(self): """ Called by the plugin Manager to initialise anything it needs. diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 8e1b519ea..484d74f97 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -21,7 +21,7 @@ import os import sys import logging -from openlp.core.lib import Plugin, EventManager +from openlp.core.lib import Plugin class PluginManager(object): """ @@ -50,7 +50,7 @@ class PluginManager(object): # this has to happen after the UI is sorted self.find_plugins(dir) log.info(u'Plugin manager done init') - def find_plugins(self, dir, plugin_helpers, eventmanager): + def find_plugins(self, dir, plugin_helpers): """ Scan the directory dir for objects inheriting from ``openlp.plugin``. @@ -60,8 +60,6 @@ class PluginManager(object): ``plugin_helpers`` A list of helper objects to pass to the plugins. - ``eventmanager`` - The event manager to pass to the plugins. """ self.plugin_helpers = plugin_helpers startdepth = len(os.path.abspath(dir).split(os.sep)) @@ -103,11 +101,9 @@ class PluginManager(object): pList = {u'plugin': plugin, u'status': u'Inactive'} if plugin.check_pre_conditions(): log.debug(u'Plugin %s active', unicode(plugin.name)) - eventmanager.register(plugin) pList[u'status'] = u'Active' self.plugins.append(pList) - def order_by_weight(self, x, y): """ Sort two plugins and order them by their weight. diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index ef6f8368f..3b76e1c89 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -32,11 +32,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): def __init__(self, thememanager, parent=None): QtGui.QDialog.__init__(self, parent) self.thememanager = thememanager - # Needed here as UI setup generates Events self.path = None self.theme = ThemeXML() self.setupUi(self) - #define signals #Buttons QtCore.QObject.connect(self.Color1PushButton , diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index bf5cfaa77..56db736ae 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -21,7 +21,7 @@ import logging from PyQt4 import QtCore, QtGui from time import sleep -from openlp.core.lib import translate, EventManager, Event, EventType, Receiver +from openlp.core.lib import translate, Receiver class MainDisplay(QtGui.QWidget): """ @@ -58,20 +58,10 @@ class MainDisplay(QtGui.QWidget): self.alertactive = False self.alertTab = None self.timer_id = 0 - # Register the main form as an event consumer. - self.parent.EventManager.register(self) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_slide_blank'), self.blankDisplay) - - 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 + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'alert_text'), self.displayAlert) def setup(self, screenNumber): """ diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 7df147328..bf8d232e4 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -26,8 +26,8 @@ from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \ ServiceManager, ThemeManager, MainDisplay, SlideController, \ PluginForm from openlp.core.lib import translate, Plugin, MediaManagerItem, \ - SettingsTab, EventManager, RenderManager, PluginConfig, \ - SettingsManager, PluginManager, EventType, Receiver + SettingsTab, RenderManager, PluginConfig, \ + SettingsManager, PluginManager, Receiver class Ui_MainWindow(object): def setupUi(self, MainWindow): @@ -416,7 +416,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.screenList = screens self.oosNotSaved = False self.settingsmanager = SettingsManager(screens) - self.EventManager = EventManager() self.mainDisplay = MainDisplay(self, screens) self.generalConfig = PluginConfig(u'General') self.alertForm = AlertForm(self) @@ -469,12 +468,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): #make the controllers available to the plugins self.plugin_helpers[u'preview'] = self.PreviewController self.plugin_helpers[u'live'] = self.LiveController - self.plugin_helpers[u'event'] = self.EventManager self.plugin_helpers[u'render'] = self.RenderManager self.plugin_helpers[u'service'] = self.ServiceManagerContents self.plugin_helpers[u'settings'] = self.settingsForm - self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers, - self.EventManager) + self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers) # hook methods have to happen after find_plugins. Find plugins needs the # controllers hence the hooks have moved from setupUI() to here @@ -492,8 +489,6 @@ 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() diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 1ee7f8777..a1e346fbc 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -28,8 +28,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.ui import AmendThemeForm, ServiceManager from openlp.core.theme import Theme -from openlp.core.lib import PluginConfig, Event, EventType, \ - EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, \ +from openlp.core.lib import PluginConfig, \ + OpenLPToolbar, ThemeXML, Renderer, translate, \ file_to_xml, buildIcon, Receiver from openlp.core.utils import ConfigHelper @@ -116,6 +116,7 @@ class ThemeManager(QtGui.QWidget): name = u'%s (%s)' % (self.global_theme, translate(u'ThemeManager', u'default')) self.ThemeListWidget.item(count).setText(name) self.config.set_config(u'theme global theme', self.global_theme) + Receiver().send_message(u'update_global_theme', self.global_theme ) self.pushThemes() def onAddTheme(self): diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index b3ba5c94b..84c6c3c31 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -22,7 +22,7 @@ import logging from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * -from openlp.core.lib import Plugin, Event, EventType, translate +from openlp.core.lib import Plugin, translate from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 368bcbf07..fd1cb43e1 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -22,7 +22,7 @@ import logging from PyQt4 import QtCore, QtGui from forms import EditCustomForm -from openlp.core.lib import Plugin, Event, EventType +from openlp.core.lib import Plugin from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 48471f826..0995413ad 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -21,7 +21,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, Event, EventType +from openlp.core.lib import Plugin from openlp.plugins.images.lib import ImageMediaItem, ImageTab class ImagePlugin(Plugin): diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 601deec66..bf6d1bf43 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -22,7 +22,7 @@ import sys from PyQt4 import QtNetwork, QtGui, QtCore -from openlp.core.lib import Plugin, Event, EventType, Receiver +from openlp.core.lib import Plugin, Receiver from openlp.plugins.remotes.lib import RemoteTab class RemotesPlugin(Plugin): @@ -58,7 +58,7 @@ class RemotesPlugin(Plugin): event = unicode(datagram[:pos].lower()) if event == u'alert': - self.event_manager.post_event(Event(u'RemotePlugin', EventType.TriggerAlert , unicode(datagram[pos + 1:]))) + Receiver().send_message(u'alert_text', unicode(datagram[pos + 1:])) if event == u'next_slide': Receiver().send_message(u'live_slide_next') diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 52f91b1e1..cafad139c 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -22,8 +22,8 @@ import logging from PyQt4 import Qt, QtCore, QtGui -from openlp.core.lib import SongXMLBuilder, SongXMLParser, Event, \ - EventType, EventManager, translate, Receiver +from openlp.core.lib import SongXMLBuilder, SongXMLParser, \ + translate, Receiver from openlp.plugins.songs.forms import EditVerseForm from openlp.plugins.songs.lib.models import Song from editsongdialog import Ui_EditSongDialog @@ -36,7 +36,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): log = logging.getLogger(u'EditSongForm') log.info(u'Song Editor loaded') - def __init__(self, songmanager, eventmanager, parent=None): + def __init__(self, songmanager, parent=None): """ Constructor """ @@ -75,7 +75,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtCore.SIGNAL(u'update_themes'), self.loadThemes) # Create other objects and forms self.songmanager = songmanager - self.eventmanager = eventmanager self.parent = parent self.verse_form = EditVerseForm() self.initialise() @@ -366,7 +365,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.processTitle() self.songmanager.save_song(self.song) if self.title_change: - self.eventmanager.post_event(Event(u'EditSongForm', EventType.LoadSongList)) + Receiver().send_message(u'load_song_list') self.close() def processLyrics(self): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 6e19b3961..e28a4ffac 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -22,7 +22,8 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, translate, ServiceItem, \ - SongXMLParser, contextMenuAction, contextMenuSeparator, BaseListWithDnD + SongXMLParser, contextMenuAction, contextMenuSeparator, BaseListWithDnD, \ + Receiver from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm class SongListView(BaseListWithDnD): @@ -43,7 +44,7 @@ class SongMediaItem(MediaManagerItem): self.PluginTextShort = u'Song' self.ConfigSection = u'song' MediaManagerItem.__init__(self, parent, icon, title) - self.edit_song_form = EditSongForm(self.parent.songmanager, self.parent.event_manager, self) + self.edit_song_form = EditSongForm(self.parent.songmanager, self) self.song_maintenance_form = SongMaintenanceForm(self.parent.songmanager, self) def setupUi(self): @@ -127,6 +128,9 @@ class SongMediaItem(MediaManagerItem): QtCore.SIGNAL(u'textChanged(const QString&)'), self.onSearchTextEditChanged) QtCore.QObject.connect(self.ListView, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onSongPreviewClick) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'load_song_list'), self.onSearchTextButtonClick) + #define and add the context menu self.ListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.ListView.addAction(contextMenuAction(self.ListView, diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 4413798db..598e32d06 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -22,7 +22,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, Event, EventType, translate +from openlp.core.lib import Plugin, translate from openlp.plugins.songs.lib import SongManager, SongsTab, SongMediaItem from openlp.plugins.songs.forms import OpenLPImportForm, OpenSongExportForm, \ OpenSongImportForm, OpenLPExportForm @@ -126,13 +126,3 @@ class SongsPlugin(Plugin): def onExportOpenSongItemClicked(self): self.opensong_export_form.show() - - def handle_event(self, event): - """ - Handle the event contained in the event object. - """ - log.debug(u'Handle event called with event %s' % event.event_type) - if event.event_type == EventType.LoadSongList : - log.debug(u'Load Load Song List Item received') - self.media_item.displayResultsSong(self.songmanager.get_songs()) - return Plugin.handle_event(self, event)