Finish off Theme thumbnail performance improvements

This commit is contained in:
Tim Bentley 2010-01-21 19:41:17 +00:00
parent a69ba0a151
commit af3f69afce
1 changed files with 10 additions and 4 deletions

View File

@ -108,6 +108,9 @@ class ThemeManager(QtGui.QWidget):
self.themelist = [] self.themelist = []
self.path = os.path.join(ConfigHelper.get_data_path(), u'themes') self.path = os.path.join(ConfigHelper.get_data_path(), u'themes')
self.checkThemesExists(self.path) self.checkThemesExists(self.path)
self.thumbPath = os.path.join(self.path, u'.thumbnails')
print self.thumbPath
self.checkThemesExists(self.thumbPath)
self.amendThemeForm.path = self.path self.amendThemeForm.path = self.path
# Last little bits of setting up # Last little bits of setting up
self.config = PluginConfig(u'themes') self.config = PluginConfig(u'themes')
@ -185,7 +188,7 @@ class ThemeManager(QtGui.QWidget):
self.ThemeListWidget.takeItem(row) self.ThemeListWidget.takeItem(row)
try: try:
os.remove(os.path.join(self.path, th)) os.remove(os.path.join(self.path, th))
os.remove(os.path.join(self.path, u'thumbs', th)) os.remove(os.path.join(self.thumbPath, th))
shutil.rmtree(os.path.join(self.path, theme)) shutil.rmtree(os.path.join(self.path, theme))
except: except:
#if not present do not worry #if not present do not worry
@ -260,15 +263,14 @@ class ThemeManager(QtGui.QWidget):
self.trUtf8('default')) self.trUtf8('default'))
else: else:
name = textName name = textName
thumb = os.path.join(self.path, u'thumbs', u'%s.png' %textName) thumb = os.path.join(self.thumbPath, u'%s.png' % textName)
item_name = QtGui.QListWidgetItem(name) item_name = QtGui.QListWidgetItem(name)
if os.path.exists(thumb): if os.path.exists(thumb):
icon = build_icon(thumb) icon = build_icon(thumb)
else: else:
icon = build_icon(theme) icon = build_icon(theme)
pixmap = icon.pixmap(QtCore.QSize(88,50)) pixmap = icon.pixmap(QtCore.QSize(88,50))
ext = os.path.splitext(thumb)[1].lower() pixmap.save(thumb, u'png')
pixmap.save(thumb, ext[1:])
item_name.setIcon(icon) item_name.setIcon(icon)
item_name.setData(QtCore.Qt.UserRole, item_name.setData(QtCore.Qt.UserRole,
QtCore.QVariant(textName)) QtCore.QVariant(textName))
@ -455,6 +457,10 @@ class ThemeManager(QtGui.QWidget):
if os.path.exists(samplepathname): if os.path.exists(samplepathname):
os.unlink(samplepathname) os.unlink(samplepathname)
frame.save(samplepathname, u'png') frame.save(samplepathname, u'png')
thumb = os.path.join(self.thumbPath, u'%s.png' % name)
icon = build_icon(frame)
pixmap = icon.pixmap(QtCore.QSize(88,50))
pixmap.save(thumb, u'png')
log.debug(u'Theme image written to %s', samplepathname) log.debug(u'Theme image written to %s', samplepathname)
def generateImage(self, themedata): def generateImage(self, themedata):