openlp/openlp/plugins/media/lib/mediaitem.py

111 lines
4.9 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, \
ItemCapabilities
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'
2009-10-07 16:16:21 +00:00
self.ConfigSection = u'media'
2009-10-30 17:44:16 +00:00
self.ConfigSection = title
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = MediaListView
self.PreviewFunction = QtGui.QPixmap(u':/media/media_video.png').toImage()
2009-05-15 05:15:53 +00:00
MediaManagerItem.__init__(self, parent, icon, title)
2009-11-03 01:38:15 +00:00
self.ServiceItemIconName = u':/media/media_video.png'
2010-02-16 18:51:41 +00:00
self.MainDisplay = self.parent.maindisplay
2009-05-15 05:15:53 +00:00
def initPluginNameVisible(self):
self.PluginNameVisible = self.trUtf8('Media')
2009-05-15 05:15:53 +00:00
2009-10-31 16:17:26 +00:00
def retranslateUi(self):
self.OnNewPrompt = self.trUtf8('Select Media')
2010-02-27 14:57:33 +00:00
self.OnNewFileMasks = self.trUtf8('Videos (%s);;'
'Audio (%s);;'
'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
def generateSlideData(self, service_item, item=None):
items = self.ListView.selectedIndexes()
if len(items) > 1:
return False
service_item.title = unicode(self.trUtf8('Media'))
service_item.add_capability(ItemCapabilities.RequiresMedia)
for item in items:
bitem = self.ListView.item(item.row())
filename = unicode((bitem.data(QtCore.Qt.UserRole)).toString())
frame = u':/media/image_clapperboard.png'
(path, name) = os.path.split(filename)
2009-11-01 16:06:59 +00:00
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)
self.ListView.setIconSize(QtCore.QSize(88,50))
self.loadList(self.parent.config.load_list(self.ConfigSection))
def onDeleteClick(self):
item = self.ListView.currentItem()
2009-11-03 19:01:53 +00:00
if item:
row = self.ListView.row(item)
self.ListView.takeItem(row)
self.parent.config.set_list(
2009-09-15 21:59:20 +00:00
self.ConfigSection, self.getFileList())
def loadList(self, list):
for file in list:
(path, filename) = os.path.split(unicode(file))
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))
self.ListView.addItem(item_name)