forked from openlp/openlp
Update Image thumbnail if original has changed
This commit is contained in:
parent
fa8c543556
commit
f5a9f9ed89
|
@ -352,6 +352,25 @@ class MediaManagerItem(QtGui.QWidget):
|
|||
count += 1
|
||||
return filelist
|
||||
|
||||
def validate(self, file, thumb):
|
||||
"""
|
||||
Validates to see if the file still exists or
|
||||
thumbnail is up to date
|
||||
"""
|
||||
filedate = os.stat(file).st_mtime
|
||||
thumbdate = os.stat(thumb).st_mtime
|
||||
#if file updated rebuild icon
|
||||
if filedate > thumbdate:
|
||||
print "rebuild"
|
||||
self.icon_from_file(file, thumb)
|
||||
|
||||
def icon_from_file(self, file, thumb):
|
||||
icon = build_icon(unicode(file))
|
||||
pixmap = icon.pixmap(QtCore.QSize(88,50))
|
||||
ext = os.path.splitext(thumb)[1].lower()
|
||||
pixmap.save(thumb, ext[1:])
|
||||
return icon
|
||||
|
||||
def loadList(self, list):
|
||||
raise NotImplementedError(u'MediaManagerItem.loadList needs to be '
|
||||
u'defined by the plugin')
|
||||
|
|
|
@ -121,15 +121,14 @@ class ImageMediaItem(MediaManagerItem):
|
|||
|
||||
def loadList(self, list):
|
||||
for file in list:
|
||||
print file
|
||||
(path, filename) = os.path.split(unicode(file))
|
||||
thumb = os.path.join(self.servicePath, filename)
|
||||
if os.path.exists(thumb):
|
||||
self.validate(file, thumb)
|
||||
icon = build_icon(thumb)
|
||||
else:
|
||||
icon = build_icon(unicode(file))
|
||||
pixmap = icon.pixmap(QtCore.QSize(88,50))
|
||||
ext = os.path.splitext(thumb)[1].lower()
|
||||
pixmap.save(thumb, ext[1:])
|
||||
icon = self.icon_from_file(file, thumb)
|
||||
item_name = QtGui.QListWidgetItem(filename)
|
||||
item_name.setIcon(icon)
|
||||
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
||||
|
|
Loading…
Reference in New Issue