forked from openlp/openlp
Refactor theme loading
This commit is contained in:
parent
a037c3ee2b
commit
78b553ac23
@ -171,16 +171,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
save_from, save_to) is not False:
|
||||
return QtGui.QDialog.accept(self)
|
||||
|
||||
def loadTheme(self, theme):
|
||||
log.debug(u'LoadTheme %s', theme)
|
||||
if theme == None:
|
||||
self.theme.parse(self.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)
|
||||
def setTheme(self, theme):
|
||||
self.theme = theme
|
||||
|
||||
def loadTheme(self):
|
||||
log.debug(u'LoadTheme %s', self.theme)
|
||||
self.allowPreview = False
|
||||
self.paintUi(self.theme)
|
||||
self.allowPreview = True
|
||||
@ -458,21 +453,6 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
#
|
||||
#Local Methods
|
||||
#
|
||||
def baseTheme(self):
|
||||
log.debug(u'base theme created')
|
||||
newtheme = ThemeXML()
|
||||
newtheme.new_document(u'New Theme')
|
||||
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',
|
||||
unicode(u'#FFFFFF'),
|
||||
unicode(0), unicode(0), unicode(0))
|
||||
|
||||
return newtheme.extract_xml()
|
||||
|
||||
def paintUi(self, theme):
|
||||
self.stateChanging(theme)
|
||||
self.ThemeNameEdit.setText(self.theme.theme_name)
|
||||
|
@ -127,14 +127,16 @@ class ThemeManager(QtGui.QWidget):
|
||||
self.pushThemes()
|
||||
|
||||
def onAddTheme(self):
|
||||
self.amendThemeForm.loadTheme(None)
|
||||
self.amendThemeForm.theme.parse(self.baseTheme())
|
||||
self.amendThemeForm.loadTheme()
|
||||
self.amendThemeForm.exec_()
|
||||
|
||||
def onEditTheme(self):
|
||||
item = self.ThemeListWidget.currentItem()
|
||||
if item is not None:
|
||||
self.amendThemeForm.loadTheme(
|
||||
unicode(item.data(QtCore.Qt.UserRole).toString()))
|
||||
self.amendThemeForm.setTheme(self.getThemeData(
|
||||
item.data(QtCore.Qt.UserRole).toString()))
|
||||
self.amendThemeForm.loadTheme()
|
||||
self.amendThemeForm.exec_()
|
||||
|
||||
def onDeleteTheme(self):
|
||||
@ -227,16 +229,7 @@ class ThemeManager(QtGui.QWidget):
|
||||
try:
|
||||
xml = file_to_xml(xml_file)
|
||||
except:
|
||||
newtheme = ThemeXML()
|
||||
newtheme.new_document(u'New Theme')
|
||||
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',
|
||||
unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0))
|
||||
xml = newtheme.extract_xml()
|
||||
xml = self.baseTheme()
|
||||
theme = ThemeXML()
|
||||
theme.parse(xml)
|
||||
theme.extend_image_filename(self.path)
|
||||
@ -401,6 +394,19 @@ class ThemeManager(QtGui.QWidget):
|
||||
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(u'New Theme')
|
||||
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',
|
||||
unicode(u'#FFFFFF'), unicode(0), unicode(0), unicode(0))
|
||||
return newtheme.extract_xml()
|
||||
|
||||
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