Plugin cleanups - Image and Audit

This commit is contained in:
Tim Bentley 2009-09-21 20:23:51 +01:00
parent 38e0c1bc77
commit d23f03bf9c
7 changed files with 9 additions and 137 deletions

View File

@ -127,7 +127,6 @@ from renderer import Renderer
from rendermanager import RenderManager
from mediamanageritem import MediaManagerItem
from baselistwithdnd import BaseListWithDnD
from listwithpreviews import ListWithPreviews
__all__ = [ 'translate', 'file_to_xml', 'str_to_bool',
'contextMenuAction', 'contextMenuSeparator','ServiceItem']

View File

@ -1,122 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2009 Raoul Snyman #
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
# --------------------------------------------------------------------------- #
# 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
from PyQt4 import QtCore, QtGui
class ListWithPreviews(QtCore.QAbstractListModel):
"""
An abstract list of unicodeings and the preview icon to go with them
"""
global log
log = logging.getLogger(u'ListWithPreviews')
log.info(u'started')
def __init__(self, new_preview_function=None):
QtCore.QAbstractListModel.__init__(self)
# will be a list of (full filename, QPixmap, shortname) tuples
self.items = []
self.rowheight = 50
self.maximagewidth = self.rowheight * 16 / 9.0;
self.preview_function = new_preview_function
def make_preview(self, filename):
if os.path.exists(filename):
if self.preview_function is not None:
preview=self.preview_function(filename)
else:
preview = QtGui.QImage(filename)
else:
preview = None
if preview is not None:
w = self.maximagewidth;
h = self.rowheight
preview = preview.scaled(w, h, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
realw = preview.width();
realh = preview.height()
# and move it to the centre of the preview space
p = QtGui.QImage(w, h, QtGui.QImage.Format_ARGB32_Premultiplied)
p.fill(QtCore.Qt.transparent)
painter = QtGui.QPainter(p)
painter.drawImage((w-realw) / 2, (h-realh) / 2, preview)
else:
w = self.maximagewidth;
h = self.rowheight
p = QtGui.QImage(w, h, QtGui.QImage.Format_ARGB32_Premultiplied)
p.fill(QtCore.Qt.transparent)
return p
def rowCount(self, parent):
return len(self.items)
def insertRow(self, row, filename):
self.beginInsertRows(QtCore.QModelIndex(), row, row)
#log.info(u'insert row %d:%s' % (row,filename))
# get short filename to display next to image
filename = unicode(filename)
(prefix, shortfilename) = os.path.split(filename)
#log.info(u'shortfilename=%s' % (shortfilename))
# create a preview image
p=self.make_preview(filename)
# finally create the row
self.items.insert(row, (filename, p, shortfilename))
self.endInsertRows()
def removeRow(self, row):
self.beginRemoveRows(QtCore.QModelIndex(), row, row)
self.items.pop(row)
self.endRemoveRows()
def addRow(self, filename):
self.insertRow(len(self.items), filename)
def data(self, index, role):
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 QtCore.QVariant()
if role == QtCore.Qt.DisplayRole:
retval = self.items[row][2]
elif role == QtCore.Qt.DecorationRole:
retval = self.items[row][1]
elif role == QtCore.Qt.ToolTipRole:
retval = self.items[row][0]
else:
retval = QtCore.QVariant()
if type(retval) is not type(QtCore.QVariant):
return QtCore.QVariant(retval)
else:
return retval
def getFileList(self):
filelist = [item[0] for item in self.items];
return filelist
def getFilename(self, index):
row = index.row()
return self.items[row][0]

View File

@ -70,7 +70,7 @@ class AuditTab(SettingsTab):
self.AuditActive.setChecked(int(self.config.get_config(u'startup', 0)))
def onAuditFileButtonClicked(self):
filename = QtGui.QFileDialog.getOpenFileName(self, u'Audit File',self.AuditFileName.text())
filename = QtGui.QFileDialog.getSaveFileName(self, u'Audit File',self.AuditFileName.text())
if filename != u'':
filename = unicode(filename)
self.AuditFileName.setText(filename)

View File

@ -51,6 +51,3 @@ class ImagePlugin(Plugin):
# Create the MediaManagerItem object
self.media_item = ImageMediaItem(self, self.icon, u'Images')
return self.media_item
def initialise(self):
log.info(u'Plugin Initialising')

View File

@ -37,28 +37,29 @@ class ImageTab(SettingsTab):
self.setObjectName(u'ImageTab')
self.ImageLayout = QtGui.QFormLayout(self)
self.ImageLayout.setObjectName(u'ImageLayout')
self.ImageModeGroupBox = QtGui.QGroupBox(self)
self.ImageModeGroupBox.setObjectName(u'ImageModeGroupBox')
self.TimeoutLayout = QtGui.QHBoxLayout(self.ImageModeGroupBox)
self.ImageSettingsGroupBox = QtGui.QGroupBox(self)
self.ImageSettingsGroupBox.setObjectName(u'ImageSettingsGroupBox')
self.TimeoutLayout = QtGui.QHBoxLayout(self.ImageSettingsGroupBox)
self.TimeoutLayout.setSpacing(8)
self.TimeoutLayout.setMargin(0)
self.TimeoutLayout.setObjectName(u'TimeoutLayout')
self.TimeoutLabel = QtGui.QLabel(self.ImageModeGroupBox)
self.TimeoutLabel = QtGui.QLabel(self.ImageSettingsGroupBox)
self.TimeoutLabel.setObjectName(u'TimeoutLabel')
self.TimeoutLayout.addWidget(self.TimeoutLabel)
self.TimeoutSpinBox = QtGui.QSpinBox(self.ImageModeGroupBox)
self.TimeoutSpinBox = QtGui.QSpinBox(self.ImageSettingsGroupBox)
self.TimeoutSpinBox.setMaximum(180)
self.TimeoutSpinBox.setObjectName(u'TimeoutSpinBox')
self.TimeoutLayout.addWidget(self.TimeoutSpinBox)
self.TimeoutSpacer = QtGui.QSpacerItem(147, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.TimeoutLayout.addItem(self.TimeoutSpacer)
self.ImageLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.ImageModeGroupBox)
self.ImageLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.ImageSettingsGroupBox)
# Signals and slots
QtCore.QObject.connect(self.TimeoutSpinBox,
QtCore.SIGNAL(u'valueChanged(int)'), self.onTimeoutSpinBoxChanged)
def retranslateUi(self):
self.ImageSettingsGroupBox.setTitle(translate(u'ImageTab', u'Image Settings'))
self.TimeoutLabel.setText(translate(u'ImageTab', u'Slide Loop Delay:'))
self.TimeoutSpinBox.setSuffix(translate(u'ImageTab', u's'))

View File

@ -118,7 +118,3 @@ class MediaMediaItem(MediaManagerItem):
item_name.setIcon(buildIcon(img))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)
# def onMediaAddClick(self):
# log.debug(u'Media Add Button pressed')
# pass

View File

@ -27,6 +27,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab
from openlp.plugins.media.lib import MediaTab,MediaMediaItem
class MediaPlugin(Plugin):
def __init__(self, plugin_helpers):