forked from openlp/openlp
Clean up Plugin Interface to be more Generic
Clean up Mainwindow for adding plugins Add ThemeManager to Main window and pass to plugins Add event Manager code to plugins and define some listners Revert changes to Alert Form.
This commit is contained in:
parent
62f48a33f2
commit
66f13e5ede
@ -17,13 +17,12 @@ 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
|
||||
"""
|
||||
from event import EventType
|
||||
from event import Event
|
||||
from eventmanager import EventManager
|
||||
from pluginconfig import PluginConfig
|
||||
from plugin import Plugin
|
||||
from settingstab import SettingsTab
|
||||
from mediamanageritem import MediaManagerItem
|
||||
from event import Event
|
||||
from eventmanager import EventManager
|
||||
from xmlrootclass import XmlRootClass
|
||||
from serviceitem import ServiceItem
|
||||
from eventreceiver import Receiver
|
||||
@ -32,6 +31,6 @@ from toolbar import OpenLPToolbar
|
||||
from songxmlhandler import SongXMLBuilder
|
||||
from songxmlhandler import SongXMLParser
|
||||
|
||||
__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event','EventType',
|
||||
__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event',
|
||||
'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder',
|
||||
'SongXMLParser', 'EventManager']
|
||||
|
@ -40,17 +40,21 @@ class EventType(object):
|
||||
PreviewAfterLoad = 12
|
||||
PreviewBeforeShow = 13
|
||||
PreviewAfterShow = 14
|
||||
ThemeData = 15
|
||||
LoadThemeData = 16
|
||||
|
||||
|
||||
class Event(object):
|
||||
"""
|
||||
Provides an Event class to encapsulate events within openlp.org.
|
||||
"""
|
||||
def __init__(self, event_type=EventType.Default, payload=None):
|
||||
self.event_type = event_type
|
||||
def __init__(self, event_type=EventType.Default):
|
||||
self.type = event_type
|
||||
self.payload = None
|
||||
|
||||
def get_payload(self):
|
||||
return self.payload
|
||||
|
||||
def set_payload(self, payload):
|
||||
self.payload = payload
|
||||
|
||||
|
||||
def get_type(self):
|
||||
return self.event_type
|
||||
return self.type
|
||||
|
@ -33,7 +33,7 @@ class EventManager(object):
|
||||
|
||||
def __init__(self):
|
||||
self.endpoints=[]
|
||||
log.info(u'Initialising')
|
||||
log.info(u'Starting')
|
||||
|
||||
def register(self, plugin):
|
||||
log.debug(u'plugin %s registered with EventManager'%plugin)
|
||||
|
@ -88,10 +88,8 @@ class Plugin(object):
|
||||
self.weight = 0
|
||||
# Set up logging
|
||||
self.log = logging.getLogger(self.name)
|
||||
self.preview_controller = plugin_helpers[u'preview']
|
||||
self.live_controller = plugin_helpers[u'live']
|
||||
self.theme_manager = plugin_helpers[u'theme']
|
||||
self.event_manager = plugin_helpers[u'event']
|
||||
self.preview_controller=plugin_helpers[u'preview']
|
||||
self.live_controller=plugin_helpers[u'live']
|
||||
|
||||
def check_pre_conditions(self):
|
||||
"""
|
||||
|
@ -31,7 +31,7 @@ class PluginManager(object):
|
||||
"""
|
||||
global log
|
||||
log=logging.getLogger(u'PluginMgr')
|
||||
log.info(u'"Plugin manager loaded')
|
||||
log.info(u'Plugin manager loaded')
|
||||
|
||||
def __init__(self, dir):
|
||||
"""
|
||||
|
@ -23,22 +23,15 @@ from PyQt4.QtGui import QDialog
|
||||
|
||||
from openlp.core import translate
|
||||
from openlp.core.resources import *
|
||||
from openlp.core.ui import AlertsTab
|
||||
from openlp.core.lib import EventManager, Event
|
||||
|
||||
class AlertForm(QDialog):
|
||||
global log
|
||||
log=logging.getLogger(u'AlertForm')
|
||||
|
||||
def __init__(self, eventmanager, parent=None):
|
||||
def __init__(self, parent=None):
|
||||
QDialog.__init__(self, parent)
|
||||
self.alertsTab = AlertsTab()
|
||||
self.eventmanager = eventmanager
|
||||
self.setupUi(self)
|
||||
log.info(u'Defined')
|
||||
|
||||
def get_settings_tab(self):
|
||||
return self.alertsTab
|
||||
|
||||
def setupUi(self, AlertForm):
|
||||
AlertForm.setObjectName("AlertForm")
|
||||
@ -102,14 +95,6 @@ class AlertForm(QDialog):
|
||||
self.DisplayButton.setText(translate("AlertForm", u'Display'))
|
||||
self.CancelButton.setText(translate("AlertForm", u'Cancel'))
|
||||
|
||||
# def show(self):
|
||||
# self.AlertForm.show()
|
||||
|
||||
def handle_event(self, event):
|
||||
"""
|
||||
Handle the event contained in the event object.
|
||||
"""
|
||||
log.debug(u'Handle event called with event %s' %event.get_type())
|
||||
|
||||
def load_settings(self):
|
||||
pass
|
||||
@ -118,4 +103,4 @@ class AlertForm(QDialog):
|
||||
pass
|
||||
|
||||
def onDisplayClicked(self):
|
||||
self.eventmanager.post_event(Event())
|
||||
pass
|
||||
|
@ -28,7 +28,7 @@ from openlp.core.resources import *
|
||||
|
||||
from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \
|
||||
SlideController, ServiceManager, ThemeManager
|
||||
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, EventManager, Event, EventType
|
||||
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, EventManager
|
||||
|
||||
from openlp.core import PluginManager
|
||||
|
||||
@ -40,7 +40,7 @@ class MainWindow(object):
|
||||
def __init__(self):
|
||||
self.main_window = QtGui.QMainWindow()
|
||||
self.EventManager = EventManager()
|
||||
self.alert_form = AlertForm(self.EventManager)
|
||||
self.alert_form = AlertForm()
|
||||
self.about_form = AboutForm()
|
||||
self.settings_form = SettingsForm()
|
||||
|
||||
@ -51,10 +51,6 @@ class MainWindow(object):
|
||||
|
||||
self.setupUi()
|
||||
|
||||
# Add the core components which have settings tabs
|
||||
self.settings_form.addTab(self.ThemeManagerContents.get_settings_tab())
|
||||
self.settings_form.addTab(self.alert_form.get_settings_tab())
|
||||
|
||||
log.info(u'Load Plugins')
|
||||
self.plugin_helpers[u'preview'] = self.PreviewController
|
||||
self.plugin_helpers[u'live'] = self.LiveController
|
||||
@ -83,15 +79,6 @@ class MainWindow(object):
|
||||
# Call the initialise method to setup plugins.
|
||||
log.info(u'initialise plugins')
|
||||
self.plugin_manager.initialise_plugins()
|
||||
|
||||
# Register the different UI components with Event Manager
|
||||
self.EventManager.register(self.ServiceManagerContents)
|
||||
self.EventManager.register(self.ThemeManagerContents)
|
||||
self.EventManager.register(self.alert_form)
|
||||
|
||||
# Now all windows are defiened and initialised Update the theme data
|
||||
event = Event(EventType.LoadThemeData)
|
||||
self.EventManager.post_event(event)
|
||||
|
||||
def setupUi(self):
|
||||
self.main_window.setObjectName("main_window")
|
||||
@ -120,10 +107,8 @@ class MainWindow(object):
|
||||
self.ControlSplitter.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.ControlSplitter.setObjectName("ControlSplitter")
|
||||
self.MainContentLayout.addWidget(self.ControlSplitter)
|
||||
|
||||
self.PreviewController = SlideController(self.ControlSplitter)
|
||||
self.LiveController = SlideController(self.ControlSplitter)
|
||||
|
||||
self.MenuBar = QtGui.QMenuBar(self.main_window)
|
||||
self.MenuBar.setGeometry(QtCore.QRect(0, 0, 1087, 27))
|
||||
self.MenuBar.setObjectName("MenuBar")
|
||||
@ -180,7 +165,6 @@ class MainWindow(object):
|
||||
self.MediaManagerLayout.addWidget(self.MediaToolBox)
|
||||
self.MediaManagerDock.setWidget(self.MediaManagerContents)
|
||||
self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.MediaManagerDock)
|
||||
|
||||
#Sevice Manager Defined
|
||||
self.ServiceManagerDock = QtGui.QDockWidget(self.main_window)
|
||||
ServiceManagerIcon = QtGui.QIcon()
|
||||
@ -189,10 +173,9 @@ class MainWindow(object):
|
||||
self.ServiceManagerDock.setWindowIcon(ServiceManagerIcon)
|
||||
self.ServiceManagerDock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures)
|
||||
self.ServiceManagerDock.setObjectName("ServiceManagerDock")
|
||||
self.ServiceManagerContents = ServiceManager(self, self.EventManager)
|
||||
self.ServiceManagerContents = ServiceManager(self)
|
||||
self.ServiceManagerDock.setWidget(self.ServiceManagerContents)
|
||||
self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock)
|
||||
|
||||
#Theme Manager Defined
|
||||
self.ThemeManagerDock = QtGui.QDockWidget(self.main_window)
|
||||
ThemeManagerIcon = QtGui.QIcon()
|
||||
@ -202,7 +185,7 @@ class MainWindow(object):
|
||||
self.ThemeManagerDock.setFloating(False)
|
||||
self.ThemeManagerDock.setObjectName("ThemeManagerDock")
|
||||
|
||||
self.ThemeManagerContents = ThemeManager(self, self.EventManager)
|
||||
self.ThemeManagerContents = ThemeManager(self)
|
||||
|
||||
# self.ThemeManagerContents = QtGui.QWidget()
|
||||
# self.ThemeManagerContents.setObjectName("ThemeManagerContents")
|
||||
|
@ -29,7 +29,6 @@ from PyQt4.QtGui import *
|
||||
# from openlp.core.ui import AboutForm, AlertForm, SettingsForm, SlideController
|
||||
from openlp.core.lib import OpenLPToolbar
|
||||
from openlp.core.lib import ServiceItem
|
||||
from openlp.core.lib import Event, EventType
|
||||
|
||||
# from openlp.core import PluginManager
|
||||
import logging
|
||||
@ -42,30 +41,24 @@ class ServiceData(QAbstractItemModel):
|
||||
"""
|
||||
global log
|
||||
log=logging.getLogger(u'ServiceData')
|
||||
|
||||
def __init__(self):
|
||||
QAbstractItemModel.__init__(self)
|
||||
self.items=[]
|
||||
log.info(u'Starting')
|
||||
|
||||
log.info("Starting")
|
||||
def columnCount(self, parent):
|
||||
return 1; # always only a single column (for now)
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self.items)
|
||||
|
||||
def insertRow(self, row, service_item):
|
||||
# self.beginInsertRows(QModelIndex(),row,row)
|
||||
log.info("insert row %d:%s"%(row,service_item))
|
||||
self.items.insert(row, service_item)
|
||||
log.info("Items: %s" % self.items)
|
||||
# self.endInsertRows()
|
||||
|
||||
def removeRow(self, row):
|
||||
self.beginRemoveRows(QModelIndex(), row,row)
|
||||
self.items.pop(row)
|
||||
self.endRemoveRows()
|
||||
|
||||
def addRow(self, item):
|
||||
self.insertRow(len(self.items), item)
|
||||
|
||||
@ -74,7 +67,6 @@ class ServiceData(QAbstractItemModel):
|
||||
|
||||
def parent(self, index=QModelIndex()):
|
||||
return QModelIndex() # no children as yet
|
||||
|
||||
def data(self, index, role):
|
||||
"""
|
||||
Called by the service manager to draw us in the service window
|
||||
@ -119,10 +111,9 @@ class ServiceManager(QWidget):
|
||||
global log
|
||||
log=logging.getLogger(u'ServiceManager')
|
||||
|
||||
def __init__(self, parent, eventManager):
|
||||
def __init__(self, parent):
|
||||
QWidget.__init__(self)
|
||||
self.parent=parent
|
||||
self.EventManager = eventManager
|
||||
self.Layout = QtGui.QVBoxLayout(self)
|
||||
self.Layout.setSpacing(0)
|
||||
self.Layout.setMargin(0)
|
||||
@ -198,12 +189,3 @@ class ServiceManager(QWidget):
|
||||
oosfile.write(self.oos_as_text)
|
||||
oosfile.write("# END OOS\n")
|
||||
oosfile.close()
|
||||
|
||||
def handle_event(self, event):
|
||||
"""
|
||||
Handle the event contained in the event object.
|
||||
"""
|
||||
log.debug(u'Handle event called with event %s' %event.get_type())
|
||||
if event.get_type() == EventType.ThemeData:
|
||||
print event.payload
|
||||
|
||||
|
@ -37,6 +37,12 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
|
||||
# General tab
|
||||
self.GeneralTab = GeneralTab()
|
||||
self.addTab(self.GeneralTab)
|
||||
# Themes tab
|
||||
self.ThemesTab = ThemesTab()
|
||||
self.addTab(self.ThemesTab)
|
||||
# Alert tab
|
||||
self.AlertsTab = AlertsTab()
|
||||
self.addTab(self.AlertsTab)
|
||||
|
||||
def addTab(self, tab):
|
||||
log.info(u'Inserting %s' % tab.title())
|
||||
|
@ -18,7 +18,6 @@ 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
|
||||
|
||||
from time import sleep
|
||||
from copy import deepcopy
|
||||
@ -28,11 +27,11 @@ from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
# from openlp.core.resources import *
|
||||
# from openlp.core.ui import AboutForm, AlertForm, SettingsForm, SlideController
|
||||
from openlp.core.lib import OpenLPToolbar, Event, EventType
|
||||
from openlp.core.ui import ThemesTab
|
||||
from openlp.core.lib import OpenLPToolbar
|
||||
#from openlp.core.lib import ThemeItem
|
||||
|
||||
# from openlp.core import PluginManager
|
||||
import logging
|
||||
|
||||
class ThemeData(QAbstractItemModel):
|
||||
"""
|
||||
@ -42,30 +41,24 @@ class ThemeData(QAbstractItemModel):
|
||||
"""
|
||||
global log
|
||||
log=logging.getLogger(u'ThemeData')
|
||||
|
||||
def __init__(self):
|
||||
QAbstractItemModel.__init__(self)
|
||||
self.items=[]
|
||||
log.info(u'Starting')
|
||||
|
||||
log.info("Starting")
|
||||
def columnCount(self, parent):
|
||||
return 1; # always only a single column (for now)
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self.items)
|
||||
|
||||
def insertRow(self, row, Theme_item):
|
||||
# self.beginInsertRows(QModelIndex(),row,row)
|
||||
log.info("insert row %d:%s"%(row,Theme_item))
|
||||
self.items.insert(row, Theme_item)
|
||||
log.info("Items: %s" % self.items)
|
||||
# self.endInsertRows()
|
||||
|
||||
def removeRow(self, row):
|
||||
self.beginRemoveRows(QModelIndex(), row,row)
|
||||
self.items.pop(row)
|
||||
self.endRemoveRows()
|
||||
|
||||
def addRow(self, item):
|
||||
self.insertRow(len(self.items), item)
|
||||
|
||||
@ -74,7 +67,6 @@ class ThemeData(QAbstractItemModel):
|
||||
|
||||
def parent(self, index=QModelIndex()):
|
||||
return QModelIndex() # no children as yet
|
||||
|
||||
def data(self, index, role):
|
||||
"""
|
||||
Called by the Theme manager to draw us in the Theme window
|
||||
@ -106,6 +98,7 @@ class ThemeData(QAbstractItemModel):
|
||||
def item(self, row):
|
||||
log.info("Get Item:%d -> %s" %(row, str(self.items)))
|
||||
return self.items[row]
|
||||
|
||||
|
||||
class ThemeManager(QWidget):
|
||||
|
||||
@ -118,10 +111,9 @@ class ThemeManager(QWidget):
|
||||
global log
|
||||
log=logging.getLogger(u'ThemeManager')
|
||||
|
||||
def __init__(self, parent, eventmanager):
|
||||
def __init__(self, parent):
|
||||
QWidget.__init__(self)
|
||||
self.parent=parent
|
||||
self.EventManager = eventmanager
|
||||
self.Layout = QtGui.QVBoxLayout(self)
|
||||
self.Layout.setSpacing(0)
|
||||
self.Layout.setMargin(0)
|
||||
@ -142,8 +134,6 @@ class ThemeManager(QWidget):
|
||||
self.TreeView.setModel(self.Theme_data)
|
||||
self.Layout.addWidget(self.TreeView)
|
||||
|
||||
self.themeTab = ThemesTab(self.EventManager)
|
||||
|
||||
# def addThemeItem(self, item):
|
||||
# """Adds Theme item"""
|
||||
# log.info("addThemeItem")
|
||||
@ -191,21 +181,7 @@ class ThemeManager(QWidget):
|
||||
# oosfile.write(self.oos_as_text)
|
||||
# oosfile.write("# END OOS\n")
|
||||
# oosfile.close()
|
||||
|
||||
def addEventManager(self, eventmanager):
|
||||
self.eventManager = eventmanager
|
||||
|
||||
def get_settings_tab(self):
|
||||
return self.themeTab
|
||||
|
||||
def handle_event(self, event):
|
||||
"""
|
||||
Handle the event contained in the event object.
|
||||
"""
|
||||
log.debug(u'Handle event called with event %s' %event.get_type())
|
||||
if event.get_type() == EventType.LoadThemeData:
|
||||
event = Event(EventType.ThemeData, self.themeTab.themelist)
|
||||
self.EventManager.post_event(event)
|
||||
|
||||
def getThemes(self):
|
||||
return self.themeTab.themelist
|
||||
def get_themes(self):
|
||||
return [u'Theme A', u'Theme B']
|
||||
|
||||
|
@ -17,26 +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
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
import logging
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core import translate
|
||||
from openlp.core.lib import SettingsTab, EventManager, Event, EventType
|
||||
from openlp.core.lib import SettingsTab
|
||||
from openlp.core.resources import *
|
||||
|
||||
class ThemesTab(SettingsTab):
|
||||
"""
|
||||
ThemesTab is the theme settings tab in the settings dialog.
|
||||
"""
|
||||
global log
|
||||
log=logging.getLogger(u'ThemesTab')
|
||||
|
||||
def __init__(self, eventmanager):
|
||||
log.debug(u'Initialise')
|
||||
self.eventmanager = eventmanager
|
||||
print eventmanager
|
||||
SettingsTab.__init__(self, u'Themes')
|
||||
def __init__(self):
|
||||
SettingsTab.__init__(self, u'Themes')
|
||||
|
||||
def setupUi(self):
|
||||
self.setObjectName(u'ThemesTab')
|
||||
@ -52,6 +45,9 @@ class ThemesTab(SettingsTab):
|
||||
self.GlobalGroupBoxLayout.setObjectName(u'GlobalGroupBoxLayout')
|
||||
self.DefaultComboBox = QtGui.QComboBox(self.GlobalGroupBox)
|
||||
self.DefaultComboBox.setObjectName(u'DefaultComboBox')
|
||||
self.DefaultComboBox.addItem(QtCore.QString())
|
||||
self.DefaultComboBox.addItem(QtCore.QString())
|
||||
self.DefaultComboBox.addItem(QtCore.QString())
|
||||
self.GlobalGroupBoxLayout.addWidget(self.DefaultComboBox)
|
||||
self.DefaultListView = QtGui.QListView(self.GlobalGroupBox)
|
||||
self.DefaultListView.setObjectName(u'DefaultListView')
|
||||
@ -99,6 +95,9 @@ class ThemesTab(SettingsTab):
|
||||
|
||||
def retranslateUi(self):
|
||||
self.GlobalGroupBox.setTitle(translate(u'ThemesTab', u'Global theme'))
|
||||
self.DefaultComboBox.setItemText(0, translate(u'ThemesTab', u'African Sunset'))
|
||||
self.DefaultComboBox.setItemText(1, translate(u'ThemesTab', u'Snowy Mountains'))
|
||||
self.DefaultComboBox.setItemText(2, translate(u'ThemesTab', u'Wilderness'))
|
||||
self.LevelGroupBox.setTitle(translate(u'ThemesTab', u'Theme level'))
|
||||
self.SongLevelRadioButton.setText(translate(u'ThemesTab', u'Song level'))
|
||||
self.SongLevelLabel.setText(translate(u'ThemesTab', u'Use the theme from each song in the database. If a song doesn\'t have a theme associated with it, then use the service\'s theme. If the service doesn\'t have a theme, then use the global theme.'))
|
||||
@ -106,10 +105,3 @@ class ThemesTab(SettingsTab):
|
||||
self.ServiceLevelLabel.setText(translate(u'ThemesTab', u'Use the theme from the service , overriding any of the individual songs\' themes. If the service doesn\'t have a theme, then use the global theme.'))
|
||||
self.GlobalLevelRadioButton.setText(translate(u'ThemesTab', u'Global level'))
|
||||
self.GlobalLevelLabel.setText(translate(u'ThemesTab', u'Use the global theme, overriding any themes associated wither either the service or the songs.'))
|
||||
|
||||
def load(self):
|
||||
log.debug(u'Load')
|
||||
self.themelist = [u'African Sunset', u'Snowy Mountains', u'Wilderness', u'Wet and Windy London']
|
||||
|
||||
for theme in self.themelist:
|
||||
self.DefaultComboBox.addItem(translate(u'ThemesTab', theme))
|
||||
|
Loading…
Reference in New Issue
Block a user