From 0c53783acd2cbed017e337d36a80da4f9cd0709c Mon Sep 17 00:00:00 2001 From: Maikel Stuivenberg Date: Thu, 27 Aug 2009 18:21:00 +0200 Subject: [PATCH 1/2] Theme manager will ask for save if theme already exists --- openlp/core/ui/amendthemeform.py | 4 ++-- openlp/core/ui/thememanager.py | 39 ++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index 3b76e1c89..cf1914d0c 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -135,8 +135,8 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): unicode(self.theme.display_horizontalAlign), unicode(self.theme.display_verticalAlign), unicode(self.theme.display_wrapStyle)) theme = new_theme.extract_xml() - self.thememanager.saveTheme(theme_name, theme, save_from, save_to) - return QtGui.QDialog.accept(self) + if self.thememanager.saveTheme(theme_name, theme, save_from, save_to) is not False: + return QtGui.QDialog.accept(self) def loadTheme(self, theme): log.debug(u'LoadTheme %s', theme) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a1e346fbc..7b9dec27d 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -329,13 +329,38 @@ class ThemeManager(QtGui.QWidget): if os.path.exists(theme_dir) == False: os.mkdir(os.path.join(self.path, name)) theme_file = os.path.join(theme_dir, name + u'.xml') - outfile = open(theme_file, u'w') - outfile.write(theme_xml) - outfile.close() - if image_from is not None and image_from != image_to: - shutil.copyfile(image_from, image_to) - self.generateAndSaveImage(self.path, name, theme_xml) - self.loadThemes() + 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.write(theme_xml) + outfile.close() + if image_from is not None and image_from != image_to: + shutil.copyfile(image_from, image_to) + self.generateAndSaveImage(self.path, name, theme_xml) + 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): log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml) From ec68413cec5bdc74a689e18215e1add9b3135082 Mon Sep 17 00:00:00 2001 From: Maikel Stuivenberg Date: Fri, 28 Aug 2009 20:34:33 +0200 Subject: [PATCH 2/2] fixed the theme code --- openlp/core/ui/thememanager.py | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 7b9dec27d..67219d6b7 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -330,36 +330,27 @@ class ThemeManager(QtGui.QWidget): os.mkdir(os.path.join(self.path, name)) 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: + + result = QtGui.QMessageBox.Yes + 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, would you like to overwrite it?'), + (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if result == QtGui.QMessageBox.Yes: + # Save the theme, overwriting the existing theme if necessary. outfile = open(theme_file, u'w') outfile.write(theme_xml) outfile.close() if image_from is not None and image_from != image_to: - shutil.copyfile(image_from, image_to) + shutil.copyfile(image_from, image_to) + self.generateAndSaveImage(self.path, name, theme_xml) 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: + 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):