diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 989277e66..eefcbd969 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -17,12 +17,13 @@ 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 @@ -31,6 +32,6 @@ from toolbar import OpenLPToolbar from songxmlhandler import SongXMLBuilder from songxmlhandler import SongXMLParser -__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', +__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event','EventType', 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder', 'SongXMLParser', 'EventManager'] diff --git a/openlp/core/lib/event.py b/openlp/core/lib/event.py index 38579d21c..4655613af 100644 --- a/openlp/core/lib/event.py +++ b/openlp/core/lib/event.py @@ -40,21 +40,17 @@ 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): - self.type = event_type - self.payload = None - - def get_payload(self): - return self.payload - - def set_payload(self, payload): + def __init__(self, event_type=EventType.Default, payload=None): + self.event_type = event_type self.payload = payload - + def get_type(self): - return self.type + return self.event_type diff --git a/openlp/core/lib/eventmanager.py b/openlp/core/lib/eventmanager.py index bbd907bc5..12dfd2ac1 100644 --- a/openlp/core/lib/eventmanager.py +++ b/openlp/core/lib/eventmanager.py @@ -33,7 +33,7 @@ class EventManager(object): def __init__(self): self.endpoints=[] - log.info(u'Starting') + log.info(u'Initialising') def register(self, plugin): log.debug(u'plugin %s registered with EventManager'%plugin) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 1cdf87eac..6e9bf7b4e 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -88,9 +88,10 @@ class Plugin(object): self.weight = 0 # Set up logging self.log = logging.getLogger(self.name) - if plugin_helpers != None: - self.preview_controller=plugin_helpers[u'preview'] - self.live_controller=plugin_helpers[u'preview'] + 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'] def check_pre_conditions(self): """ diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 47cb26fe6..137251cf3 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -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 +from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, EventManager, Event, EventType from openlp.core import PluginManager @@ -43,7 +43,6 @@ class MainWindow(object): self.alert_form = AlertForm(self.EventManager) self.about_form = AboutForm() self.settings_form = SettingsForm() - self.settings_form.addTab(self.alert_form.get_settings_tab()) pluginpath = os.path.split(os.path.abspath(__file__))[0] pluginpath = os.path.abspath(os.path.join(pluginpath, '..', '..','plugins')) @@ -52,6 +51,10 @@ 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 @@ -84,7 +87,11 @@ class MainWindow(object): # Register the different UI components with Event Manager self.EventManager.register(self.ServiceManagerContents) self.EventManager.register(self.ThemeManagerContents) - self.EventManager.register(self.alert_form) + 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") @@ -113,8 +120,10 @@ 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") @@ -171,6 +180,7 @@ 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() @@ -179,9 +189,10 @@ class MainWindow(object): self.ServiceManagerDock.setWindowIcon(ServiceManagerIcon) self.ServiceManagerDock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) self.ServiceManagerDock.setObjectName("ServiceManagerDock") - self.ServiceManagerContents = ServiceManager(self) + self.ServiceManagerContents = ServiceManager(self, self.EventManager) 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() @@ -191,7 +202,7 @@ class MainWindow(object): self.ThemeManagerDock.setFloating(False) self.ThemeManagerDock.setObjectName("ThemeManagerDock") - self.ThemeManagerContents = ThemeManager(self) + self.ThemeManagerContents = ThemeManager(self, self.EventManager) # self.ThemeManagerContents = QtGui.QWidget() # self.ThemeManagerContents.setObjectName("ThemeManagerContents") diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index aacf445ab..f153f1466 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -29,6 +29,7 @@ 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 @@ -41,24 +42,30 @@ class ServiceData(QAbstractItemModel): """ global log log=logging.getLogger(u'ServiceData') + def __init__(self): QAbstractItemModel.__init__(self) self.items=[] - log.info("Starting") + log.info(u'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) @@ -67,6 +74,7 @@ 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 @@ -111,9 +119,10 @@ class ServiceManager(QWidget): global log log=logging.getLogger(u'ServiceManager') - def __init__(self, parent): + def __init__(self, parent, eventManager): QWidget.__init__(self) self.parent=parent + self.EventManager = eventManager self.Layout = QtGui.QVBoxLayout(self) self.Layout.setSpacing(0) self.Layout.setMargin(0) @@ -195,4 +204,6 @@ class ServiceManager(QWidget): 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 diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 5b8a17552..8e4754d89 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -37,9 +37,6 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): # General tab self.GeneralTab = GeneralTab() self.addTab(self.GeneralTab) - # Themes tab - self.ThemesTab = ThemesTab() - self.addTab(self.ThemesTab) def addTab(self, tab): log.info(u'Inserting %s' % tab.title()) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 95851250a..7bb70f51e 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -18,6 +18,7 @@ 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 @@ -27,11 +28,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 +from openlp.core.lib import OpenLPToolbar, Event, EventType +from openlp.core.ui import ThemesTab #from openlp.core.lib import ThemeItem # from openlp.core import PluginManager -import logging class ThemeData(QAbstractItemModel): """ @@ -41,24 +42,30 @@ class ThemeData(QAbstractItemModel): """ global log log=logging.getLogger(u'ThemeData') + def __init__(self): QAbstractItemModel.__init__(self) self.items=[] - log.info("Starting") + log.info(u'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) @@ -67,6 +74,7 @@ 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 @@ -98,7 +106,6 @@ class ThemeData(QAbstractItemModel): def item(self, row): log.info("Get Item:%d -> %s" %(row, str(self.items))) return self.items[row] - class ThemeManager(QWidget): @@ -111,9 +118,10 @@ class ThemeManager(QWidget): global log log=logging.getLogger(u'ThemeManager') - def __init__(self, parent): + def __init__(self, parent, eventmanager): QWidget.__init__(self) self.parent=parent + self.EventManager = eventmanager self.Layout = QtGui.QVBoxLayout(self) self.Layout.setSpacing(0) self.Layout.setMargin(0) @@ -134,6 +142,8 @@ 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") @@ -181,13 +191,21 @@ 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 get_themes(self): - return [u'Theme A', u'Theme B'] - + def getThemes(self): + return self.themeTab.themelist diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 98b3f0e73..04ecec933 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -17,19 +17,26 @@ 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 +from openlp.core.lib import SettingsTab, EventManager, Event, EventType from openlp.core.resources import * class ThemesTab(SettingsTab): """ ThemesTab is the theme settings tab in the settings dialog. """ - def __init__(self): - SettingsTab.__init__(self, u'Themes') + 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 setupUi(self): self.setObjectName(u'ThemesTab') @@ -45,9 +52,6 @@ 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') @@ -95,9 +99,6 @@ 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.')) @@ -105,3 +106,10 @@ 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))