2008-11-22 15:16:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-29 05:36:16 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
|
|
|
OpenLP - Open Source Lyrics Projection
|
2009-02-21 19:23:54 +00:00
|
|
|
Copyright (c) 2008-2009 Raoul Snyman
|
|
|
|
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
|
2008-11-22 15:16:02 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2008-11-23 21:24:58 +00:00
|
|
|
import types
|
2008-11-22 15:16:02 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2009-06-26 16:17:55 +00:00
|
|
|
|
2009-02-21 19:23:54 +00:00
|
|
|
from openlp.core.lib.toolbar import *
|
2009-06-23 20:53:06 +00:00
|
|
|
from openlp.core.lib import translate
|
2009-06-23 20:59:38 +00:00
|
|
|
from listwithpreviews import ListWithPreviews
|
|
|
|
from serviceitem import ServiceItem
|
2009-06-26 16:17:55 +00:00
|
|
|
|
2008-11-22 15:16:02 +00:00
|
|
|
class MediaManagerItem(QtGui.QWidget):
|
|
|
|
"""
|
|
|
|
MediaManagerItem is a helper widget for plugins.
|
|
|
|
"""
|
2009-06-23 20:59:38 +00:00
|
|
|
global log
|
|
|
|
log = logging.getLogger(u'MediaManagerItem')
|
|
|
|
log.info(u'Media Item loaded')
|
|
|
|
|
2009-03-02 22:12:14 +00:00
|
|
|
def __init__(self, parent=None, icon=None, title=None):
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
|
|
|
Constructor to create the media manager item.
|
|
|
|
"""
|
|
|
|
QtGui.QWidget.__init__(self)
|
2009-03-02 22:12:14 +00:00
|
|
|
self.parent = parent
|
2008-11-23 21:24:58 +00:00
|
|
|
if type(icon) is QtGui.QIcon:
|
2008-12-14 15:49:54 +00:00
|
|
|
self.icon = icon
|
2008-11-23 21:24:58 +00:00
|
|
|
elif type(icon) is types.StringType:
|
2008-12-14 15:49:54 +00:00
|
|
|
self.icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
|
2008-11-23 21:24:58 +00:00
|
|
|
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
2008-11-22 15:16:02 +00:00
|
|
|
else:
|
2008-12-14 15:49:54 +00:00
|
|
|
self.icon = None
|
2008-11-22 15:16:02 +00:00
|
|
|
if title is not None:
|
2008-12-14 15:49:54 +00:00
|
|
|
self.title = title
|
2008-11-22 21:41:20 +00:00
|
|
|
self.Toolbar = None
|
2009-06-26 16:39:16 +00:00
|
|
|
#self.ConfigSection = None
|
2009-02-21 19:23:54 +00:00
|
|
|
self.PageLayout = QtGui.QVBoxLayout(self)
|
|
|
|
self.PageLayout.setSpacing(0)
|
|
|
|
self.PageLayout.setMargin(0)
|
2009-03-02 21:57:49 +00:00
|
|
|
self.setupUi()
|
|
|
|
self.retranslateUi()
|
|
|
|
self.initialise()
|
|
|
|
|
|
|
|
def retranslateUi(self):
|
|
|
|
pass
|
|
|
|
|
2008-11-22 21:41:20 +00:00
|
|
|
def addToolbar(self):
|
|
|
|
"""
|
|
|
|
A method to help developers easily add a toolbar to the media manager
|
|
|
|
item.
|
|
|
|
"""
|
|
|
|
if self.Toolbar is None:
|
2009-05-20 20:17:20 +00:00
|
|
|
self.Toolbar = OpenLPToolbar(self)
|
2008-11-30 20:01:19 +00:00
|
|
|
self.PageLayout.addWidget(self.Toolbar)
|
2008-11-25 16:26:49 +00:00
|
|
|
|
|
|
|
def addToolbarButton(self, title, tooltip, icon, slot=None, objectname=None):
|
|
|
|
"""
|
|
|
|
A method to help developers easily add a button to the toolbar.
|
|
|
|
"""
|
2009-02-21 19:23:54 +00:00
|
|
|
# NB different order (when I broke this out, I wanted to not break compatability)
|
|
|
|
# but it makes sense for the icon to come before the tooltip (as you have to have an icon, but not neccesarily a tooltip)
|
|
|
|
self.Toolbar.addToolbarButton(title, icon, tooltip, slot, objectname)
|
2008-11-25 16:26:49 +00:00
|
|
|
|
2008-11-30 20:01:19 +00:00
|
|
|
def addToolbarSeparator(self):
|
|
|
|
"""
|
|
|
|
A very simple method to add a separator to the toolbar.
|
|
|
|
"""
|
|
|
|
self.Toolbar.addSeparator()
|
2009-03-02 21:57:49 +00:00
|
|
|
|
|
|
|
def contextMenuSeparator(self, base):
|
2009-05-20 20:17:20 +00:00
|
|
|
action = QtGui.QAction(u'', base)
|
2009-03-02 21:57:49 +00:00
|
|
|
action.setSeparator(True)
|
|
|
|
return action
|
|
|
|
|
|
|
|
def contextMenuAction(self, base, icon, text, slot):
|
|
|
|
"""
|
|
|
|
Utility method to help build context menus for plugins
|
|
|
|
"""
|
|
|
|
if type(icon) is QtGui.QIcon:
|
|
|
|
ButtonIcon = icon
|
2009-06-07 16:33:33 +00:00
|
|
|
elif type(icon) is types.StringType or type(icon) is types.UnicodeType:
|
2009-03-02 21:57:49 +00:00
|
|
|
ButtonIcon = QtGui.QIcon()
|
2009-05-20 20:17:20 +00:00
|
|
|
if icon.startswith(u':/'):
|
2009-03-02 21:57:49 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
action = QtGui.QAction(text, base)
|
|
|
|
action .setIcon(ButtonIcon)
|
2009-05-20 20:17:20 +00:00
|
|
|
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), slot)
|
2009-03-02 21:57:49 +00:00
|
|
|
return action
|
|
|
|
|
2009-06-26 16:17:55 +00:00
|
|
|
###########################################################################
|
2009-06-23 20:53:06 +00:00
|
|
|
### None of the following *need* to be used, feel free to override
|
|
|
|
### them cmopletely in your plugin's implementation. Alternatively, call them from your
|
|
|
|
### plugin before or after you've done etra things that you need to.
|
|
|
|
### in order for them to work, you need to have setup
|
2009-06-24 20:15:24 +00:00
|
|
|
# self.TranslationContext
|
|
|
|
# self.PluginTextShort # eg "Image" for the image plugin
|
|
|
|
# self.ConfigSection - where the items in the media manager are stored
|
|
|
|
# this could potentially be self.PluginTextShort.lower()
|
2009-06-24 19:36:33 +00:00
|
|
|
#
|
2009-06-24 20:15:24 +00:00
|
|
|
# self.OnNewPrompt=u'Select Image(s)'
|
|
|
|
# self.OnNewFileMasks=u'Images (*.jpg *jpeg *.gif *.png *.bmp)'
|
2009-06-24 19:36:33 +00:00
|
|
|
# assumes that the new action is to load a file. If not, override onnew
|
2009-06-24 20:15:24 +00:00
|
|
|
# self.ListViewWithDnD_class - there is a base list class with DnD assigned to it (openlp.core.lib.BaseListWithDnD())
|
|
|
|
# each plugin needs to inherit a class from this and pass that *class* (not an instance) to here
|
|
|
|
# via the ListViewWithDnD_class member
|
2009-06-23 20:53:06 +00:00
|
|
|
# The assumption is that given that at least two plugins are of the form
|
|
|
|
# "text with an icon" then all this will help
|
|
|
|
# even for plugins of another sort, the setup of the right-click menu, common toolbar
|
|
|
|
# will help to keep things consistent and ease the creation of new plugins
|
2009-06-26 16:39:16 +00:00
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
# also a set of completely consistent action anesm then exist
|
|
|
|
# (onPreviewClick() is always called that, rather than having the
|
|
|
|
# name of the plugin added in as well... I regard that as a
|
|
|
|
# feature, I guess others might differ!)
|
2009-06-26 16:39:16 +00:00
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def setupUi(self):
|
|
|
|
# Add a toolbar
|
|
|
|
self.addToolbar()
|
|
|
|
# Create buttons for the toolbar
|
|
|
|
## New Song Button ##
|
|
|
|
self.addToolbarButton(
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, u'Load '+self.PluginTextShort),
|
|
|
|
translate(self.TranslationContext, u'Load item into openlp.org'),
|
2009-06-23 20:53:06 +00:00
|
|
|
u':/images/image_load.png', self.onNewClick, u'ImageNewItem')
|
|
|
|
## Delete Song Button ##
|
|
|
|
self.addToolbarButton(
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, u'Delete '+self.PluginTextShort),
|
|
|
|
translate(self.TranslationContext, u'Delete the selected item'),
|
2009-06-23 20:53:06 +00:00
|
|
|
u':/images/image_delete.png', self.onDeleteClick, u'DeleteItem')
|
|
|
|
## Separator Line ##
|
|
|
|
self.addToolbarSeparator()
|
|
|
|
## Preview Button ##
|
|
|
|
self.addToolbarButton(
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, u'Preview '+self.PluginTextShort),
|
|
|
|
translate(self.TranslationContext, u'Preview the selected item'),
|
2009-06-23 20:53:06 +00:00
|
|
|
u':/system/system_preview.png', self.onPreviewClick, u'PreviewItem')
|
|
|
|
## Live Button ##
|
|
|
|
self.addToolbarButton(
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, u'Go Live'),
|
|
|
|
translate(self.TranslationContext, u'Send the selected item live'),
|
2009-06-23 20:53:06 +00:00
|
|
|
u':/system/system_live.png', self.onLiveClick, u'LiveItem')
|
|
|
|
## Add Button ##
|
|
|
|
self.addToolbarButton(
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, u'Add '+self.PluginTextShort+u' To Service'),
|
|
|
|
translate(self.TranslationContext, u'Add the selected item(s) to the service'),
|
|
|
|
u':/system/system_add.png', self.onAddClick, self.PluginTextShort+u'AddItem')
|
|
|
|
#Add the List widget
|
|
|
|
self.ListView = self.ListViewWithDnD_class()
|
|
|
|
self.ListView.uniformItemSizes = True
|
|
|
|
self.ListData = ListWithPreviews()
|
|
|
|
self.ListView.setModel(self.ListData)
|
|
|
|
self.ListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
|
|
|
|
self.ListView.setSpacing(1)
|
|
|
|
self.ListView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
|
|
|
|
self.ListView.setAlternatingRowColors(True)
|
|
|
|
self.ListView.setDragEnabled(True)
|
|
|
|
self.ListView.setObjectName(self.PluginTextShort+u'ListView')
|
|
|
|
self.PageLayout.addWidget(self.ListView)
|
2009-06-23 20:53:06 +00:00
|
|
|
#define and add the context menu
|
2009-06-24 20:15:24 +00:00
|
|
|
self.ListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
|
|
|
|
self.ListView.addAction(self.contextMenuAction(
|
|
|
|
self.ListView, ':/system/system_preview.png',
|
|
|
|
translate(self.TranslationContext, u'&Preview '+self.PluginTextShort),
|
2009-06-23 20:53:06 +00:00
|
|
|
self.onPreviewClick))
|
2009-06-24 20:15:24 +00:00
|
|
|
self.ListView.addAction(self.contextMenuAction(
|
|
|
|
self.ListView, ':/system/system_live.png',
|
|
|
|
translate(self.TranslationContext, u'&Show Live'),
|
2009-06-23 20:53:06 +00:00
|
|
|
self.onLiveClick))
|
2009-06-24 20:15:24 +00:00
|
|
|
self.ListView.addAction(self.contextMenuAction(
|
|
|
|
self.ListView, ':/system/system_add.png',
|
|
|
|
translate(self.TranslationContext, u'&Add to Service'),
|
2009-06-23 20:53:06 +00:00
|
|
|
self.onAddClick))
|
2009-06-24 20:15:24 +00:00
|
|
|
QtCore.QObject.connect(self.ListView,
|
2009-06-23 20:53:06 +00:00
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onPreviewClick)
|
|
|
|
|
|
|
|
def initialise(self):
|
2009-06-24 20:15:24 +00:00
|
|
|
self.loadList(self.parent.config.load_list(self.ConfigSection))
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def onNewClick(self):
|
|
|
|
files = QtGui.QFileDialog.getOpenFileNames(None,
|
2009-06-24 20:15:24 +00:00
|
|
|
translate(self.TranslationContext, self.OnNewPrompt),
|
2009-06-23 20:53:06 +00:00
|
|
|
self.parent.config.get_last_dir(),
|
2009-06-24 20:15:24 +00:00
|
|
|
self.OnNewFileMasks)
|
2009-06-23 20:53:06 +00:00
|
|
|
log.info(u'New files(s)', unicode(files))
|
|
|
|
if len(files) > 0:
|
|
|
|
self.loadList(files)
|
|
|
|
dir, filename = os.path.split(unicode(files[0]))
|
|
|
|
self.parent.config.set_last_dir(dir)
|
2009-06-24 20:15:24 +00:00
|
|
|
self.parent.config.set_list(self.ConfigSection, self.ListData.getFileList())
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def loadList(self, list):
|
|
|
|
for file in list:
|
2009-06-24 20:15:24 +00:00
|
|
|
self.ListData.addRow(file)
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def onDeleteClick(self):
|
2009-06-24 20:15:24 +00:00
|
|
|
indexes = self.ListView.selectedIndexes()
|
2009-06-23 20:53:06 +00:00
|
|
|
for index in indexes:
|
|
|
|
current_row = int(index.row())
|
2009-06-24 20:15:24 +00:00
|
|
|
self.ListData.removeRow(current_row)
|
|
|
|
self.parent.config.set_list(self.ConfigSection, self.ListData.getFileList())
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def generateSlideData(self):
|
2009-06-26 16:17:55 +00:00
|
|
|
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs to be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def onPreviewClick(self):
|
2009-06-24 20:15:24 +00:00
|
|
|
log.debug(self.PluginTextShort+u'Preview Requested')
|
2009-06-23 20:53:06 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
|
|
|
service_item.addIcon(u':/media/media_image.png')
|
|
|
|
self.generateSlideData(service_item)
|
|
|
|
self.parent.preview_controller.addServiceItem(service_item)
|
|
|
|
|
|
|
|
def onLiveClick(self):
|
2009-06-24 20:15:24 +00:00
|
|
|
log.debug(self.PluginTextShort+u' Live Requested')
|
2009-06-23 20:53:06 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
|
|
|
service_item.addIcon(u':/media/media_image.png')
|
|
|
|
self.generateSlideData(service_item)
|
|
|
|
self.parent.live_controller.addServiceItem(service_item)
|
|
|
|
|
|
|
|
def onAddClick(self):
|
2009-06-24 20:15:24 +00:00
|
|
|
log.debug(self.PluginTextShort+u' Add Requested')
|
2009-06-23 20:53:06 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
|
|
|
service_item.addIcon(u':/media/media_image.png')
|
|
|
|
self.generateSlideData(service_item)
|
|
|
|
self.parent.service_manager.addServiceItem(service_item)
|