diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 1a2674c11..db38bc5e5 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -22,6 +22,8 @@ from plugin import Plugin from settingstab import SettingsTab from mediamanageritem import MediaManagerItem from event import Event +from event import EventType +from eventmanager import EventManager from xmlrootclass import XmlRootClass from serviceitem import ServiceItem from eventreceiver import Receiver @@ -30,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'] + 'SongXMLParser', 'EventManager'] diff --git a/openlp/core/lib/event.py b/openlp/core/lib/event.py index efc67bd41..d6c390c62 100644 --- a/openlp/core/lib/event.py +++ b/openlp/core/lib/event.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Scott Guerreri, +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 @@ -46,6 +46,9 @@ class Event(object): """ Provides an Event class to encapsulate events within openlp.org. """ - - def __init__(self, event_type=EventType.Default): - self.type = event_type + def __init__(self, event_type=EventType.Default, payload=None): + self.event_type = event_type + self.payload = payload + + def get_type(self): + return self.event_type diff --git a/openlp/core/lib/eventmanager.py b/openlp/core/lib/eventmanager.py new file mode 100644 index 000000000..12dfd2ac1 --- /dev/null +++ b/openlp/core/lib/eventmanager.py @@ -0,0 +1,46 @@ +# -*- 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): + self.endpoints=[] + log.info(u'Initialising') + + def register(self, plugin): + log.debug(u'plugin %s registered with EventManager'%plugin) + self.endpoints.append(plugin) + + def post_event(self, event): + log.debug(u'post event called for event %s'%event.get_type) + for point in self.endpoints: + point.handle_event(event) + diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 16194e65d..8436bc8d3 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -67,7 +67,7 @@ class Plugin(object): and screen number. """ - def __init__(self, name=None, version=None, preview_controller=None, live_controller=None): + def __init__(self, name=None, version=None, plugin_helpers=None): """ This is the constructor for the plugin object. This provides an easy way for descendent plugins to populate common data. This method *must* @@ -88,8 +88,10 @@ class Plugin(object): self.weight = 0 # Set up logging self.log = logging.getLogger(self.name) - self.preview_controller=preview_controller - self.live_controller=live_controller + 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/pluginmanager.py b/openlp/core/pluginmanager.py index fa3c33442..03749139e 100644 --- a/openlp/core/pluginmanager.py +++ b/openlp/core/pluginmanager.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley, +Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley, 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 @@ -22,7 +22,7 @@ import os import sys import logging -from openlp.core.lib import Plugin +from openlp.core.lib import Plugin, EventManager class PluginManager(object): """ @@ -30,15 +30,15 @@ class PluginManager(object): and executes all the hooks, as and when necessary. """ global log - log=logging.getLogger("PluginMgr") - log.info("Plugin manager loaded") + log=logging.getLogger(u'PluginMgr') + log.info(u'Plugin manager loaded') def __init__(self, dir): """ The constructor for the plugin manager. Passes the controllers on to the plugins for them to interact with via their ServiceItems """ - log.info("Plugin manager initing") + log.info(u'Plugin manager initing') if not dir in sys.path: log.debug("Inserting %s into sys.path", dir) sys.path.insert(0, dir) @@ -48,12 +48,11 @@ class PluginManager(object): # this has to happen after the UI is sorted self.find_plugins(dir) log.info("Plugin manager done init") - def find_plugins(self, dir, preview_controller, live_controller): # xxx shouldn't dir come from self.basepath + def find_plugins(self, dir, plugin_helpers, eventmanager): # TODO shouldn't dir come from self.basepath """ Scan the directory dir for objects inheriting from openlp.plugin """ - self.preview_controller=preview_controller - self.live_controller=live_controller + self.plugin_helpers = plugin_helpers startdepth=len(os.path.abspath(dir).split(os.sep)) log.debug("find plugins %s at depth %d" %( str(dir), startdepth)) @@ -80,16 +79,15 @@ class PluginManager(object): plugin_objects = [] for p in self.plugin_classes: try: - plugin = p(self.preview_controller, self.live_controller) - log.debug('loaded plugin' + str(p) + ' with controllers'+str(self.preview_controller)+str(self.live_controller)) + plugin = p(self.plugin_helpers) + log.debug(u'loaded plugin %s with helpers'%str(p)) + log.debug("Plugin="+str(p)) + if plugin.check_pre_conditions(): + log.debug("Appending "+str(p)) + plugin_objects.append(plugin) + eventmanager.register(plugin) except TypeError: - # TODO: need to get rid of this once all plugins are up to date - plugin = p() - log.debug('loaded plugin' + str(p) + ' with no controllers') - log.debug("Plugin="+str(p)) - if plugin.check_pre_conditions(): - log.debug("Appending "+str(p)) - plugin_objects.append(plugin) + log.error(u'loaded plugin %s has no helpers'%str(p)) self.plugins = sorted(plugin_objects, self.order_by_weight) def order_by_weight(self, x, y): @@ -105,8 +103,6 @@ class PluginManager(object): if media_manager_item is not None: log.debug('Inserting media manager item from %s' % plugin.name) mediatoolbox.addItem(media_manager_item, plugin.icon, media_manager_item.title) - # TODO: These shouldn't be called here... - plugin.initialise() def hook_settings_tabs(self, settingsform=None): """ @@ -137,5 +133,19 @@ class PluginManager(object): for plugin in self.plugins: plugin.add_export_menu_item(export_menu) - def hook_handle_event(self, event): - pass + def hook_handle_event(self, eventmanager): + for plugin in self.plugins: + handle_event = plugin.handle_event(None) + print plugin, handle_event +# if settings_tab is not None: +# log.debug('Inserting settings tab item from %s' % plugin.name) +# settingsform.addTab(settings_tab) +# else: +# log.debug('No settings in %s' % plugin.name) + def initialise_plugins(self): + """ + Loop through all the plugins and give them an opportunity to add an item + to the export menu. + """ + for plugin in self.plugins: + plugin.initialise() diff --git a/openlp/core/render.py b/openlp/core/render.py index 41a1643ab..471ad0093 100644 --- a/openlp/core/render.py +++ b/openlp/core/render.py @@ -44,8 +44,10 @@ class Renderer: self._theme=None self._bg_image_filename=None self._paint=None + def set_debug(self, debug): self._debug=debug + def set_theme(self, theme): self._theme=theme if theme.BackgroundType == 2: @@ -56,6 +58,7 @@ class Renderer: self._bg_image_filename=filename if self._paint is not None: self.scale_bg_image() + def scale_bg_image(self): assert self._paint i=QtGui.QImage(self._bg_image_filename) @@ -81,6 +84,7 @@ class Renderer: self._paint=p if self._bg_image_filename is not None: self.scale_bg_image() + def set_words_openlp(self, words): # print "set words openlp", words verses=[] @@ -95,6 +99,7 @@ class Renderer: verses_text.append('\n'.join(v).lstrip()) # remove first \n return verses_text + def render_screen(self, screennum): print "render screen\n", screennum, self.words[screennum] import time @@ -106,6 +111,7 @@ class Renderer: def set_text_rectangle(self, rect): """ Sets the rectangle within which text should be rendered""" self._rect=rect + def _render_background(self): # xxx may have to prerender to a memdc when set theme is called for use on slow machines # takes 26ms on mijiti's machine! @@ -149,6 +155,7 @@ class Renderer: p.drawPixmap(self.background_offsetx,self.background_offsety, self.img) p.end() print "render background done" + def split_set_of_lines(self, lines): """Given a list of lines, decide how to split them best if they don't all fit on the screen @@ -212,7 +219,6 @@ class Renderer: return retval - def _render_lines(self, lines): """render a set of lines according to the theme, return bounding box""" print "_render_lines", lines @@ -234,6 +240,7 @@ class Renderer: print "render lines DONE" return bbox + def _render_lines_unaligned(self, lines, tlcorner=(0,0)): """Given a list of lines to render, render each one in turn @@ -265,7 +272,6 @@ class Renderer: return retval - def _render_single_line(self, line, tlcorner=(0,0)): """render a single line of words onto the DC, top left corner @@ -402,8 +408,3 @@ class Renderer: p.drawText(x,y+metrics.height()-metrics.descent()-1, line) p.end() return (w, h) - - - - - diff --git a/openlp/core/theme/theme.py b/openlp/core/theme/theme.py index 81f94a9ce..c36434273 100644 --- a/openlp/core/theme/theme.py +++ b/openlp/core/theme/theme.py @@ -15,7 +15,8 @@ blankstylexml=\ ''' BlankStyle - 0 + 1 + 0 $000000 @@ -37,6 +38,9 @@ class Theme: attributes: name : theme name + BackgroundMode : 1 - Transparent + 1 - Opaque + BackgroundType : 0 - solid color 1 - gradient color 2 - image diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 7deffb3ab..f4662afb1 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -27,7 +27,8 @@ from about import AboutForm from alertform import AlertForm from settingsform import SettingsForm from servicemanager import ServiceManager +from thememanager import ThemeManager from mainwindow import MainWindow __all__ = ['SplashScreen', 'AboutForm', 'SettingsForm', - 'MainWindow', 'SlideController', 'ServiceManager'] + 'MainWindow', 'SlideController', 'ServiceManager', 'ThemeManager'] diff --git a/openlp/core/ui/alertform.py b/openlp/core/ui/alertform.py index 0446c60a8..68319a65a 100644 --- a/openlp/core/ui/alertform.py +++ b/openlp/core/ui/alertform.py @@ -17,7 +17,7 @@ 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 PyQt4.QtGui import QDialog @@ -25,14 +25,17 @@ from openlp.core import translate from openlp.core.resources import * class AlertForm(QDialog): - + global log + log=logging.getLogger(u'AlertForm') + def __init__(self, parent=None): QDialog.__init__(self, parent) self.setupUi(self) + log.info(u'Defined') def setupUi(self, AlertForm): AlertForm.setObjectName("AlertForm") - AlertForm.resize(370, 105) + AlertForm.resize(370, 110) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icon/openlp.org-icon-32.bmp"), QtGui.QIcon.Normal, QtGui.QIcon.Off) AlertForm.setWindowIcon(icon) @@ -56,7 +59,7 @@ class AlertForm(QDialog): self.AlertEntryLabel.setSizePolicy(sizePolicy) self.AlertEntryLabel.setObjectName("AlertEntryLabel") self.AlertEntryEditItem = QtGui.QLineEdit(self.AlertEntryWidget) - self.AlertEntryEditItem.setGeometry(QtCore.QRect(0, 20, 353, 21)) + self.AlertEntryEditItem.setGeometry(QtCore.QRect(0, 20, 353, 26)) self.AlertEntryEditItem.setObjectName("AlertEntryEditItem") self.AlertFormLayout.addWidget(self.AlertEntryWidget) self.ButtonBoxWidget = QtGui.QWidget(AlertForm) @@ -83,20 +86,21 @@ class AlertForm(QDialog): self.retranslateUi(AlertForm) QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL("clicked()"), AlertForm.close) + QtCore.QObject.connect(self.DisplayButton, QtCore.SIGNAL("clicked()"), self.onDisplayClicked) QtCore.QMetaObject.connectSlotsByName(AlertForm) def retranslateUi(self, AlertForm): - AlertForm.setWindowTitle(translate("AlertForm", "Alert Message")) - self.AlertEntryLabel.setText(translate("AlertForm", "Alert Text:")) - self.DisplayButton.setText(translate("AlertForm", "Display")) - self.CancelButton.setText(translate("AlertForm", "Cancel")) + AlertForm.setWindowTitle(translate("AlertForm", u'Alert Message')) + self.AlertEntryLabel.setText(translate("AlertForm", u'Alert Text:')) + self.DisplayButton.setText(translate("AlertForm", u'Display')) + self.CancelButton.setText(translate("AlertForm", u'Cancel')) -# def show(self): -# self.AlertForm.show() - def load_settings(self): pass def save_settings(self): pass + + def onDisplayClicked(self): + pass diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 6d39f1254..56904343f 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley, +Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley, 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 @@ -18,54 +18,68 @@ 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 PyQt4 import * from PyQt4 import QtCore, QtGui from openlp.core.resources import * from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \ - SlideController, ServiceManager -from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab + SlideController, ServiceManager, ThemeManager +from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, EventManager from openlp.core import PluginManager -import logging + class MainWindow(object): global log - log=logging.getLogger("MainWindow") - log.info("MainWindow loaded") + log=logging.getLogger(u'MainWindow') + log.info(u'MainWindow loaded') def __init__(self): self.main_window = QtGui.QMainWindow() + self.EventManager = EventManager() self.alert_form = AlertForm() self.about_form = AboutForm() self.settings_form = SettingsForm() + pluginpath = os.path.split(os.path.abspath(__file__))[0] pluginpath = os.path.abspath(os.path.join(pluginpath, '..', '..','plugins')) self.plugin_manager = PluginManager(pluginpath) + self.plugin_helpers = {} + self.setupUi() - log.info('') - self.plugin_manager.find_plugins(pluginpath, self.PreviewController, self.LiveController) + log.info(u'Load 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'theme'] = self.ThemeManagerContents # Theme manger + + self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers, self.EventManager) # hook methods have to happen after find_plugins. Find plugins needs the controllers # hence the hooks have moved from setupUI() to here # Find and insert media manager items - log.info("hook media") + log.info(u'hook media') self.plugin_manager.hook_media_manager(self.MediaToolBox) # Find and insert settings tabs - log.info("hook settings") + log.info(u'hook settings') self.plugin_manager.hook_settings_tabs(self.settings_form) # Call the hook method to pull in import menus. - log.info("hook menus") + log.info(u'hook menus') self.plugin_manager.hook_import_menu(self.FileImportMenu) # Call the hook method to pull in export menus. - self.plugin_manager.hook_import_menu(self.FileExportMenu) + self.plugin_manager.hook_export_menu(self.FileExportMenu) + # Call the initialise method to setup plugins. + log.info(u'initialise plugins') + self.plugin_manager.initialise_plugins() + def setupUi(self): self.main_window.setObjectName("main_window") self.main_window.resize(1087, 847) @@ -151,7 +165,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() ServiceManagerIcon.addPixmap(QtGui.QPixmap(":/system/system_servicemanager.png"), @@ -162,6 +176,7 @@ class MainWindow(object): 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() ThemeManagerIcon.addPixmap(QtGui.QPixmap(":/system/system_thememanager.png"), @@ -169,41 +184,46 @@ class MainWindow(object): self.ThemeManagerDock.setWindowIcon(ThemeManagerIcon) self.ThemeManagerDock.setFloating(False) self.ThemeManagerDock.setObjectName("ThemeManagerDock") - self.ThemeManagerContents = QtGui.QWidget() - self.ThemeManagerContents.setObjectName("ThemeManagerContents") - self.ThemeManagerLayout = QtGui.QVBoxLayout(self.ThemeManagerContents) - self.ThemeManagerLayout.setSpacing(0) - self.ThemeManagerLayout.setMargin(0) - self.ThemeManagerLayout.setObjectName("ThemeManagerLayout") - self.ThemeManagerToolbar = QtGui.QToolBar(self.ThemeManagerContents) - self.ThemeManagerToolbar.setObjectName("ThemeManagerToolbar") - NewThemeIcon = QtGui.QIcon() - NewThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_new.png"), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.ThemeNewItem = self.ThemeManagerToolbar.addAction(NewThemeIcon, 'New theme') - EditThemeIcon = QtGui.QIcon() - EditThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_edit.png"), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.ThemeEditItem = self.ThemeManagerToolbar.addAction(EditThemeIcon, 'Edit theme') - DeleteThemeIcon = QtGui.QIcon() - DeleteThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_delete.png"), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.ThemeDeleteButton = self.ThemeManagerToolbar.addAction(DeleteThemeIcon, 'Delete theme') - self.ThemeManagerToolbar.addSeparator() - ImportThemeIcon = QtGui.QIcon() - ImportThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_import.png"), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.ThemeImportButton = self.ThemeManagerToolbar.addAction(ImportThemeIcon, 'Import theme') - ExportThemeIcon = QtGui.QIcon() - ExportThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_export.png"), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.ThemeExportButton = self.ThemeManagerToolbar.addAction(ExportThemeIcon, 'Export theme') - self.ThemeManagerLayout.addWidget(self.ThemeManagerToolbar) - self.ThemeManagerListView = QtGui.QListView(self.ThemeManagerContents) - self.ThemeManagerListView.setObjectName("ThemeManagerListView") - self.ThemeManagerLayout.addWidget(self.ThemeManagerListView) + + self.ThemeManagerContents = ThemeManager(self) + +# self.ThemeManagerContents = QtGui.QWidget() +# self.ThemeManagerContents.setObjectName("ThemeManagerContents") +# self.ThemeManagerLayout = QtGui.QVBoxLayout(self.ThemeManagerContents) +# self.ThemeManagerLayout.setSpacing(0) +# self.ThemeManagerLayout.setMargin(0) +# self.ThemeManagerLayout.setObjectName("ThemeManagerLayout") +# self.ThemeManagerToolbar = QtGui.QToolBar(self.ThemeManagerContents) +# self.ThemeManagerToolbar.setObjectName("ThemeManagerToolbar") +# NewThemeIcon = QtGui.QIcon() +# NewThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_new.png"), +# QtGui.QIcon.Normal, QtGui.QIcon.Off) +# self.ThemeNewItem = self.ThemeManagerToolbar.addAction(NewThemeIcon, 'New theme') +# EditThemeIcon = QtGui.QIcon() +# EditThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_edit.png"), +# QtGui.QIcon.Normal, QtGui.QIcon.Off) +# self.ThemeEditItem = self.ThemeManagerToolbar.addAction(EditThemeIcon, 'Edit theme') +# DeleteThemeIcon = QtGui.QIcon() +# DeleteThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_delete.png"), +# QtGui.QIcon.Normal, QtGui.QIcon.Off) +# self.ThemeDeleteButton = self.ThemeManagerToolbar.addAction(DeleteThemeIcon, 'Delete theme') +# self.ThemeManagerToolbar.addSeparator() +# ImportThemeIcon = QtGui.QIcon() +# ImportThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_import.png"), +# QtGui.QIcon.Normal, QtGui.QIcon.Off) +# self.ThemeImportButton = self.ThemeManagerToolbar.addAction(ImportThemeIcon, 'Import theme') +# ExportThemeIcon = QtGui.QIcon() +# ExportThemeIcon.addPixmap(QtGui.QPixmap(":/themes/theme_export.png"), +# QtGui.QIcon.Normal, QtGui.QIcon.Off) +# self.ThemeExportButton = self.ThemeManagerToolbar.addAction(ExportThemeIcon, 'Export theme') +# self.ThemeManagerLayout.addWidget(self.ThemeManagerToolbar) +# self.ThemeManagerListView = QtGui.QListView(self.ThemeManagerContents) +# self.ThemeManagerListView.setObjectName("ThemeManagerListView") +# self.ThemeManagerLayout.addWidget(self.ThemeManagerListView) + self.ThemeManagerDock.setWidget(self.ThemeManagerContents) self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock) + self.FileNewItem = QtGui.QAction(self.main_window) self.FileNewItem.setIcon(self.ServiceManagerContents.Toolbar.getIconFromTitle("New Service")) self.FileNewItem.setObjectName("FileNewItem") @@ -359,11 +379,11 @@ class MainWindow(object): # self.ServiceManagerContents.ThemeComboBox.setItemText(1, QtGui.QApplication.translate("main_window", "Snowy Mountains", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.ThemeComboBox.setItemText(2, QtGui.QApplication.translate("main_window", "Wilderness", None, QtGui.QApplication.UnicodeUTF8)) self.ThemeManagerDock.setWindowTitle(QtGui.QApplication.translate("main_window", "Theme Manager", None, QtGui.QApplication.UnicodeUTF8)) - self.ThemeNewItem.setText(QtGui.QApplication.translate("main_window", "New Theme", None, QtGui.QApplication.UnicodeUTF8)) - self.ThemeEditItem.setText(QtGui.QApplication.translate("main_window", "Edit Theme", None, QtGui.QApplication.UnicodeUTF8)) - self.ThemeDeleteButton.setText(QtGui.QApplication.translate("main_window", "Delete Theme", None, QtGui.QApplication.UnicodeUTF8)) - self.ThemeImportButton.setText(QtGui.QApplication.translate("main_window", "Import Theme", None, QtGui.QApplication.UnicodeUTF8)) - self.ThemeExportButton.setText(QtGui.QApplication.translate("main_window", "Export Theme", None, QtGui.QApplication.UnicodeUTF8)) +# self.ThemeNewItem.setText(QtGui.QApplication.translate("main_window", "New Theme", None, QtGui.QApplication.UnicodeUTF8)) +# self.ThemeEditItem.setText(QtGui.QApplication.translate("main_window", "Edit Theme", None, QtGui.QApplication.UnicodeUTF8)) +# self.ThemeDeleteButton.setText(QtGui.QApplication.translate("main_window", "Delete Theme", None, QtGui.QApplication.UnicodeUTF8)) +# self.ThemeImportButton.setText(QtGui.QApplication.translate("main_window", "Import Theme", None, QtGui.QApplication.UnicodeUTF8)) +# self.ThemeExportButton.setText(QtGui.QApplication.translate("main_window", "Export Theme", None, QtGui.QApplication.UnicodeUTF8)) self.FileNewItem.setText(QtGui.QApplication.translate("main_window", "&New", None, QtGui.QApplication.UnicodeUTF8)) self.FileNewItem.setToolTip(QtGui.QApplication.translate("main_window", "New Service", None, QtGui.QApplication.UnicodeUTF8)) self.FileNewItem.setStatusTip(QtGui.QApplication.translate("main_window", "Create a new Service", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index ed0ce8fc4..f2f45e5ce 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -40,7 +40,7 @@ class ServiceData(QAbstractItemModel): Root contains a list of ServiceItems """ global log - log=logging.getLogger("ServiceData") + log=logging.getLogger(u'ServiceData') def __init__(self): QAbstractItemModel.__init__(self) self.items=[] @@ -108,6 +108,8 @@ class ServiceManager(QWidget): one lump. Also handles the UI tasks of moving things up and down etc. """ + global log + log=logging.getLogger(u'ServiceManager') def __init__(self, parent): QWidget.__init__(self) @@ -163,6 +165,7 @@ class ServiceManager(QWidget): self.service_data.addRow(item) else: self.service_data.insertRow(row+1, item) + def removeServiceItem(self): """Remove currently selected item""" pass diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 22a0e230a..20fb8ed20 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -40,9 +40,9 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): # Themes tab self.ThemesTab = ThemesTab() self.addTab(self.ThemesTab) - # Alerts tab + # Alert tab self.AlertsTab = AlertsTab() - self.addTab(self.AlertsTab) + self.addTab(self.AlertsTab) 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 new file mode 100644 index 000000000..af60c554b --- /dev/null +++ b/openlp/core/ui/thememanager.py @@ -0,0 +1,191 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2009 Raoul Snyman +Portions copyright (c) 2009 Martin Thompson, Tim Bentley, + +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 + +from time import sleep +from copy import deepcopy +from PyQt4 import * +from PyQt4 import QtCore, QtGui +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 ThemeItem + +# from openlp.core import PluginManager +import logging + +class ThemeData(QAbstractItemModel): + """ + Tree of items for an order of Theme. + Includes methods for reading and writing the contents to an OOS file + Root contains a list of ThemeItems + """ + global log + log=logging.getLogger(u'ThemeData') + def __init__(self): + QAbstractItemModel.__init__(self) + self.items=[] + 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) + + def index(self, row, col, parent = QModelIndex()): + return self.createIndex(row,col) + + 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 + """ + row=index.row() + if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row! + return QVariant() + item=self.items[row] + if role==Qt.DisplayRole: + retval= item.pluginname + ":" + item.shortname + elif role == Qt.DecorationRole: + retval = item.iconic_representation + elif role == Qt.ToolTipRole: + retval= None + else: + retval= None + if retval == None: + retval=QVariant() +# log.info("Returning"+ str(retval)) + if type(retval) is not type(QVariant): + return QVariant(retval) + else: + return retval + + def __iter__(self): + for i in self.items: + yield i + + def item(self, row): + log.info("Get Item:%d -> %s" %(row, str(self.items))) + return self.items[row] + + +class ThemeManager(QWidget): + + """Manages the orders of Theme. Currently this involves taking + text strings from plugins and adding them to an OOS file. In + future, it will also handle zipping up all the resources used into + one lump. + Also handles the UI tasks of moving things up and down etc. + """ + global log + log=logging.getLogger(u'ThemeManager') + + def __init__(self, parent): + QWidget.__init__(self) + self.parent=parent + self.Layout = QtGui.QVBoxLayout(self) + self.Layout.setSpacing(0) + self.Layout.setMargin(0) + self.Toolbar = OpenLPToolbar(self) + self.Toolbar.addToolbarButton("New Theme", ":/themes/theme_new.png") + self.Toolbar.addToolbarButton("Edit Theme", ":/themes/theme_edit.png") + self.Toolbar.addToolbarButton("Delete Theme", ":/themes/theme_delete.png") + self.Toolbar.addSeparator() + self.Toolbar.addToolbarButton("Import Theme", ":/themes/theme_import.png") + self.Toolbar.addToolbarButton("Export Theme", ":/themes/theme_export.png") + self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar) + self.Toolbar.addAction(self.ThemeWidget) + + self.Layout.addWidget(self.Toolbar) + + self.TreeView = QtGui.QTreeView(self) + self.Theme_data=ThemeData() + self.TreeView.setModel(self.Theme_data) + self.Layout.addWidget(self.TreeView) + self.themelist= [] + +# def addThemeItem(self, item): +# """Adds Theme item""" +# log.info("addThemeItem") +# indexes=self.TreeView.selectedIndexes() +# assert len(indexes) <= 1 # can only have one selected index in this view +# if indexes == []: +# log.info("No row") +# row = None +# selected_item = None +# else: +# row=indexes[0].row() +# # if currently selected is of correct type, add it to it +# log.info("row:%d"%row) +# selected_item=self.Theme_data.item(row) +# if type(selected_item) == type(item): +# log.info("Add to existing item") +# selected_item.add(item) +# else: +# log.info("Create new item") +# if row is None: +# self.Theme_data.addRow(item) +# else: +# self.Theme_data.insertRow(row+1, item) +# +# def removeThemeItem(self): +# """Remove currently selected item""" +# pass +# +# def oos_as_text(self): +# text=[] +# log.info( "oos as text") +# log.info("Data:"+str(self.Theme_data)) +# for i in self.Theme_data: +# text.append("# " + str(i)) +# text.append(i.get_oos_text()) +# return '\n'.join(text) +# +# def write_oos(self, filename): +# """ +# Write a full OOS file out - iterate over plugins and call their respective methods +# This format is totally arbitrary testing purposes - something sensible needs to go in here! +# """ +# oosfile=open(filename, "w") +# oosfile.write("# BEGIN OOS\n") +# oosfile.write(self.oos_as_text) +# oosfile.write("# END OOS\n") +# oosfile.close() + + def load(self): + log.debug(u'Load') + self.themelist = [u'African Sunset', u'Snowy Mountains', u'Wilderness', u'Wet and Windy London'] + + def getThemes(self): + return self.themelist diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 4684bae34..d3ca64f81 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -35,9 +35,9 @@ class BiblePlugin(Plugin): log=logging.getLogger(u'BiblePlugin') log.info(u'Bible Plugin loaded') - def __init__(self): + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Bibles', u'1.9.0') + Plugin.__init__(self, u'Bibles', u'1.9.0', plugin_helpers) self.weight = -9 # Create the plugin icon self.icon = QtGui.QIcon() diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 3afa3e114..d4ed4f36e 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 openlp.core.resources import * -from openlp.core.lib import Plugin +from openlp.core.lib import Plugin, Event from forms import EditCustomForm from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem, CustomServiceItem @@ -31,10 +31,10 @@ class CustomPlugin(Plugin): global log log=logging.getLogger(u'CustomPlugin') log.info(u'Custom Plugin loaded') - - def __init__(self, preview_controller, live_controller): + + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Custom', u'1.9.0', preview_controller, live_controller) + Plugin.__init__(self, u'Custom', u'1.9.0', plugin_helpers) self.weight = -5 self.custommanager = CustomManager(self.config) self.edit_custom_form = EditCustomForm(self.custommanager) @@ -42,18 +42,16 @@ class CustomPlugin(Plugin): self.icon = QtGui.QIcon() self.icon.addPixmap(QtGui.QPixmap(':/media/media_custom.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off) - - self.preview_service_item = CustomServiceItem(preview_controller) - self.live_service_item = CustomServiceItem(live_controller) + self.preview_service_item = CustomServiceItem(self.preview_controller) + self.live_service_item = CustomServiceItem(self.live_controller) def get_media_manager_item(self): # Create the CustomManagerItem object self.media_item = CustomMediaItem(self, self.icon, u'Custom Slides') return self.media_item - def get_settings_tab(self): - pass - - def initialise(self): - pass - + 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()) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index fd640af25..b01ce9bb9 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -32,6 +32,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): Constructor """ QtGui.QDialog.__init__(self, parent) + #self.parent = parent self.setupUi(self) # Connecting signals and slots QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.rejected) @@ -52,8 +53,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): # Create other objects and forms self.custommanager = custommanager self.initialise() - self.VerseListView.setAlternatingRowColors(True) - #self.savebutton = self.ButtonBox.button(QtGui.QDialogButtonBox.Save) + self.VerseListView.setAlternatingRowColors(True) def initialise(self): self.valid = True @@ -65,7 +65,9 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): self.VerseTextEdit.clear() self.VerseListView.clear() #make sure we have a new item - self.customSlide = CustomSlide() + self.customSlide = CustomSlide() + self.ThemecomboBox.addItem(u'') + #self.theme_manager.getThemes() def loadCustom(self, id): self.customSlide = CustomSlide() diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index a6947c89b..f6b8ce2e1 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -31,17 +31,17 @@ class ImagePlugin(Plugin): log=logging.getLogger(u'ImagePlugin') log.info(u'Image Plugin loaded') - def __init__(self, preview_controller, live_controller): + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Images', u'1.9.0', preview_controller, live_controller) + Plugin.__init__(self, u'Images', u'1.9.0', plugin_helpers) self.weight = -7 # Create the plugin icon self.icon = QtGui.QIcon() self.icon.addPixmap(QtGui.QPixmap(':/media/media_image.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.preview_service_item = ImageServiceItem(preview_controller) - self.live_service_item = ImageServiceItem(live_controller) + self.preview_service_item = ImageServiceItem(self.preview_controller) + self.live_service_item = ImageServiceItem(self.live_controller) def get_media_manager_item(self): # Create the MediaManagerItem object diff --git a/openlp/plugins/images/lib/__init__.py b/openlp/plugins/images/lib/__init__.py index 34111461b..36105e173 100644 --- a/openlp/plugins/images/lib/__init__.py +++ b/openlp/plugins/images/lib/__init__.py @@ -17,6 +17,6 @@ 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 imageserviceitem import ImageServiceItem from listwithpreviews import ListWithPreviews +from imageserviceitem import ImageServiceItem from mediaitem import ImageMediaItem diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index b4cf4bfa4..4587039cf 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -28,9 +28,9 @@ from openlp.plugins.presentations.lib import PresentationMediaItem class PresentationPlugin(Plugin): - def __init__(self): + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Presentations', u'1.9.0') + Plugin.__init__(self, u'Presentations', u'1.9.0', plugin_helpers) self.weight = -8 # Create the plugin icon self.icon = QtGui.QIcon() diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index fd874c1d9..715ec2c03 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -33,9 +33,9 @@ class SongsPlugin(Plugin): log=logging.getLogger(u'SongsPlugin') log.info(u'Song Plugin loaded') - def __init__(self): + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Songs', u'1.9.0') + Plugin.__init__(self, u'Songs', u'1.9.0', plugin_helpers) self.weight = -10 self.songmanager = SongManager(self.config) self.openlp_import_form = OpenLPImportForm() diff --git a/openlp/plugins/videos/videoplugin.py b/openlp/plugins/videos/videoplugin.py index 036d8d34c..2d64a9879 100644 --- a/openlp/plugins/videos/videoplugin.py +++ b/openlp/plugins/videos/videoplugin.py @@ -26,9 +26,9 @@ from openlp.plugins.videos.lib import VideoTab, VideoMediaItem class VideoPlugin(Plugin): - def __init__(self): + def __init__(self, plugin_helpers): # Call the parent constructor - Plugin.__init__(self, u'Videos', u'1.9.0') + Plugin.__init__(self, u'Videos', u'1.9.0', plugin_helpers) self.weight = -6 # Create the plugin icon self.icon = QtGui.QIcon()