forked from openlp/openlp
MediaItem cleanups
This commit is contained in:
parent
a2994fb7d7
commit
d029fb81a7
openlp
@ -366,33 +366,34 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
count += 1
|
count += 1
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
def validate(self, file, thumb):
|
def validate(self, image, thumb):
|
||||||
"""
|
"""
|
||||||
Validates to see if the file still exists or thumbnail is up to date
|
Validates whether an image still exists and, if it does, is the
|
||||||
|
thumbnail representation of the image up to date.
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(file):
|
if not os.path.exists(image):
|
||||||
return False
|
return False
|
||||||
if os.path.exists(thumb):
|
if os.path.exists(thumb):
|
||||||
filedate = os.stat(file).st_mtime
|
imageDate = os.stat(image).st_mtime
|
||||||
thumbdate = os.stat(thumb).st_mtime
|
thumbDate = os.stat(thumb).st_mtime
|
||||||
# if file updated rebuild icon
|
# If image has been updated rebuild icon
|
||||||
if filedate > thumbdate:
|
if imageDate > thumbDate:
|
||||||
self.iconFromFile(file, thumb)
|
self.iconFromFile(image, thumb)
|
||||||
else:
|
else:
|
||||||
self.iconFromFile(file, thumb)
|
self.iconFromFile(image, thumb)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def iconFromFile(self, file, thumb):
|
def iconFromFile(self, image, thumb):
|
||||||
"""
|
"""
|
||||||
Create a thumbnail icon from a given file
|
Create a thumbnail icon from a given image.
|
||||||
|
|
||||||
``file``
|
``image``
|
||||||
The file to create the icon from
|
The image file to create the icon from.
|
||||||
|
|
||||||
``thumb``
|
``thumb``
|
||||||
The filename to save the thumbnail to
|
The filename to save the thumbnail to
|
||||||
"""
|
"""
|
||||||
icon = build_icon(unicode(file))
|
icon = build_icon(unicode(image))
|
||||||
pixmap = icon.pixmap(QtCore.QSize(88, 50))
|
pixmap = icon.pixmap(QtCore.QSize(88, 50))
|
||||||
ext = os.path.splitext(thumb)[1].lower()
|
ext = os.path.splitext(thumb)[1].lower()
|
||||||
pixmap.save(thumb, ext[1:])
|
pixmap.save(thumb, ext[1:])
|
||||||
@ -403,12 +404,16 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
u'defined by the plugin')
|
u'defined by the plugin')
|
||||||
|
|
||||||
def onNewClick(self):
|
def onNewClick(self):
|
||||||
raise NotImplementedError(u'MediaManagerItem.onNewClick needs to be '
|
"""
|
||||||
u'defined by the plugin')
|
Hook for plugins to define behaviour for adding new items.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def onEditClick(self):
|
def onEditClick(self):
|
||||||
raise NotImplementedError(u'MediaManagerItem.onEditClick needs to be '
|
"""
|
||||||
u'defined by the plugin')
|
Hook for plugins to define behaviour for editing items.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def onDeleteClick(self):
|
def onDeleteClick(self):
|
||||||
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to '
|
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to '
|
||||||
|
@ -123,19 +123,19 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.settingsSection, self.getFileList())
|
self.settingsSection, self.getFileList())
|
||||||
|
|
||||||
def loadList(self, list):
|
def loadList(self, list):
|
||||||
for file in list:
|
for imageFile in list:
|
||||||
filename = os.path.split(unicode(file))[1]
|
filename = os.path.split(unicode(imageFile))[1]
|
||||||
thumb = os.path.join(self.servicePath, filename)
|
thumb = os.path.join(self.servicePath, filename)
|
||||||
if os.path.exists(thumb):
|
if os.path.exists(thumb):
|
||||||
if self.validate(file, thumb):
|
if self.validate(imageFile, thumb):
|
||||||
icon = build_icon(thumb)
|
icon = build_icon(thumb)
|
||||||
else:
|
else:
|
||||||
icon = build_icon(u':/general/general_delete.png')
|
icon = build_icon(u':/general/general_delete.png')
|
||||||
else:
|
else:
|
||||||
icon = self.iconFromFile(file, thumb)
|
icon = self.iconFromFile(imageFile, thumb)
|
||||||
item_name = QtGui.QListWidgetItem(filename)
|
item_name = QtGui.QListWidgetItem(filename)
|
||||||
item_name.setIcon(icon)
|
item_name.setIcon(icon)
|
||||||
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile))
|
||||||
self.listView.addItem(item_name)
|
self.listView.addItem(item_name)
|
||||||
|
|
||||||
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user