openlp/openlp/core/ui/thememanager.py

580 lines
26 KiB
Python
Raw Normal View History

2009-09-13 15:14:45 +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 #
2009-09-13 15:14:45 +00:00
# --------------------------------------------------------------------------- #
# 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 zipfile
import shutil
import logging
from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtCore, QtGui
2009-09-25 00:43:42 +00:00
from openlp.core.ui import AmendThemeForm
2009-09-13 15:14:45 +00:00
from openlp.core.theme import Theme
2010-04-27 16:27:57 +00:00
from openlp.core.lib import OpenLPToolbar, contextMenuAction, \
2010-01-24 23:16:15 +00:00
ThemeXML, str_to_bool, get_text_file_string, build_icon, Receiver, \
2010-06-08 15:38:09 +00:00
contextMenuSeparator, SettingsManager, translate
2010-04-27 16:27:57 +00:00
from openlp.core.utils import AppLocation
2009-09-13 15:14:45 +00:00
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2009-09-13 15:14:45 +00:00
class ThemeManager(QtGui.QWidget):
"""
Manages the orders of Theme.
"""
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.parent = parent
self.settingsSection = u'themes'
2009-09-13 15:14:45 +00:00
self.Layout = QtGui.QVBoxLayout(self)
self.Layout.setSpacing(0)
self.Layout.setMargin(0)
self.amendThemeForm = AmendThemeForm(self)
self.Toolbar = OpenLPToolbar(self)
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'New Theme'), u':/themes/theme_new.png',
translate(u'ThemeManager', u'Create a new theme'), self.onAddTheme)
2009-09-13 15:14:45 +00:00
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Edit Theme'),
u':/themes/theme_edit.png',
translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme)
2009-09-13 15:14:45 +00:00
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Delete Theme'),
u':/general/general_delete.png',
translate(u'ThemeManager', u'Delete a theme'), self.onDeleteTheme)
2009-09-13 15:14:45 +00:00
self.Toolbar.addSeparator()
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Import Theme'),
u':/general/general_import.png',
translate(u'ThemeManager', u'Import a theme'), self.onImportTheme)
2009-09-13 15:14:45 +00:00
self.Toolbar.addToolbarButton(
translate(u'ThemeManager', u'Export Theme'),
u':/general/general_export.png',
translate(u'ThemeManager', u'Export a theme'), self.onExportTheme)
2009-09-13 15:14:45 +00:00
self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar)
self.Layout.addWidget(self.Toolbar)
self.ThemeListWidget = QtGui.QListWidget(self)
self.ThemeListWidget.setAlternatingRowColors(True)
2010-05-25 16:16:43 +00:00
self.ThemeListWidget.setIconSize(QtCore.QSize(88, 50))
2009-09-13 15:14:45 +00:00
self.Layout.addWidget(self.ThemeListWidget)
2009-10-10 18:36:58 +00:00
self.ThemeListWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
2009-10-23 13:17:43 +00:00
self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget, u':/themes/theme_edit.png',
translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme))
2009-10-23 13:17:43 +00:00
self.ThemeListWidget.addAction(
2009-11-03 20:04:38 +00:00
contextMenuSeparator(self.ThemeListWidget))
2009-10-23 13:17:43 +00:00
self.ThemeListWidget.addAction(
2009-11-03 20:04:38 +00:00
contextMenuAction(self.ThemeListWidget,
u':/general/general_delete.png',
translate(u'ThemeManager', u'Delete theme'),
2009-11-03 20:04:38 +00:00
self.onDeleteTheme))
2009-10-23 13:17:43 +00:00
self.ThemeListWidget.addAction(
2009-11-03 20:04:38 +00:00
contextMenuAction(self.ThemeListWidget,
u':/general/general_export.png',
translate(u'ThemeManager', u'Make Global'),
2009-11-03 20:04:38 +00:00
self.changeGlobalFromScreen))
self.ThemeListWidget.addAction(
contextMenuAction(self.ThemeListWidget,
u':/general/general_export.png',
translate(u'ThemeManager', u'Export theme'),
2010-06-08 15:38:09 +00:00
self.onExportTheme))
2009-11-03 20:04:38 +00:00
self.ThemeListWidget.addAction(
contextMenuSeparator(self.ThemeListWidget))
2009-09-13 15:14:45 +00:00
#Signals
QtCore.QObject.connect(self.ThemeListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.changeGlobalFromScreen)
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-16 07:31:01 +00:00
QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab)
2009-09-13 15:14:45 +00:00
#Variables
self.themelist = []
self.path = AppLocation.get_section_data_path(self.settingsSection)
2009-09-13 15:14:45 +00:00
self.checkThemesExists(self.path)
self.thumbPath = os.path.join(self.path, u'thumbnails')
self.checkThemesExists(self.thumbPath)
2009-09-13 15:14:45 +00:00
self.amendThemeForm.path = self.path
# Last little bits of setting up
2010-04-27 16:27:57 +00:00
self.global_theme = unicode(QtCore.QSettings().value(
self.settingsSection + u'/global theme',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(u'')).toString())
2009-09-13 15:14:45 +00:00
def changeGlobalFromTab(self, themeName):
log.debug(u'changeGlobalFromTab %s', themeName)
2009-09-21 17:56:36 +00:00
for count in range (0, self.ThemeListWidget.count()):
2009-09-13 15:14:45 +00:00
#reset the old name
item = self.ThemeListWidget.item(count)
2009-09-21 17:56:36 +00:00
oldName = item.text()
2009-09-13 15:14:45 +00:00
newName = unicode(item.data(QtCore.Qt.UserRole).toString())
if oldName != newName:
self.ThemeListWidget.item(count).setText(newName)
#Set the new name
2009-09-21 23:11:50 +00:00
if themeName == newName:
name = u'%s (%s)' % (newName,
translate(u'ThemeManager', u'default'))
2009-09-13 15:14:45 +00:00
self.ThemeListWidget.item(count).setText(name)
2009-10-10 18:36:58 +00:00
def changeGlobalFromScreen(self, index = -1):
2009-09-13 15:14:45 +00:00
log.debug(u'changeGlobalFromScreen %s', index)
2009-10-10 18:36:58 +00:00
selected_row = self.ThemeListWidget.currentRow()
2009-09-21 17:56:36 +00:00
for count in range (0, self.ThemeListWidget.count()):
2009-09-13 15:14:45 +00:00
item = self.ThemeListWidget.item(count)
2009-09-21 17:56:36 +00:00
oldName = item.text()
2009-09-13 15:14:45 +00:00
#reset the old name
if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()):
self.ThemeListWidget.item(count).setText(
unicode(item.data(QtCore.Qt.UserRole).toString()))
#Set the new name
2009-10-10 18:36:58 +00:00
if count == selected_row:
2009-09-13 15:14:45 +00:00
self.global_theme = unicode(
self.ThemeListWidget.item(count).text())
name = u'%s (%s)' % (self.global_theme,
translate(u'ThemeManager', u'default'))
2009-09-13 15:14:45 +00:00
self.ThemeListWidget.item(count).setText(name)
2010-04-28 14:17:42 +00:00
QtCore.QSettings().setValue(
self.settingsSection + u'/global theme',
2010-04-28 01:28:37 +00:00
QtCore.QVariant(self.global_theme))
2010-04-20 22:00:55 +00:00
Receiver.send_message(u'theme_update_global', self.global_theme)
2009-09-13 15:14:45 +00:00
self.pushThemes()
def onAddTheme(self):
theme = self.createThemeFromXml(self.baseTheme(), self.path)
self.amendThemeForm.loadTheme(theme)
2009-10-17 18:20:07 +00:00
self.saveThemeName = u''
2009-09-13 15:14:45 +00:00
self.amendThemeForm.exec_()
def onEditTheme(self):
item = self.ThemeListWidget.currentItem()
2009-11-03 18:14:25 +00:00
if item:
theme = self.getThemeData(
2009-09-13 15:14:45 +00:00
unicode(item.data(QtCore.Qt.UserRole).toString()))
self.amendThemeForm.loadTheme(theme)
2009-11-03 18:14:25 +00:00
self.saveThemeName = unicode(
item.data(QtCore.Qt.UserRole).toString())
2009-09-13 15:14:45 +00:00
self.amendThemeForm.exec_()
def onDeleteTheme(self):
2010-04-27 16:27:57 +00:00
self.global_theme = unicode(QtCore.QSettings().value(
self.settingsSection + u'/global theme',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(u'')).toString())
2009-09-13 15:14:45 +00:00
item = self.ThemeListWidget.currentItem()
2009-11-03 18:14:25 +00:00
if item:
2009-09-13 15:14:45 +00:00
theme = unicode(item.text())
# should be the same unless default
if theme != unicode(item.data(QtCore.Qt.UserRole).toString()):
2009-10-23 13:17:43 +00:00
QtGui.QMessageBox.critical(
self, translate(u'ThemeManager', u'Error'),
translate(u'ThemeManager',
u'You are unable to delete the default theme.'),
2009-09-13 15:14:45 +00:00
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
else:
for plugin in self.parent.plugin_manager.plugins:
if not plugin.can_delete_theme(theme):
2010-06-06 22:30:11 +00:00
QtGui.QMessageBox.critical(self,
translate(u'ThemeManager', u'Error'),
2010-06-06 22:30:11 +00:00
translate(u'ThemeManager',
u'Theme %s is use in %s plugin' % (theme,
2010-05-29 19:50:50 +00:00
plugin.name)))
return
if unicode(self.parent.ServiceManagerContents.ThemeComboBox.currentText()) == theme:
QtGui.QMessageBox.critical(
2010-06-08 15:38:09 +00:00
self, translate(u'ThemeManager',u'Error'),
translate(u'ThemeManager',
u'Theme %s is use by Service Manager' % theme),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
2009-09-13 15:14:45 +00:00
self.themelist.remove(theme)
2009-09-21 23:11:50 +00:00
th = theme + u'.png'
2009-09-13 15:14:45 +00:00
row = self.ThemeListWidget.row(item)
self.ThemeListWidget.takeItem(row)
try:
os.remove(os.path.join(self.path, th))
os.remove(os.path.join(self.thumbPath, th))
2009-09-13 15:14:45 +00:00
shutil.rmtree(os.path.join(self.path, theme))
2010-05-27 16:00:51 +00:00
except OSError:
2009-09-13 15:14:45 +00:00
#if not present do not worry
pass
# As we do not reload the themes push out the change
# Reaload the list as the internal lists and events need
# to be triggered
self.pushThemes()
def onExportTheme(self):
"""
Save the theme in a zip file
"""
item = self.ThemeListWidget.currentItem()
if item is None:
QtGui.QMessageBox.critical(self,
translate(u'ThemeManager', u'Error'),
translate(u'ThemeManager', u'You have not selected a theme.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
path = QtGui.QFileDialog.getExistingDirectory(self,
unicode(translate(u'ThemeManager', u'Save Theme - (%s)')) % theme,
SettingsManager.get_last_dir(self.settingsSection, 1))
path = unicode(path)
2009-11-07 00:00:36 +00:00
if path:
SettingsManager.set_last_dir(self.settingsSection, path, 1)
2009-09-21 17:56:36 +00:00
themePath = os.path.join(path, theme + u'.theme')
2009-11-07 00:00:36 +00:00
zip = None
try:
zip = zipfile.ZipFile(themePath, u'w')
source = os.path.join(self.path, theme)
2010-05-27 14:41:47 +00:00
for files in os.walk(source)[2]:
2009-11-07 00:00:36 +00:00
for name in files:
zip.write(
2010-04-28 14:17:42 +00:00
os.path.join(source, name),
os.path.join(theme, name))
2010-05-27 16:00:51 +00:00
except (IOError, OSError):
2009-11-07 00:00:36 +00:00
log.exception(u'Export Theme Failed')
finally:
if zip:
zip.close()
2009-09-13 15:14:45 +00:00
def onImportTheme(self):
2009-10-23 13:17:43 +00:00
files = QtGui.QFileDialog.getOpenFileNames(
self, translate(u'ThemeManager', u'Select Theme Import File'),
SettingsManager.get_last_dir(self.settingsSection), u'Theme (*.*)')
2009-09-13 15:14:45 +00:00
log.info(u'New Themes %s', unicode(files))
2010-03-09 19:43:11 +00:00
if files:
2009-09-13 15:14:45 +00:00
for file in files:
2010-04-28 14:17:42 +00:00
SettingsManager.set_last_dir(
self.settingsSection, unicode(file))
2009-09-13 15:14:45 +00:00
self.unzipTheme(file, self.path)
self.loadThemes()
def loadThemes(self):
"""
Loads the theme lists and triggers updates accross the whole system
using direct calls or core functions and events for the plugins.
2009-09-13 15:14:45 +00:00
The plugins will call back in to get the real list if they want it.
"""
log.debug(u'Load themes from dir')
self.themelist = []
self.ThemeListWidget.clear()
#root, dirs, files = os.walk(self.path)
dirList = os.listdir(self.path)
for name in dirList:
if name.endswith(u'.png'):
#check to see file is in theme root directory
theme = os.path.join(self.path, name)
if os.path.exists(theme):
textName = os.path.splitext(name)[0]
if textName == self.global_theme:
name = u'%s (%s)' % (textName,
translate(u'ThemeManager', u'default'))
else:
name = textName
thumb = os.path.join(self.thumbPath, u'%s.png' % textName)
item_name = QtGui.QListWidgetItem(name)
if os.path.exists(thumb):
icon = build_icon(thumb)
else:
icon = build_icon(theme)
2010-05-25 16:16:43 +00:00
pixmap = icon.pixmap(QtCore.QSize(88, 50))
pixmap.save(thumb, u'png')
item_name.setIcon(icon)
item_name.setData(QtCore.Qt.UserRole,
QtCore.QVariant(textName))
self.ThemeListWidget.addItem(item_name)
self.themelist.append(textName)
2009-09-13 15:14:45 +00:00
self.pushThemes()
def pushThemes(self):
2010-04-30 21:00:17 +00:00
Receiver.send_message(u'theme_update_list', self.getThemes())
2009-09-13 15:14:45 +00:00
def getThemes(self):
return self.themelist
def getThemeData(self, themename):
log.debug(u'getthemedata for theme %s', themename)
xml_file = os.path.join(self.path, unicode(themename),
unicode(themename) + u'.xml')
xml = get_text_file_string(xml_file)
2009-11-06 02:12:56 +00:00
if not xml:
2009-10-29 13:58:03 +00:00
xml = self.baseTheme()
return self.createThemeFromXml(xml, self.path)
2009-09-13 15:14:45 +00:00
def checkThemesExists(self, dir):
log.debug(u'check themes')
2009-11-03 15:13:52 +00:00
if not os.path.exists(dir):
2009-09-13 15:14:45 +00:00
os.mkdir(dir)
def unzipTheme(self, filename, dir):
"""
Unzip the theme, remove the preview file if stored
Generate a new preview fileCheck the XML theme version and upgrade if
necessary.
"""
log.debug(u'Unzipping theme %s', filename)
filename = unicode(filename)
2009-11-07 00:00:36 +00:00
zip = None
outfile = None
try:
zip = zipfile.ZipFile(filename)
2009-11-07 00:00:36 +00:00
filexml = None
themename = None
for file in zip.namelist():
osfile = unicode(QtCore.QDir.toNativeSeparators(file))
2010-02-21 23:05:03 +00:00
theme_dir = None
if osfile.endswith(os.path.sep):
theme_dir = os.path.join(dir, osfile)
2009-11-07 00:00:36 +00:00
if not os.path.exists(theme_dir):
os.mkdir(os.path.join(dir, osfile))
2009-11-07 00:00:36 +00:00
else:
fullpath = os.path.join(dir, osfile)
names = osfile.split(os.path.sep)
2009-11-07 00:00:36 +00:00
if len(names) > 1:
# not preview file
if themename is None:
themename = names[0]
2010-02-21 23:05:03 +00:00
if theme_dir is None:
theme_dir = os.path.join(dir, names[0])
if not os.path.exists(theme_dir):
os.mkdir(os.path.join(dir, names[0]))
2009-11-07 00:00:36 +00:00
xml_data = zip.read(file)
if os.path.splitext(file)[1].lower() in [u'.xml']:
if self.checkVersion1(xml_data):
# upgrade theme xml
filexml = self.migrateVersion122(filename,
fullpath, xml_data)
else:
filexml = xml_data
outfile = open(fullpath, u'w')
outfile.write(filexml)
else:
2010-02-22 16:57:08 +00:00
outfile = open(fullpath, u'wb')
2009-11-07 00:00:36 +00:00
outfile.write(zip.read(file))
self.generateAndSaveImage(dir, themename, filexml)
2010-05-27 16:00:51 +00:00
except IOError:
2009-10-23 13:17:43 +00:00
QtGui.QMessageBox.critical(
self, translate(u'ThemeManager', u'Error'),
2010-06-06 22:44:49 +00:00
translate(u'ThemeManager', u'File is not a valid theme.'))
2010-02-16 17:40:41 +00:00
log.exception(u'Importing theme from zip file failed %s' % filename)
2009-11-07 00:00:36 +00:00
finally:
if zip:
zip.close()
if outfile:
outfile.close()
2009-09-13 15:14:45 +00:00
def checkVersion1(self, xmlfile):
"""
Am I a version 1 theme
"""
log.debug(u'checkVersion1 ')
theme = xmlfile
tree = ElementTree(element=XML(theme)).getroot()
if tree.find(u'BackgroundType') is None:
return False
else:
return True
def migrateVersion122(self, filename, fullpath, xml_data):
"""
Called by convert the xml data from version 1 format
to the current format.
New fields are defaulted but the new theme is useable
"""
log.debug(u'migrateVersion122 %s %s', filename, fullpath)
theme = Theme(xml_data)
newtheme = ThemeXML()
newtheme.new_document(theme.Name)
if theme.BackgroundType == 0:
newtheme.add_background_solid(unicode(
theme.BackgroundParameter1.name()))
elif theme.BackgroundType == 1:
direction = u'vertical'
if theme.BackgroundParameter3.name() == 1:
direction = u'horizontal'
newtheme.add_background_gradient(
unicode(theme.BackgroundParameter1.name()),
unicode(theme.BackgroundParameter2.name()), direction)
else:
newtheme.add_background_image(unicode(theme.BackgroundParameter1))
newtheme.add_font(unicode(theme.FontName),
unicode(theme.FontColor.name()),
2009-10-24 07:22:44 +00:00
unicode(theme.FontProportion * 3), u'False')
2009-09-13 15:14:45 +00:00
newtheme.add_font(unicode(theme.FontName),
unicode(theme.FontColor.name()),
unicode(12), u'False', u'footer')
outline = False
shadow = False
if theme.Shadow == 1:
shadow = True
if theme.Outline == 1:
outline = True
2010-02-22 15:53:23 +00:00
vAlignCorrection = 0
if theme.VerticalAlign == 2:
vAlignCorrection = 1
elif theme.VerticalAlign == 1:
vAlignCorrection = 2
2009-09-13 15:14:45 +00:00
newtheme.add_display(unicode(shadow), unicode(theme.ShadowColor.name()),
unicode(outline), unicode(theme.OutlineColor.name()),
2010-02-22 15:53:23 +00:00
unicode(theme.HorizontalAlign), unicode(vAlignCorrection),
2010-02-16 17:40:41 +00:00
unicode(theme.WrapStyle), unicode(0))
2009-09-13 15:14:45 +00:00
return newtheme.extract_xml()
def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from,
2010-06-09 17:09:32 +00:00
image_to):
2009-09-13 15:14:45 +00:00
"""
Called by thememaintenance Dialog to save the theme
and to trigger the reload of the theme list
"""
log.debug(u'saveTheme %s %s', name, theme_xml)
theme_dir = os.path.join(self.path, name)
2009-11-03 15:13:52 +00:00
if not os.path.exists(theme_dir):
2009-09-13 15:14:45 +00:00
os.mkdir(os.path.join(self.path, name))
theme_file = os.path.join(theme_dir, name + u'.xml')
log.debug(theme_file)
result = QtGui.QMessageBox.Yes
2009-10-17 18:20:07 +00:00
if self.saveThemeName != name:
if os.path.exists(theme_file):
result = QtGui.QMessageBox.question(
self, translate(u'ThemeManager', u'Theme Exists'),
translate(u'ThemeManager',
u'A theme with this name already exists, '
u'would you like to overwrite it?'),
2009-10-17 18:20:07 +00:00
(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
2009-09-13 15:14:45 +00:00
if result == QtGui.QMessageBox.Yes:
# Save the theme, overwriting the existing theme if necessary.
2009-11-07 00:00:36 +00:00
outfile = None
try:
outfile = open(theme_file, u'w')
outfile.write(theme_pretty_xml)
2010-05-27 16:00:51 +00:00
except IOError:
2009-11-07 00:00:36 +00:00
log.exception(u'Saving theme to file failed')
finally:
if outfile:
outfile.close()
2009-11-03 18:14:25 +00:00
if image_from and image_from != image_to:
2009-11-07 00:00:36 +00:00
try:
shutil.copyfile(image_from, image_to)
2010-05-27 16:00:51 +00:00
except IOError:
2009-11-07 00:00:36 +00:00
log.exception(u'Failed to save theme image')
2009-09-13 15:14:45 +00:00
self.generateAndSaveImage(self.path, name, theme_xml)
self.loadThemes()
else:
# Don't close the dialog - allow the user to change the name of
# the theme or to cancel the theme dialog completely.
return False
def generateAndSaveImage(self, dir, name, theme_xml):
log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)
2009-11-06 02:12:56 +00:00
theme = self.createThemeFromXml(theme_xml, dir)
2009-09-13 15:14:45 +00:00
frame = self.generateImage(theme)
samplepathname = os.path.join(self.path, name + u'.png')
if os.path.exists(samplepathname):
os.unlink(samplepathname)
frame.save(samplepathname, u'png')
thumb = os.path.join(self.thumbPath, u'%s.png' % name)
icon = build_icon(frame)
2010-05-25 16:16:43 +00:00
pixmap = icon.pixmap(QtCore.QSize(88, 50))
pixmap.save(thumb, u'png')
2009-09-13 15:14:45 +00:00
log.debug(u'Theme image written to %s', samplepathname)
def generateImage(self, themedata):
"""
Call the RenderManager to build a Sample Image
"""
log.debug(u'generateImage %s ', themedata)
frame = self.parent.RenderManager.generate_preview(themedata)
return frame
def getPreviewImage(self, theme):
log.debug(u'getPreviewImage %s ', theme)
image = os.path.join(self.path, theme + u'.png')
return image
def baseTheme(self):
log.debug(u'base theme created')
newtheme = ThemeXML()
newtheme.new_document(unicode(translate(u'ThemeManager', u'New Theme')))
2009-09-13 15:14:45 +00:00
newtheme.add_background_solid(unicode(u'#000000'))
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'),
unicode(30), u'False')
newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'),
unicode(12), u'False', u'footer')
newtheme.add_display(u'False', unicode(u'#FFFFFF'), u'False',
2009-12-11 17:40:18 +00:00
unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0), u'False')
2009-09-13 15:14:45 +00:00
return newtheme.extract_xml()
2009-11-06 02:12:56 +00:00
def createThemeFromXml(self, theme_xml, path):
theme = ThemeXML()
theme.parse(theme_xml)
self.cleanTheme(theme)
theme.extend_image_filename(path)
return theme
2009-09-13 15:14:45 +00:00
def cleanTheme(self, theme):
theme.background_color = theme.background_color.strip()
theme.background_direction = theme.background_direction.strip()
theme.background_endColor = theme.background_endColor.strip()
if theme.background_filename:
theme.background_filename = theme.background_filename.strip()
#theme.background_mode
theme.background_startColor = theme.background_startColor.strip()
#theme.background_type
if theme.display_display:
theme.display_display = theme.display_display.strip()
2009-11-04 01:16:15 +00:00
theme.display_horizontalAlign = \
int(theme.display_horizontalAlign.strip())
2009-09-13 15:14:45 +00:00
theme.display_outline = str_to_bool(theme.display_outline)
#theme.display_outline_color
theme.display_shadow = str_to_bool(theme.display_shadow)
#theme.display_shadow_color
2009-11-03 20:04:38 +00:00
theme.display_verticalAlign = int(theme.display_verticalAlign.strip())
2009-09-13 15:14:45 +00:00
theme.display_wrapStyle = theme.display_wrapStyle.strip()
theme.display_slideTransition = theme.display_slideTransition
2009-09-13 15:14:45 +00:00
theme.font_footer_color = theme.font_footer_color.strip()
2009-11-04 01:16:15 +00:00
theme.font_footer_height = int(theme.font_footer_height.strip())
theme.font_footer_indentation = \
int(theme.font_footer_indentation.strip())
2009-09-13 15:14:45 +00:00
theme.font_footer_italics = str_to_bool(theme.font_footer_italics)
theme.font_footer_name = theme.font_footer_name.strip()
#theme.font_footer_override
2009-11-04 01:16:15 +00:00
theme.font_footer_proportion = \
int(theme.font_footer_proportion.strip())
2009-09-13 15:14:45 +00:00
theme.font_footer_weight = theme.font_footer_weight.strip()
2009-11-04 01:16:15 +00:00
theme.font_footer_width = int(theme.font_footer_width.strip())
theme.font_footer_x = int(theme.font_footer_x.strip())
theme.font_footer_y = int(theme.font_footer_y.strip())
2009-09-13 15:14:45 +00:00
theme.font_main_color = theme.font_main_color.strip()
2009-11-04 01:16:15 +00:00
theme.font_main_height = int(theme.font_main_height.strip())
2009-09-13 15:14:45 +00:00
theme.font_main_italics = str_to_bool(theme.font_main_italics)
theme.font_main_indentation = int(theme.font_main_indentation)
2009-09-13 15:14:45 +00:00
theme.font_main_name = theme.font_main_name.strip()
#theme.font_main_override
2009-11-04 01:16:15 +00:00
theme.font_main_proportion = int(theme.font_main_proportion.strip())
2009-09-13 15:14:45 +00:00
theme.font_main_weight = theme.font_main_weight.strip()
2009-11-04 01:16:15 +00:00
theme.font_main_width = int(theme.font_main_width.strip())
theme.font_main_x = int(theme.font_main_x.strip())
theme.font_main_y = int(theme.font_main_y.strip())
2009-09-13 15:14:45 +00:00
#theme.theme_mode
theme.theme_name = theme.theme_name.strip()
2010-04-20 22:00:55 +00:00
#theme.theme_version
2010-05-27 14:41:47 +00:00