Refactor theme loading

This commit is contained in:
Jon Tibble 2009-09-07 14:05:53 +01:00
parent a037c3ee2b
commit 78b553ac23
2 changed files with 24 additions and 38 deletions

View File

@ -171,16 +171,11 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
save_from, save_to) is not False: save_from, save_to) is not False:
return QtGui.QDialog.accept(self) return QtGui.QDialog.accept(self)
def loadTheme(self, theme): def setTheme(self, theme):
log.debug(u'LoadTheme %s', theme) self.theme = theme
if theme == None:
self.theme.parse(self.baseTheme()) def loadTheme(self):
else: log.debug(u'LoadTheme %s', self.theme)
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.allowPreview = False self.allowPreview = False
self.paintUi(self.theme) self.paintUi(self.theme)
self.allowPreview = True self.allowPreview = True
@ -458,21 +453,6 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
# #
#Local Methods #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): def paintUi(self, theme):
self.stateChanging(theme) self.stateChanging(theme)
self.ThemeNameEdit.setText(self.theme.theme_name) self.ThemeNameEdit.setText(self.theme.theme_name)

View File

@ -127,14 +127,16 @@ class ThemeManager(QtGui.QWidget):
self.pushThemes() self.pushThemes()
def onAddTheme(self): def onAddTheme(self):
self.amendThemeForm.loadTheme(None) self.amendThemeForm.theme.parse(self.baseTheme())
self.amendThemeForm.loadTheme()
self.amendThemeForm.exec_() self.amendThemeForm.exec_()
def onEditTheme(self): def onEditTheme(self):
item = self.ThemeListWidget.currentItem() item = self.ThemeListWidget.currentItem()
if item is not None: if item is not None:
self.amendThemeForm.loadTheme( self.amendThemeForm.setTheme(self.getThemeData(
unicode(item.data(QtCore.Qt.UserRole).toString())) item.data(QtCore.Qt.UserRole).toString()))
self.amendThemeForm.loadTheme()
self.amendThemeForm.exec_() self.amendThemeForm.exec_()
def onDeleteTheme(self): def onDeleteTheme(self):
@ -227,16 +229,7 @@ class ThemeManager(QtGui.QWidget):
try: try:
xml = file_to_xml(xml_file) xml = file_to_xml(xml_file)
except: except:
newtheme = ThemeXML() xml = self.baseTheme()
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()
theme = ThemeXML() theme = ThemeXML()
theme.parse(xml) theme.parse(xml)
theme.extend_image_filename(self.path) theme.extend_image_filename(self.path)
@ -401,6 +394,19 @@ class ThemeManager(QtGui.QWidget):
image = os.path.join(self.path, theme + u'.png') image = os.path.join(self.path, theme + u'.png')
return image 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): def cleanTheme(self, theme):
theme.background_color = theme.background_color.strip() theme.background_color = theme.background_color.strip()
theme.background_direction = theme.background_direction.strip() theme.background_direction = theme.background_direction.strip()