forked from openlp/openlp
Clean theme loading
This commit is contained in:
parent
b6289db8a8
commit
74b08cb9c4
@ -28,7 +28,7 @@ import os.path
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import ThemeXML, file_to_xml
|
||||
from openlp.core.lib import ThemeXML
|
||||
from amendthemedialog import Ui_AmendThemeDialog
|
||||
|
||||
log = logging.getLogger(u'AmendThemeForm')
|
||||
@ -184,14 +184,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
|
||||
def loadTheme(self, theme):
|
||||
log.debug(u'LoadTheme %s', theme)
|
||||
if theme is None:
|
||||
self.theme.parse(self.thememanager.baseTheme())
|
||||
else:
|
||||
xml_file = os.path.join(self.path, theme, theme + u'.xml')
|
||||
xml = file_to_xml(xml_file)
|
||||
self.theme.parse(xml)
|
||||
self.theme.extend_image_filename(self.path)
|
||||
self.thememanager.cleanTheme(self.theme)
|
||||
self.theme = self.thememanager.getThemeData(theme)
|
||||
# Stop the initial screen setup generating 1 preview per field!
|
||||
self.allowPreview = False
|
||||
self.paintUi(self.theme)
|
||||
|
@ -269,18 +269,14 @@ class ThemeManager(QtGui.QWidget):
|
||||
return self.themelist
|
||||
|
||||
def getThemeData(self, themename):
|
||||
assert(themename)
|
||||
log.debug(u'getthemedata for theme %s', themename)
|
||||
xml_file = os.path.join(self.path, unicode(themename),
|
||||
unicode(themename) + u'.xml')
|
||||
try:
|
||||
xml = file_to_xml(xml_file)
|
||||
except:
|
||||
if not xml:
|
||||
xml = self.baseTheme()
|
||||
theme = ThemeXML()
|
||||
theme.parse(xml)
|
||||
self.cleanTheme(theme)
|
||||
theme.extend_image_filename(self.path)
|
||||
return theme
|
||||
return createThemeFromXml(xml, self.path)
|
||||
|
||||
def checkThemesExists(self, dir):
|
||||
log.debug(u'check themes')
|
||||
@ -428,10 +424,7 @@ class ThemeManager(QtGui.QWidget):
|
||||
|
||||
def generateAndSaveImage(self, dir, name, theme_xml):
|
||||
log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)
|
||||
theme = ThemeXML()
|
||||
theme.parse(theme_xml)
|
||||
self.cleanTheme(theme)
|
||||
theme.extend_image_filename(dir)
|
||||
theme = self.createThemeFromXml(theme_xml, dir)
|
||||
frame = self.generateImage(theme)
|
||||
samplepathname = os.path.join(self.path, name + u'.png')
|
||||
if os.path.exists(samplepathname):
|
||||
@ -465,6 +458,13 @@ class ThemeManager(QtGui.QWidget):
|
||||
unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0))
|
||||
return newtheme.extract_xml()
|
||||
|
||||
def createThemeFromXml(self, theme_xml, path):
|
||||
theme = ThemeXML()
|
||||
theme.parse(theme_xml)
|
||||
self.cleanTheme(theme)
|
||||
theme.extend_image_filename(path)
|
||||
return theme
|
||||
|
||||
def cleanTheme(self, theme):
|
||||
theme.background_color = theme.background_color.strip()
|
||||
theme.background_direction = theme.background_direction.strip()
|
||||
|
Loading…
Reference in New Issue
Block a user