EventManager Removal - complete

This commit is contained in:
Tim Bentley 2009-08-26 06:00:19 +01:00
parent 49a424abd1
commit 63f67ea756
17 changed files with 30 additions and 241 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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():

View File

@ -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.

View File

@ -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.

View File

@ -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 ,

View File

@ -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):
"""

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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')

View File

@ -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):

View File

@ -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,

View File

@ -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)