EventManager Removal part 1

This commit is contained in:
Tim Bentley 2009-08-24 21:05:46 +01:00
parent 8b1425d163
commit 7226d4a232
9 changed files with 106 additions and 74 deletions

View File

@ -25,11 +25,36 @@ class EventReceiver(QtCore.QObject):
"""
Class to allow events to be passed from different parts of the system.
This is a private class and should not be used directly but via the Receiver class
``stop_import``
Stops the Bible Import
``pre_load_bibles``
Triggers the plugin to relaod the bible lists
``process_events``
Requests the Application to flush the events queue
``{preview|live}_slide_first``
display the first slide on the list
``{preview|live}_slide_previous``
display the previous slide on the list
``{preview|live}_slide_next``
display the next slide on the list
``{preview|live}_slide_last``
display the last slide on the list
``{plugin}_add_service_item ``
ask the plugin to push the selected items to the service item
``update_themes ``
send out message with new themes
``update_global_theme ``
Tell the components we have a new global theme
"""
def __init__(self):
QtCore.QObject.__init__(self)
def send_message(self, event, msg=None):
print u'message ', event, msg
self.emit(QtCore.SIGNAL(event), msg)
class Receiver():
@ -39,11 +64,11 @@ class Receiver():
As there is only one instance of it in the systems the QT signal/slot architecture
can send messages across the system
Send message
Receiver().send_message(u'messageid',data)
``Send message``
Receiver().send_message(u'<<Message ID>>', data)
Receive Message
QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlprepaint'),<<ACTION>>)
``Receive Message``
QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'<<Message ID>>'),<<ACTION>>)
"""
eventreceiver = EventReceiver()

View File

@ -19,12 +19,14 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
from PyQt4 import QtCore
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):
"""
@ -126,7 +128,8 @@ class Plugin(object):
self.render_manager = plugin_helpers[u'render']
self.service_manager = plugin_helpers[u'service']
self.settings = plugin_helpers[u'settings']
self.dnd_id=None
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'%s_add_service_item'% self.name), self.process_add_service_event)
def check_pre_conditions(self):
"""
@ -177,29 +180,37 @@ class Plugin(object):
"""
pass
def handle_event(self, event):
def process_add_service_event(self):
"""
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.
Proxy method as method is not defined early enough
in the processing
"""
# default behaviour - can be overridden if desired
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')
log.debug(u'Handle event called with plugin %s' % self.name)
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 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):
"""
@ -208,37 +219,37 @@ 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 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):
"""

View File

@ -24,9 +24,9 @@ import zipfile
import shutil
from PyQt4 import QtCore, QtGui
from openlp.core.lib import PluginConfig, OpenLPToolbar, ServiceItem, Event, \
RenderManager, EventType, EventManager, translate, buildIcon, \
contextMenuAction, contextMenuSeparator
from openlp.core.lib import PluginConfig, OpenLPToolbar, ServiceItem, \
RenderManager, translate, buildIcon, \
contextMenuAction, contextMenuSeparator, Receiver
from openlp.core.utils import ConfigHelper
class ServiceManagerList(QtGui.QTreeWidget):
@ -66,6 +66,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
class Iter(QtGui.QTreeWidgetItemIterator):
def __init__(self, *args):
QtGui.QTreeWidgetItemIterator.__init__(self, *args)
def next(self):
self.__iadd__(1)
value = self.value()
@ -488,7 +489,7 @@ class ServiceManager(QtGui.QWidget):
link = event.mimeData()
if link.hasText():
plugin = event.mimeData().text()
self.parent.EventManager.post_event(Event(u'ServiceManager', EventType.LoadServiceItem, plugin))
Receiver().send_message(u'%s_add_service_item' % plugin)
def updateThemeList(self, theme_list):
"""

View File

@ -30,7 +30,7 @@ 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, \
file_to_xml, buildIcon
file_to_xml, buildIcon, Receiver
from openlp.core.utils import ConfigHelper
class ThemeManager(QtGui.QWidget):
@ -184,7 +184,8 @@ class ThemeManager(QtGui.QWidget):
self.pushThemes()
def pushThemes(self):
self.parent.EventManager.post_event(Event(u'ThemeManager', EventType.ThemeListChanged, self.getThemes()))
#self.parent.EventManager.post_event(Event(u'ThemeManager', EventType.ThemeListChanged, self.getThemes()))
Receiver().send_message(u'update_themes', self.getThemes() )
def getThemes(self):
return self.themelist

View File

@ -41,9 +41,6 @@ class BiblePlugin(Plugin):
QtGui.QIcon.Normal, QtGui.QIcon.Off)
#Register the bible Manager
self.biblemanager = BibleManager(self.config)
# passed with drag and drop messages
self.dnd_id = u'Bibles'
def get_settings_tab(self):
self.bibles_tab = BiblesTab()

View File

@ -152,9 +152,9 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
def onCancelButtonClicked(self):
# tell import to stop
self.message = u'Bible import stopped'
Receiver().send_message(u'openlpstopimport')
Receiver().send_message(u'stop_import')
# tell bibleplugin to reload the bibles
Receiver().send_message(u'openlpreloadbibles')
Receiver().send_message(u'pre_load_bibles')
self.close()
def onImportButtonClicked(self):
@ -172,7 +172,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.MessageLabel.setText(message)
self.ProgressBar.setValue(self.barmax)
# tell bibleplugin to reload the bibles
Receiver().send_message(u'openlpreloadbibles')
Receiver().send_message(u'pre_load_bibles')
reply = QtGui.QMessageBox.information(self,
translate(u'BibleMediaItem', u'Information'),
translate(u'BibleMediaItem', message))

View File

@ -41,7 +41,6 @@ class PresentationPlugin(Plugin):
self.icon = QtGui.QIcon()
self.icon.addPixmap(QtGui.QPixmap(u':/media/media_presentation.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.dnd_id = u'Presentations'
def get_settings_tab(self):
"""

View File

@ -27,7 +27,7 @@ from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm
class SongListView(BaseListWithDnD):
def __init__(self, parent=None):
self.PluginName = u'Song'
self.PluginName = u'Songs'
BaseListWithDnD.__init__(self, parent)
class SongMediaItem(MediaManagerItem):

View File

@ -46,8 +46,6 @@ class SongsPlugin(Plugin):
self.icon = QtGui.QIcon()
self.icon.addPixmap(QtGui.QPixmap(u':/media/media_song.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
# passed with drag and drop messages
self.dnd_id=u'Song'
def get_media_manager_item(self):
# Create the MediaManagerItem object