1
0
mirror of https://gitlab.com/openlp/openlp.git synced 2024-09-28 19:07:35 +00:00
openlp/openlp/plugins/media/lib/mediaitem.py

169 lines
7.5 KiB
Python
Raw Normal View History

2009-05-15 05:15:53 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-03-21 23:58:01 +00:00
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
2009-05-15 05:15:53 +00:00
import logging
import os
from PyQt4 import QtCore, QtGui
2010-04-03 07:10:31 +00:00
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
2010-06-30 16:30:25 +00:00
ItemCapabilities, SettingsManager, translate, check_item_selected, \
context_menu_action
2010-02-27 09:55:44 +00:00
log = logging.getLogger(__name__)
class MediaListView(BaseListWithDnD):
def __init__(self, parent=None):
self.PluginName = u'Media'
BaseListWithDnD.__init__(self, parent)
2009-05-15 05:15:53 +00:00
class MediaMediaItem(MediaManagerItem):
"""
This is the custom media manager item for Media Slides.
2009-05-15 05:15:53 +00:00
"""
2010-02-27 09:55:44 +00:00
log.info(u'%s MediaMediaItem loaded', __name__)
2009-05-15 05:15:53 +00:00
def __init__(self, parent, icon, title):
2009-10-28 01:36:24 +00:00
self.PluginNameShort = u'Media'
self.IconPath = u'images/image'
2010-04-30 16:30:25 +00:00
self.background = False
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = MediaListView
2010-04-27 16:27:57 +00:00
self.PreviewFunction = QtGui.QPixmap(
u':/media/media_video.png').toImage()
2009-05-15 05:15:53 +00:00
MediaManagerItem.__init__(self, parent, icon, title)
2010-04-06 19:16:14 +00:00
self.singleServiceItem = False
2009-11-03 01:38:15 +00:00
self.ServiceItemIconName = u':/media/media_video.png'
2009-05-15 05:15:53 +00:00
def initPluginNameVisible(self):
self.PluginNameVisible = translate('MediaPlugin.MediaItem', 'Media')
2009-05-15 05:15:53 +00:00
2009-10-31 16:17:26 +00:00
def retranslateUi(self):
self.OnNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
self.OnNewFileMasks = translate('MediaPlugin.MediaItem',
u'Videos (%s);;'
u'Audio (%s);;'
u'All files (*)' % (self.parent.video_list, self.parent.audio_list))
2009-09-26 09:11:39 +00:00
def requiredIcons(self):
MediaManagerItem.requiredIcons(self)
self.hasFileIcon = True
self.hasNewIcon = False
self.hasEditIcon = False
2010-06-30 16:30:25 +00:00
def addListViewToToolBar(self):
MediaManagerItem.addListViewToToolBar(self)
self.ListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.ListView.addAction(
context_menu_action(self.ListView, u':/slides/slide_blank.png',
translate('MediaPlugin.MediaItem', 'Replace Live Background'),
self.onReplaceClick))
2010-04-30 16:30:25 +00:00
def addEndHeaderBar(self):
self.ImageWidget = QtGui.QWidget(self)
sizePolicy = QtGui.QSizePolicy(
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.ImageWidget.sizePolicy().hasHeightForWidth())
self.ImageWidget.setSizePolicy(sizePolicy)
self.ImageWidget.setObjectName(u'ImageWidget')
#Replace backgrounds do not work at present so remove functionality.
2010-06-30 16:30:25 +00:00
self.blankButton = self.Toolbar.addToolbarButton(
u'Replace Background', u':/slides/slide_blank.png',
translate('MediaPlugin.MediaItem', 'Replace Live Background'),
self.onReplaceClick, False)
2010-04-30 16:30:25 +00:00
# Add the song widget to the page layout
self.PageLayout.addWidget(self.ImageWidget)
2010-06-30 16:30:25 +00:00
def onReplaceClick(self):
# if self.background:
# self.background = False
# Receiver.send_message(u'videodisplay_stop')
# else:
# self.background = True
2010-06-30 16:30:25 +00:00
if not self.ListView.selectedIndexes():
QtGui.QMessageBox.information(self,
translate('MediaPlugin.MediaItem', 'No item selected'),
translate('MediaPlugin.MediaItem',
'You must select one item'))
return
item = self.ListView.currentItem()
if item is None:
return False
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
print filename
self.parent.live_controller.displayManager.displayVideo(filename)
# items = self.ListView.selectedIndexes()
# for item in items:
# bitem = self.ListView.item(item.row())
# filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
# Receiver.send_message(u'videodisplay_background', filename)
2010-04-30 16:30:25 +00:00
def generateSlideData(self, service_item, item=None):
2010-04-05 07:22:21 +00:00
if item is None:
item = self.ListView.currentItem()
if item is None:
return False
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
service_item.title = unicode(
translate('MediaPlugin.MediaItem', 'Media'))
service_item.add_capability(ItemCapabilities.RequiresMedia)
2010-04-05 07:22:21 +00:00
frame = u':/media/image_clapperboard.png'
(path, name) = os.path.split(filename)
service_item.add_from_command(path, name, frame)
return True
2009-05-15 05:15:53 +00:00
def initialise(self):
self.ListView.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
2010-05-25 16:16:43 +00:00
self.ListView.setIconSize(QtCore.QSize(88, 50))
2010-06-08 15:38:09 +00:00
self.loadList(SettingsManager.load_list(self.settingsSection,
self.settingsSection))
def onDeleteClick(self):
"""
Remove a media item from the list
"""
2010-06-24 15:50:40 +00:00
if check_item_selected(self.ListView, translate('MediaPlugin.MediaItem',
'You must select an item to delete.')):
row_list = [item.row() for item in self.ListView.selectedIndexes()]
row_list.sort(reverse=True)
for row in row_list:
self.ListView.takeItem(row)
2010-06-28 20:00:35 +00:00
SettingsManager.set_list(self.settingsSection,
self.settingsSection, self.getFileList())
def loadList(self, list):
for file in list:
2010-05-27 14:41:47 +00:00
filename = os.path.split(unicode(file))[1]
item_name = QtGui.QListWidgetItem(filename)
img = QtGui.QPixmap(u':/media/media_video.png').toImage()
item_name.setIcon(build_icon(img))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
2010-04-28 14:17:42 +00:00
self.ListView.addItem(item_name)