Moved toolbars out into separate class, as they are used by more than Media Manager items

Move Service Manager into own class so it can do some real work

bzr-revno: 336
This commit is contained in:
Martin Thompson 2009-02-21 19:23:54 +00:00
parent 851c669e8b
commit 603ac29b90
6 changed files with 156 additions and 91 deletions

View File

@ -27,6 +27,7 @@ from xmlrootclass import XmlRootClass
from serviceitem import ServiceItem from serviceitem import ServiceItem
from eventreceiver import Receiver from eventreceiver import Receiver
from imageserviceitem import ImageServiceItem from imageserviceitem import ImageServiceItem
from toolbar import OpenLPToolbar
__all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event', __all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event',
'XmlRootClass', 'ServiceItem', 'Receiver', 'ImageServiceItem'] 'XmlRootClass', 'ServiceItem', 'Receiver', 'ImageServiceItem', 'OpenLPToolbar']

View File

@ -2,8 +2,8 @@
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
""" """
OpenLP - Open Source Lyrics Projection OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman Copyright (c) 2008-2009 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 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 the terms of the GNU General Public License as published by the Free Software
@ -21,6 +21,7 @@ import types
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.lib.toolbar import *
class MediaManagerItem(QtGui.QWidget): class MediaManagerItem(QtGui.QWidget):
""" """
@ -41,7 +42,9 @@ class MediaManagerItem(QtGui.QWidget):
if title is not None: if title is not None:
self.title = title self.title = title
self.Toolbar = None self.Toolbar = None
#self.ToolbarButtons = [] self.PageLayout = QtGui.QVBoxLayout(self)
self.PageLayout.setSpacing(0)
self.PageLayout.setMargin(0)
def addToolbar(self): def addToolbar(self):
""" """
@ -49,33 +52,16 @@ class MediaManagerItem(QtGui.QWidget):
item. item.
""" """
if self.Toolbar is None: if self.Toolbar is None:
self.PageLayout = QtGui.QVBoxLayout(self) self.Toolbar=OpenLPToolbar(self)
self.PageLayout.setSpacing(0)
self.PageLayout.setMargin(0)
self.PageLayout.setObjectName('PageLayout')
self.Toolbar = QtGui.QToolBar(self)
self.Toolbar.setObjectName('Toolbar')
self.PageLayout.addWidget(self.Toolbar) self.PageLayout.addWidget(self.Toolbar)
def addToolbarButton(self, title, tooltip, icon, slot=None, objectname=None): def addToolbarButton(self, title, tooltip, icon, slot=None, objectname=None):
""" """
A method to help developers easily add a button to the toolbar. A method to help developers easily add a button to the toolbar.
""" """
if type(icon) is QtGui.QIcon: # NB different order (when I broke this out, I wanted to not break compatability)
ButtonIcon = icon # but it makes sense for the icon to come before the tooltip (as you have to have an icon, but not neccesarily a tooltip)
elif type(icon) is types.StringType: self.Toolbar.addToolbarButton(title, icon, tooltip, slot, objectname)
ButtonIcon = QtGui.QIcon()
if icon.startswith(':/'):
ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
else:
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
ToolbarButton = self.Toolbar.addAction(ButtonIcon, title)
if tooltip is not None:
ToolbarButton.setToolTip(tooltip)
if slot is not None:
QtCore.QObject.connect(ToolbarButton, QtCore.SIGNAL('triggered()'), slot)
def addToolbarSeparator(self): def addToolbarSeparator(self):
""" """

View File

@ -0,0 +1,60 @@
# -*- 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 types
from PyQt4 import QtCore, QtGui
import logging
class OpenLPToolbar(QtGui.QToolBar):
"""
Lots of toolbars around the place, so it makes sense to have a common way to manage them
"""
def __init__(self, parent):
QtGui.QToolBar.__init__(self, parent)
self.icons={} # useful to be able to reuse button icons...
self.log=logging.getLogger("OpenLPToolbar"+str(parent))
self.log.info("Init done")
def addToolbarButton(self, title, icon, tooltip=None, slot=None, objectname=None):
"""
A method to help developers easily add a button to the toolbar.
"""
if type(icon) is QtGui.QIcon:
ButtonIcon = icon
elif type(icon) is types.StringType:
ButtonIcon = QtGui.QIcon()
if icon.startswith(':/'):
ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
else:
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
ToolbarButton = self.addAction(ButtonIcon, title)
if tooltip is not None:
ToolbarButton.setToolTip(tooltip)
if slot is not None:
QtCore.QObject.connect(ToolbarButton, QtCore.SIGNAL('triggered()'), slot)
self.icons[title]=ButtonIcon
def getIconFromTitle(self, title):
if self.icons.has_key(title):
return self.icons[title]
else:
self.log.error("getIconFromTitle - no icon for %s" %title)
return QtGui.QIcon()

View File

@ -23,6 +23,8 @@ from splashscreen import SplashScreen
from about import AboutForm from about import AboutForm
from alertform import AlertForm from alertform import AlertForm
from settings import SettingsDialog from settings import SettingsDialog
from servicemanager import ServiceManager
from mainwindow import MainWindow from mainwindow import MainWindow
__all__ = ['SplashScreen', 'AboutForm', 'AlertForm', 'SettingsDialog', 'MainWindow', 'SlideController'] __all__ = ['SplashScreen', 'AboutForm', 'AlertForm', 'SettingsDialog',
'MainWindow', 'SlideController', 'ServiceManager']

View File

@ -24,7 +24,8 @@ from PyQt4 import *
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.ui import AboutForm, AlertForm, SettingsDialog, SlideController from openlp.core.ui import AboutForm, AlertForm, SettingsDialog
from openlp.core.ui import SlideController, ServiceManager
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, Receiver from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, Receiver
from openlp.core import PluginManager from openlp.core import PluginManager
@ -153,57 +154,7 @@ class MainWindow(object):
self.ServiceManagerDock.setWindowIcon(ServiceManagerIcon) self.ServiceManagerDock.setWindowIcon(ServiceManagerIcon)
self.ServiceManagerDock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) self.ServiceManagerDock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures)
self.ServiceManagerDock.setObjectName("ServiceManagerDock") self.ServiceManagerDock.setObjectName("ServiceManagerDock")
self.ServiceManagerContents = QtGui.QWidget() self.ServiceManagerContents = ServiceManager(self)
self.ServiceManagerContents.setObjectName("ServiceManagerContents")
self.ServiceManagerLayout = QtGui.QVBoxLayout(self.ServiceManagerContents)
self.ServiceManagerLayout.setSpacing(0)
self.ServiceManagerLayout.setMargin(0)
self.ServiceManagerLayout.setObjectName("ServiceManagerLayout")
self.ServiceToolbar = QtGui.QToolBar(self.ServiceManagerContents)
self.ServiceToolbar.setObjectName("ServiceToolbar")
MoveTopIcon = QtGui.QIcon()
MoveTopIcon.addPixmap(QtGui.QPixmap(":/services/service_top.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.MoveTopButton = self.ServiceToolbar.addAction(MoveTopIcon, 'Move to top')
MoveUpIcon = QtGui.QIcon()
MoveUpIcon.addPixmap(QtGui.QPixmap(":/services/service_up.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.MoveUpButton = self.ServiceToolbar.addAction(MoveUpIcon, 'Move up')
MoveDownIcon = QtGui.QIcon()
MoveDownIcon.addPixmap(QtGui.QPixmap(":/services/service_down.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.MoveDownButton = self.ServiceToolbar.addAction(MoveDownIcon, 'Move down')
MoveBottomIcon = QtGui.QIcon()
MoveBottomIcon.addPixmap(QtGui.QPixmap(":/services/service_bottom.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.MoveBottomButton = self.ServiceToolbar.addAction(MoveBottomIcon, 'Move to bottom')
self.ServiceToolbar.addSeparator()
NewServiceIcon = QtGui.QIcon()
NewServiceIcon.addPixmap(QtGui.QPixmap(":/services/service_new.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ServiceNewItem = self.ServiceToolbar.addAction(NewServiceIcon, 'New service')
OpenServiceIcon = QtGui.QIcon()
OpenServiceIcon.addPixmap(QtGui.QPixmap(":/services/service_open.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ServiceOpenItem = self.ServiceToolbar.addAction(OpenServiceIcon, 'Open service')
SaveServiceIcon = QtGui.QIcon()
SaveServiceIcon.addPixmap(QtGui.QPixmap(":/services/service_save.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ServiceSaveItem = self.ServiceToolbar.addAction(SaveServiceIcon, 'Save service')
self.ServiceToolbar.addSeparator()
self.ServiceThemeComboBox = QtGui.QComboBox(self.ServiceToolbar)
self.ServiceThemeComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.ServiceThemeComboBox.setObjectName("ServiceThemeComboBox")
self.ServiceThemeComboBox.addItem(QtCore.QString())
self.ServiceThemeComboBox.addItem(QtCore.QString())
self.ServiceThemeComboBox.addItem(QtCore.QString())
self.ServiceThemeWidget = QtGui.QWidgetAction(self.ServiceToolbar)
self.ServiceThemeWidget.setDefaultWidget(self.ServiceThemeComboBox)
self.ServiceToolbar.addAction(self.ServiceThemeWidget)
self.ServiceManagerLayout.addWidget(self.ServiceToolbar)
self.ServiceListView = QtGui.QListView(self.ServiceManagerContents)
self.ServiceListView.setObjectName("ServiceListView")
self.ServiceManagerLayout.addWidget(self.ServiceListView)
self.ServiceManagerDock.setWidget(self.ServiceManagerContents) self.ServiceManagerDock.setWidget(self.ServiceManagerContents)
self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock) self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ServiceManagerDock)
self.ThemeManagerDock = QtGui.QDockWidget(self.main_window) self.ThemeManagerDock = QtGui.QDockWidget(self.main_window)
@ -249,13 +200,13 @@ class MainWindow(object):
self.ThemeManagerDock.setWidget(self.ThemeManagerContents) self.ThemeManagerDock.setWidget(self.ThemeManagerContents)
self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock) self.main_window.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.ThemeManagerDock)
self.FileNewItem = QtGui.QAction(self.main_window) self.FileNewItem = QtGui.QAction(self.main_window)
self.FileNewItem.setIcon(NewServiceIcon) self.FileNewItem.setIcon(self.ServiceManagerContents.Toolbar.getIconFromTitle("New Service"))
self.FileNewItem.setObjectName("FileNewItem") self.FileNewItem.setObjectName("FileNewItem")
self.FileOpenItem = QtGui.QAction(self.main_window) self.FileOpenItem = QtGui.QAction(self.main_window)
self.FileOpenItem.setIcon(OpenServiceIcon) self.FileOpenItem.setIcon(self.ServiceManagerContents.Toolbar.getIconFromTitle("Open Service"))
self.FileOpenItem.setObjectName("FileOpenItem") self.FileOpenItem.setObjectName("FileOpenItem")
self.FileSaveItem = QtGui.QAction(self.main_window) self.FileSaveItem = QtGui.QAction(self.main_window)
self.FileSaveItem.setIcon(SaveServiceIcon) self.FileSaveItem.setIcon(self.ServiceManagerContents.Toolbar.getIconFromTitle("Save Service"))
self.FileSaveItem.setObjectName("FileSaveItem") self.FileSaveItem.setObjectName("FileSaveItem")
self.FileSaveAsItem = QtGui.QAction(self.main_window) self.FileSaveAsItem = QtGui.QAction(self.main_window)
self.FileSaveAsItem.setObjectName("FileSaveAsItem") self.FileSaveAsItem.setObjectName("FileSaveAsItem")
@ -392,16 +343,16 @@ class MainWindow(object):
self.HelpMenu.setTitle(QtGui.QApplication.translate("main_window", "&Help", None, QtGui.QApplication.UnicodeUTF8)) self.HelpMenu.setTitle(QtGui.QApplication.translate("main_window", "&Help", None, QtGui.QApplication.UnicodeUTF8))
self.MediaManagerDock.setWindowTitle(QtGui.QApplication.translate("main_window", "Media Manager", None, QtGui.QApplication.UnicodeUTF8)) self.MediaManagerDock.setWindowTitle(QtGui.QApplication.translate("main_window", "Media Manager", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceManagerDock.setWindowTitle(QtGui.QApplication.translate("main_window", "Service Manager", None, QtGui.QApplication.UnicodeUTF8)) self.ServiceManagerDock.setWindowTitle(QtGui.QApplication.translate("main_window", "Service Manager", None, QtGui.QApplication.UnicodeUTF8))
self.MoveTopButton.setText(QtGui.QApplication.translate("main_window", "Move To Top", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.MoveTopButton.setText(QtGui.QApplication.translate("main_window", "Move To Top", None, QtGui.QApplication.UnicodeUTF8))
self.MoveUpButton.setText(QtGui.QApplication.translate("main_window", "Move Up", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.MoveUpButton.setText(QtGui.QApplication.translate("main_window", "Move Up", None, QtGui.QApplication.UnicodeUTF8))
self.MoveDownButton.setText(QtGui.QApplication.translate("main_window", "Move Down", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.MoveDownButton.setText(QtGui.QApplication.translate("main_window", "Move Down", None, QtGui.QApplication.UnicodeUTF8))
self.MoveBottomButton.setText(QtGui.QApplication.translate("main_window", "Move To Bottom", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.MoveBottomButton.setText(QtGui.QApplication.translate("main_window", "Move To Bottom", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceNewItem.setText(QtGui.QApplication.translate("main_window", "New Service", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.NewItem.setText(QtGui.QApplication.translate("main_window", "New Service", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceOpenItem.setText(QtGui.QApplication.translate("main_window", "Open Service", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.OpenItem.setText(QtGui.QApplication.translate("main_window", "Open Service", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceSaveItem.setText(QtGui.QApplication.translate("main_window", "Save Service", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.SaveItem.setText(QtGui.QApplication.translate("main_window", "Save Service", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceThemeComboBox.setItemText(0, QtGui.QApplication.translate("main_window", "African Sunset", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.ThemeComboBox.setItemText(0, QtGui.QApplication.translate("main_window", "African Sunset", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceThemeComboBox.setItemText(1, QtGui.QApplication.translate("main_window", "Snowy Mountains", None, QtGui.QApplication.UnicodeUTF8)) # self.ServiceManagerContents.ThemeComboBox.setItemText(1, QtGui.QApplication.translate("main_window", "Snowy Mountains", None, QtGui.QApplication.UnicodeUTF8))
self.ServiceThemeComboBox.setItemText(2, QtGui.QApplication.translate("main_window", "Wilderness", 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.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.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.ThemeEditItem.setText(QtGui.QApplication.translate("main_window", "Edit Theme", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -0,0 +1,65 @@
# -*- 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 PyQt4 import *
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
# from openlp.core.resources import *
# from openlp.core.ui import AboutForm, AlertForm, SettingsDialog, SlideController
from openlp.core.lib import OpenLPToolbar
# from openlp.core import PluginManager
import logging
class ServiceManager(QWidget):
"""Manages the orders of service. 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"""
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("Move to top", ":/services/service_top.png")
self.Toolbar.addToolbarButton("Move up", ":/services/service_up.png")
self.Toolbar.addToolbarButton("Move down", ":/services/service_down.png")
self.Toolbar.addToolbarButton("Move to bottom", ":/services/service_bottom.png")
self.Toolbar.addSeparator()
self.Toolbar.addToolbarButton("New Service", ":/services/service_new.png")
self.Toolbar.addToolbarButton("Save Service", ":/services/service_save.png")
self.Toolbar.addSeparator()
self.ThemeComboBox = QtGui.QComboBox(self.Toolbar)
self.ThemeComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.ThemeComboBox.addItem(QtCore.QString())
self.ThemeComboBox.addItem(QtCore.QString())
self.ThemeComboBox.addItem(QtCore.QString())
self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar)
self.ThemeWidget.setDefaultWidget(self.ThemeComboBox)
self.Toolbar.addAction(self.ThemeWidget)
self.Layout.addWidget(self.Toolbar)
self.ListView = QtGui.QListView(self)
self.Layout.addWidget(self.ListView)