Theme manager will ask for save if theme already exists

This commit is contained in:
Maikel Stuivenberg 2009-08-27 18:21:00 +02:00
parent 7a317f82f4
commit 0c53783acd
2 changed files with 34 additions and 9 deletions

View File

@ -135,7 +135,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
unicode(self.theme.display_horizontalAlign), unicode(self.theme.display_verticalAlign), unicode(self.theme.display_horizontalAlign), unicode(self.theme.display_verticalAlign),
unicode(self.theme.display_wrapStyle)) unicode(self.theme.display_wrapStyle))
theme = new_theme.extract_xml() theme = new_theme.extract_xml()
self.thememanager.saveTheme(theme_name, theme, save_from, save_to) if self.thememanager.saveTheme(theme_name, theme, save_from, save_to) is not False:
return QtGui.QDialog.accept(self) return QtGui.QDialog.accept(self)
def loadTheme(self, theme): def loadTheme(self, theme):

View File

@ -329,6 +329,21 @@ class ThemeManager(QtGui.QWidget):
if os.path.exists(theme_dir) == False: if os.path.exists(theme_dir) == False:
os.mkdir(os.path.join(self.path, name)) os.mkdir(os.path.join(self.path, name))
theme_file = os.path.join(theme_dir, name + u'.xml') theme_file = os.path.join(theme_dir, name + u'.xml')
log.debug(theme_file)
if os.path.exists(theme_file):
result = QtGui.QMessageBox.information(
self,
translate(u'ThemeManager',u'Theme already exist!'),
translate(u'ThemeManager',u'This theme name already exist.\n') + \
translate(u'ThemeManager',u'do you want to overwrite it?'),
translate(u'ThemeManager',u'Save'),
translate(u'ThemeManager',u'Discard'),
translate(u'ThemeManager',u'Cancel'),
0,
2)
else:
result = 0
if result == 0:
outfile = open(theme_file, u'w') outfile = open(theme_file, u'w')
outfile.write(theme_xml) outfile.write(theme_xml)
outfile.close() outfile.close()
@ -336,6 +351,16 @@ class ThemeManager(QtGui.QWidget):
shutil.copyfile(image_from, image_to) shutil.copyfile(image_from, image_to)
self.generateAndSaveImage(self.path, name, theme_xml) self.generateAndSaveImage(self.path, name, theme_xml)
self.loadThemes() self.loadThemes()
"""
Case 1, Discard (Only Reload Theme's)
"""
if result == 1:
self.loadThemes()
"""
Case 2, Cancel (Back to New Theme Screen)
"""
if result == 2:
return False
def generateAndSaveImage(self, dir, name, theme_xml): def generateAndSaveImage(self, dir, name, theme_xml):
log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml) log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)