From e9caa194f5f40a9cce0c40b660313ece4636a744 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Fri, 9 Mar 2012 21:43:27 +0000 Subject: [PATCH 1/7] Adds a dialouge asking if the user wants to replace an existing theme when importing. It works, but I dont know, it just feels like my code is a little bit "rough 'n' ready" let me know what you think! --- openlp/core/ui/thememanager.py | 58 ++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 3585e5c97..d4a861e44 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -511,6 +511,20 @@ class ThemeManager(QtGui.QWidget): return ThemeXML() else: return self._createThemeFromXml(xml, self.path) + + def overWriteMessageBox(self, themeName): + ret = QtGui.QMessageBox.question(self, + translate('OpenLP.ThemeManager', 'Theme Already Exists!'), + translate('OpenLP.ThemeManager', + 'The theme %s already exists. Do you want to replace it?' + % themeName), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.No) + if ret == QtGui.QMessageBox.Yes: + return True + elif ret == QtGui.QMessageBox.No: + return False def unzipTheme(self, filename, dir): """ @@ -522,7 +536,7 @@ class ThemeManager(QtGui.QWidget): filename = unicode(filename) zip = None outfile = None - filexml = None + filexml = None try: zip = zipfile.ZipFile(filename) xmlfile = filter(lambda name: @@ -533,10 +547,17 @@ class ThemeManager(QtGui.QWidget): xml_tree = ElementTree(element=XML(zip.read(xmlfile[0]))).getroot() v1_background = xml_tree.find(u'BackgroundType') if v1_background is not None: - (themename, filexml, outfile) = self.unzipVersion122(dir, zip, + (themename, filexml, outfile, abortimport) = self.unzipVersion122(dir, zip, xmlfile[0], xml_tree, v1_background, outfile) else: themename = xml_tree.find(u'name').text.strip() + themefolder = os.path.join(dir, themename) + themeexists = os.path.exists(themefolder) + if themeexists and not self.overWriteMessageBox(themename): + abortimport = True + return + else: + abortimport = False for name in zip.namelist(): try: uname = unicode(name, u'utf-8') @@ -575,19 +596,20 @@ class ThemeManager(QtGui.QWidget): zip.close() if outfile: outfile.close() - # As all files are closed, we can create the Theme. - if filexml: - theme = self._createThemeFromXml(filexml, self.path) - self.generateAndSaveImage(dir, themename, theme) - # Only show the error message, when IOError was not raised (in this - # case the error message has already been shown). - elif zip is not None: - critical_error_message_box( - translate('OpenLP.ThemeManager', 'Validation Error'), - translate('OpenLP.ThemeManager', - 'File is not a valid theme.')) - log.exception(u'Theme file does not contain XML data %s' % - filename) + if not abortimport: + # As all files are closed, we can create the Theme. + if filexml: + theme = self._createThemeFromXml(filexml, self.path) + self.generateAndSaveImage(dir, themename, theme) + # Only show the error message, when IOError was not raised (in this + # case the error message has already been shown). + elif zip is not None: + critical_error_message_box( + translate('OpenLP.ThemeManager', 'Validation Error'), + translate('OpenLP.ThemeManager', + 'File is not a valid theme.')) + log.exception(u'Theme file does not contain XML data %s' % + filename) def unzipVersion122(self, dir, zip, xmlfile, xml_tree, background, outfile): """ @@ -596,6 +618,10 @@ class ThemeManager(QtGui.QWidget): """ themename = xml_tree.find(u'Name').text.strip() themename = self.bad_v1_name_chars.sub(u'', themename) + themefolder = os.path.join(dir, themename) + themeexists = os.path.exists(themefolder) + if themeexists and not self.overWriteMessageBox(themename): + return ( '', '', '', True) themedir = os.path.join(dir, themename) check_directory_exists(themedir) filexml = unicode(zip.read(xmlfile), u'utf-8') @@ -617,7 +643,7 @@ class ThemeManager(QtGui.QWidget): log.exception(u'Theme file does not contain image file "%s"' % imagename.decode(u'utf-8', u'replace')) raise Exception(u'validation') - return (themename, filexml, outfile) + return (themename, filexml, outfile, False) def checkIfThemeExists(self, themeName): """ From a40717c16f98b95465e69a3ea9f997e57b6f883c Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 08:22:52 +0000 Subject: [PATCH 2/7] Fixed up to Raouls guidelines --- openlp/core/ui/thememanager.py | 183 ++++++++++++++++----------------- 1 file changed, 90 insertions(+), 93 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index d4a861e44..0b86faca6 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -178,10 +178,10 @@ class ThemeManager(QtGui.QWidget): """ if item is None: return - realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) - themeName = unicode(item.text()) + realtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + theme_name = unicode(item.text()) # If default theme restrict actions - if realThemeName == themeName: + if realtheme_name == theme_name: self.deleteToolbarAction.setVisible(True) else: self.deleteToolbarAction.setVisible(False) @@ -194,24 +194,24 @@ class ThemeManager(QtGui.QWidget): item = self.themeListWidget.itemAt(point) if item is None: return - realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) - themeName = unicode(item.text()) + realtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + theme_name = unicode(item.text()) self.deleteAction.setVisible(False) self.renameAction.setVisible(False) self.globalAction.setVisible(False) # If default theme restrict actions - if realThemeName == themeName: + if realtheme_name == theme_name: self.deleteAction.setVisible(True) self.renameAction.setVisible(True) self.globalAction.setVisible(True) self.menu.exec_(self.themeListWidget.mapToGlobal(point)) - def changeGlobalFromTab(self, themeName): + def changeGlobalFromTab(self, theme_name): """ Change the global theme when it is changed through the Themes settings tab """ - log.debug(u'changeGlobalFromTab %s', themeName) + log.debug(u'changeGlobalFromTab %s', theme_name) for count in range (0, self.themeListWidget.count()): # reset the old name item = self.themeListWidget.item(count) @@ -220,7 +220,7 @@ class ThemeManager(QtGui.QWidget): if oldName != newName: self.themeListWidget.item(count).setText(newName) # Set the new name - if themeName == newName: + if theme_name == newName: name = unicode(translate('OpenLP.ThemeManager', '%s (default)')) % newName self.themeListWidget.item(count).setText(name) @@ -272,19 +272,19 @@ class ThemeManager(QtGui.QWidget): unicode(translate('OpenLP.ThemeManager', 'Rename %s theme?')), False, False): item = self.themeListWidget.currentItem() - oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) - self.fileRenameForm.fileNameEdit.setText(oldThemeName) + oldtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + self.fileRenameForm.fileNameEdit.setText(oldtheme_name) if self.fileRenameForm.exec_(): - newThemeName = unicode(self.fileRenameForm.fileNameEdit.text()) - if oldThemeName == newThemeName: + newtheme_name = unicode(self.fileRenameForm.fileNameEdit.text()) + if oldtheme_name == newtheme_name: return - if self.checkIfThemeExists(newThemeName): - oldThemeData = self.getThemeData(oldThemeName) - self.cloneThemeData(oldThemeData, newThemeName) - self.deleteTheme(oldThemeName) + if self.checkIfThemeExists(newtheme_name): + oldThemeData = self.getThemeData(oldtheme_name) + self.cloneThemeData(oldThemeData, newtheme_name) + self.deleteTheme(oldtheme_name) for plugin in self.mainwindow.pluginManager.plugins: - if plugin.usesTheme(oldThemeName): - plugin.renameTheme(oldThemeName, newThemeName) + if plugin.usesTheme(oldtheme_name): + plugin.renameTheme(oldtheme_name, newtheme_name) self.loadThemes() def onCopyTheme(self): @@ -292,17 +292,17 @@ class ThemeManager(QtGui.QWidget): Copies an existing theme to a new name """ item = self.themeListWidget.currentItem() - oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) + oldtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) self.fileRenameForm.fileNameEdit.setText( unicode(translate('OpenLP.ThemeManager', - 'Copy of %s','Copy of ')) % oldThemeName) + 'Copy of %s','Copy of ')) % oldtheme_name) if self.fileRenameForm.exec_(True): - newThemeName = unicode(self.fileRenameForm.fileNameEdit.text()) - if self.checkIfThemeExists(newThemeName): - themeData = self.getThemeData(oldThemeName) - self.cloneThemeData(themeData, newThemeName) + newtheme_name = unicode(self.fileRenameForm.fileNameEdit.text()) + if self.checkIfThemeExists(newtheme_name): + themeData = self.getThemeData(oldtheme_name) + self.cloneThemeData(themeData, newtheme_name) - def cloneThemeData(self, themeData, newThemeName): + def cloneThemeData(self, themeData, newtheme_name): """ Takes a theme and makes a new copy of it as well as saving it. """ @@ -310,10 +310,10 @@ class ThemeManager(QtGui.QWidget): saveTo = None saveFrom = None if themeData.background_type == u'image': - saveTo = os.path.join(self.path, newThemeName, + saveTo = os.path.join(self.path, newtheme_name, os.path.split(unicode(themeData.background_filename))[1]) saveFrom = themeData.background_filename - themeData.theme_name = newThemeName + themeData.theme_name = newtheme_name themeData.extend_image_filename(self.path) self.saveTheme(themeData, saveFrom, saveTo) @@ -458,7 +458,7 @@ class ThemeManager(QtGui.QWidget): files = SettingsManager.get_files(self.settingsSection, u'.png') # Sort the themes by its name considering language specific characters. # lower() is needed for windows! - files.sort(key=lambda filename: unicode(filename).lower(), + files.sort(key=lambda file_name: unicode(file_name).lower(), cmp=locale.strcoll) # now process the file list of png files for name in files: @@ -495,16 +495,16 @@ class ThemeManager(QtGui.QWidget): """ return self.themelist - def getThemeData(self, themeName): + def getThemeData(self, theme_name): """ Returns a theme object from an XML file - ``themeName`` + ``theme_name`` Name of the theme to load from file """ - log.debug(u'getthemedata for theme %s', themeName) - xmlFile = os.path.join(self.path, unicode(themeName), - unicode(themeName) + u'.xml') + log.debug(u'getthemedata for theme %s', theme_name) + xmlFile = os.path.join(self.path, unicode(theme_name), + unicode(theme_name) + u'.xml') xml = get_text_file_string(xmlFile) if not xml: log.debug("No theme data - using default theme") @@ -512,33 +512,30 @@ class ThemeManager(QtGui.QWidget): else: return self._createThemeFromXml(xml, self.path) - def overWriteMessageBox(self, themeName): + def overWriteMessageBox(self, theme_name): ret = QtGui.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists!'), translate('OpenLP.ThemeManager', 'The theme %s already exists. Do you want to replace it?' - % themeName), + % theme_name), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) - if ret == QtGui.QMessageBox.Yes: - return True - elif ret == QtGui.QMessageBox.No: - return False + return ret == QtGui.QMessageBox.Yes - def unzipTheme(self, filename, dir): + def unzipTheme(self, file_name, dir): """ Unzip the theme, remove the preview file if stored Generate a new preview file. Check the XML theme version and upgrade if necessary. """ - log.debug(u'Unzipping theme %s', filename) - filename = unicode(filename) + log.debug(u'Unzipping theme %s', file_name) + file_name = unicode(file_name) zip = None - outfile = None - filexml = None + out_file = None + file_xml = None try: - zip = zipfile.ZipFile(filename) + zip = zipfile.ZipFile(file_name) xmlfile = filter(lambda name: os.path.splitext(name)[1].lower() == u'.xml', zip.namelist()) if len(xmlfile) != 1: @@ -547,17 +544,17 @@ class ThemeManager(QtGui.QWidget): xml_tree = ElementTree(element=XML(zip.read(xmlfile[0]))).getroot() v1_background = xml_tree.find(u'BackgroundType') if v1_background is not None: - (themename, filexml, outfile, abortimport) = self.unzipVersion122(dir, zip, - xmlfile[0], xml_tree, v1_background, outfile) + theme_name, file_xml, out_file, abort_import = self.unzipVersion122(dir, zip, + xmlfile[0], xml_tree, v1_background, out_file) else: - themename = xml_tree.find(u'name').text.strip() - themefolder = os.path.join(dir, themename) - themeexists = os.path.exists(themefolder) - if themeexists and not self.overWriteMessageBox(themename): - abortimport = True + theme_name = xml_tree.find(u'name').text.strip() + theme_folder = os.path.join(dir, theme_name) + theme_exists = os.path.exists(theme_folder) + if theme_exists and not self.overWriteMessageBox(theme_name): + abort_import = True return else: - abortimport = False + abort_import = False for name in zip.namelist(): try: uname = unicode(name, u'utf-8') @@ -573,15 +570,15 @@ class ThemeManager(QtGui.QWidget): fullname = os.path.join(dir, uname) check_directory_exists(os.path.dirname(fullname)) if os.path.splitext(uname)[1].lower() == u'.xml': - filexml = unicode(zip.read(name), u'utf-8') - outfile = open(fullname, u'w') - outfile.write(filexml.encode(u'utf-8')) + file_xml = unicode(zip.read(name), u'utf-8') + out_file = open(fullname, u'w') + out_file.write(file_xml.encode(u'utf-8')) else: - outfile = open(fullname, u'wb') - outfile.write(zip.read(name)) - outfile.close() + out_file = open(fullname, u'wb') + out_file.write(zip.read(name)) + out_file.close() except (IOError, zipfile.BadZipfile): - log.exception(u'Importing theme from zip failed %s' % filename) + log.exception(u'Importing theme from zip failed %s' % file_name) raise Exception(u'validation') except Exception as info: if unicode(info) == u'validation': @@ -594,13 +591,13 @@ class ThemeManager(QtGui.QWidget): # Close the files, to be able to continue creating the theme. if zip: zip.close() - if outfile: - outfile.close() - if not abortimport: + if out_file: + out_file.close() + if not abort_import: # As all files are closed, we can create the Theme. - if filexml: - theme = self._createThemeFromXml(filexml, self.path) - self.generateAndSaveImage(dir, themename, theme) + if file_xml: + theme = self._createThemeFromXml(file_xml, self.path) + self.generateAndSaveImage(dir, theme_name, theme) # Only show the error message, when IOError was not raised (in this # case the error message has already been shown). elif zip is not None: @@ -609,26 +606,26 @@ class ThemeManager(QtGui.QWidget): translate('OpenLP.ThemeManager', 'File is not a valid theme.')) log.exception(u'Theme file does not contain XML data %s' % - filename) + file_name) - def unzipVersion122(self, dir, zip, xmlfile, xml_tree, background, outfile): + def unzipVersion122(self, dir, zip, xmlfile, xml_tree, background, out_file): """ Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling this method, please keep in mind, that some parameters are redundant. """ - themename = xml_tree.find(u'Name').text.strip() - themename = self.bad_v1_name_chars.sub(u'', themename) - themefolder = os.path.join(dir, themename) - themeexists = os.path.exists(themefolder) - if themeexists and not self.overWriteMessageBox(themename): - return ( '', '', '', True) - themedir = os.path.join(dir, themename) + theme_name = xml_tree.find(u'Name').text.strip() + theme_name = self.bad_v1_name_chars.sub(u'', theme_name) + theme_folder = os.path.join(dir, theme_name) + theme_exists = os.path.exists(theme_folder) + if theme_exists and not self.overWriteMessageBox(theme_name): + return '', '', '', True + themedir = os.path.join(dir, theme_name) check_directory_exists(themedir) - filexml = unicode(zip.read(xmlfile), u'utf-8') - filexml = self._migrateVersion122(filexml) - outfile = open(os.path.join(themedir, themename + u'.xml'), u'w') - outfile.write(filexml.encode(u'utf-8')) - outfile.close() + file_xml = unicode(zip.read(xmlfile), u'utf-8') + file_xml = self._migrateVersion122(file_xml) + out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w') + out_file.write(file_xml.encode(u'utf-8')) + out_file.close() if background.text.strip() == u'2': imagename = xml_tree.find(u'BackgroundParameter1').text.strip() # image file has same extension and is in subfolder @@ -636,23 +633,23 @@ class ThemeManager(QtGui.QWidget): == os.path.splitext(imagename)[1].lower() and name.find(r'/'), zip.namelist()) if len(imagefile) >= 1: - outfile = open(os.path.join(themedir, imagename), u'wb') - outfile.write(zip.read(imagefile[0])) - outfile.close() + out_file = open(os.path.join(themedir, imagename), u'wb') + out_file.write(zip.read(imagefile[0])) + out_file.close() else: log.exception(u'Theme file does not contain image file "%s"' % imagename.decode(u'utf-8', u'replace')) raise Exception(u'validation') - return (themename, filexml, outfile, False) + return theme_name, file_xml, out_file, False - def checkIfThemeExists(self, themeName): + def checkIfThemeExists(self, theme_name): """ Check if theme already exists and displays error message - ``themeName`` + ``theme_name`` Name of the Theme to test """ - theme_dir = os.path.join(self.path, themeName) + theme_dir = os.path.join(self.path, theme_name) if os.path.exists(theme_dir): critical_error_message_box( translate('OpenLP.ThemeManager', 'Validation Error'), @@ -688,15 +685,15 @@ class ThemeManager(QtGui.QWidget): if self.oldBackgroundImage and \ imageTo != self.oldBackgroundImage: delete_file(self.oldBackgroundImage) - outfile = None + out_file = None try: - outfile = open(theme_file, u'w') - outfile.write(theme_pretty_xml) + out_file = open(theme_file, u'w') + out_file.write(theme_pretty_xml) except IOError: log.exception(u'Saving theme to file failed') finally: - if outfile: - outfile.close() + if out_file: + out_file.close() if imageFrom and imageFrom != imageTo: try: encoding = get_filesystem_encoding() From 7d7e76fd9b5c04a7a770f3c29f381f1184d35ed8 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 16:03:58 +0000 Subject: [PATCH 3/7] renaming variables, if your going to open a can of worms, might as well eat them all! --- openlp/core/ui/thememanager.py | 271 ++++++++++++++++----------------- 1 file changed, 135 insertions(+), 136 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 0b86faca6..eb022bb25 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -52,9 +52,9 @@ class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. """ - def __init__(self, mainwindow, parent=None): + def __init__(self, mainWindow, parent=None): QtGui.QWidget.__init__(self, parent) - self.mainwindow = mainwindow + self.mainWindow = mainWindow self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) @@ -140,13 +140,13 @@ class ThemeManager(QtGui.QWidget): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated) # Variables - self.themelist = [] + self.theme_list = [] self.path = AppLocation.get_section_data_path(self.settingsSection) check_directory_exists(self.path) - self.thumbPath = os.path.join(self.path, u'thumbnails') - check_directory_exists(self.thumbPath) + self.thumb_path = os.path.join(self.path, u'thumbnails') + check_directory_exists(self.thumb_path) self.themeForm.path = self.path - self.oldBackgroundImage = None + self.old_background_image = None self.bad_v1_name_chars = re.compile(r'[%+\[\]]') # Last little bits of setting up self.configUpdated() @@ -178,10 +178,10 @@ class ThemeManager(QtGui.QWidget): """ if item is None: return - realtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) theme_name = unicode(item.text()) # If default theme restrict actions - if realtheme_name == theme_name: + if real_theme_name == theme_name: self.deleteToolbarAction.setVisible(True) else: self.deleteToolbarAction.setVisible(False) @@ -194,13 +194,13 @@ class ThemeManager(QtGui.QWidget): item = self.themeListWidget.itemAt(point) if item is None: return - realtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) theme_name = unicode(item.text()) self.deleteAction.setVisible(False) self.renameAction.setVisible(False) self.globalAction.setVisible(False) # If default theme restrict actions - if realtheme_name == theme_name: + if real_theme_name == theme_name: self.deleteAction.setVisible(True) self.renameAction.setVisible(True) self.globalAction.setVisible(True) @@ -215,14 +215,14 @@ class ThemeManager(QtGui.QWidget): for count in range (0, self.themeListWidget.count()): # reset the old name item = self.themeListWidget.item(count) - oldName = item.text() - newName = unicode(item.data(QtCore.Qt.UserRole).toString()) - if oldName != newName: - self.themeListWidget.item(count).setText(newName) + old_name = item.text() + new_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + if old_name != new_name: + self.themeListWidget.item(count).setText(new_name) # Set the new name - if theme_name == newName: + if theme_name == new_name: name = unicode(translate('OpenLP.ThemeManager', - '%s (default)')) % newName + '%s (default)')) % new_name self.themeListWidget.item(count).setText(name) def changeGlobalFromScreen(self, index=-1): @@ -234,9 +234,9 @@ class ThemeManager(QtGui.QWidget): selected_row = self.themeListWidget.currentRow() for count in range (0, self.themeListWidget.count()): item = self.themeListWidget.item(count) - oldName = item.text() + old_name = item.text() # reset the old name - if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()): + if old_name != unicode(item.data(QtCore.Qt.UserRole).toString()): self.themeListWidget.item(count).setText( unicode(item.data(QtCore.Qt.UserRole).toString())) # Set the new name @@ -272,19 +272,19 @@ class ThemeManager(QtGui.QWidget): unicode(translate('OpenLP.ThemeManager', 'Rename %s theme?')), False, False): item = self.themeListWidget.currentItem() - oldtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) - self.fileRenameForm.fileNameEdit.setText(oldtheme_name) + old_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + self.fileRenameForm.fileNameEdit.setText(old_theme_name) if self.fileRenameForm.exec_(): - newtheme_name = unicode(self.fileRenameForm.fileNameEdit.text()) - if oldtheme_name == newtheme_name: + new_theme_name = unicode(self.fileRenameForm.fileNameEdit.text()) + if old_theme_name == new_theme_name: return - if self.checkIfThemeExists(newtheme_name): - oldThemeData = self.getThemeData(oldtheme_name) - self.cloneThemeData(oldThemeData, newtheme_name) - self.deleteTheme(oldtheme_name) - for plugin in self.mainwindow.pluginManager.plugins: - if plugin.usesTheme(oldtheme_name): - plugin.renameTheme(oldtheme_name, newtheme_name) + if self.checkIfThemeExists(new_theme_name): + old_theme_data = self.getThemeData(old_theme_name) + self.cloneThemeData(old_theme_data, new_theme_name) + self.deleteTheme(old_theme_name) + for plugin in self.mainWindow.pluginManager.plugins: + if plugin.usesTheme(old_theme_name): + plugin.renameTheme(old_theme_name, new_theme_name) self.loadThemes() def onCopyTheme(self): @@ -292,30 +292,30 @@ class ThemeManager(QtGui.QWidget): Copies an existing theme to a new name """ item = self.themeListWidget.currentItem() - oldtheme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) + old_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) self.fileRenameForm.fileNameEdit.setText( unicode(translate('OpenLP.ThemeManager', - 'Copy of %s','Copy of ')) % oldtheme_name) + 'Copy of %s','Copy of ')) % old_theme_name) if self.fileRenameForm.exec_(True): - newtheme_name = unicode(self.fileRenameForm.fileNameEdit.text()) - if self.checkIfThemeExists(newtheme_name): - themeData = self.getThemeData(oldtheme_name) - self.cloneThemeData(themeData, newtheme_name) + new_theme_name = unicode(self.fileRenameForm.fileNameEdit.text()) + if self.checkIfThemeExists(new_theme_name): + theme_data = self.getThemeData(old_theme_name) + self.cloneThemeData(theme_data, new_theme_name) - def cloneThemeData(self, themeData, newtheme_name): + def cloneThemeData(self, theme_data, new_theme_name): """ Takes a theme and makes a new copy of it as well as saving it. """ log.debug(u'cloneThemeData') - saveTo = None - saveFrom = None - if themeData.background_type == u'image': - saveTo = os.path.join(self.path, newtheme_name, - os.path.split(unicode(themeData.background_filename))[1]) - saveFrom = themeData.background_filename - themeData.theme_name = newtheme_name - themeData.extend_image_filename(self.path) - self.saveTheme(themeData, saveFrom, saveTo) + save_to = None + save_from = None + if theme_data.background_type == u'image': + save_to = os.path.join(self.path, new_theme_name, + os.path.split(unicode(theme_data.background_filename))[1]) + save_from = theme_data.background_filename + theme_data.theme_name = new_theme_name + theme_data.extend_image_filename(self.path) + self.saveTheme(theme_data, save_from, save_to) def onEditTheme(self): """ @@ -329,10 +329,10 @@ class ThemeManager(QtGui.QWidget): theme = self.getThemeData( unicode(item.data(QtCore.Qt.UserRole).toString())) if theme.background_type == u'image': - self.oldBackgroundImage = theme.background_filename + self.old_background_image = theme.background_filename self.themeForm.theme = theme self.themeForm.exec_(True) - self.oldBackgroundImage = None + self.old_background_image = None def onDeleteTheme(self): """ @@ -358,10 +358,10 @@ class ThemeManager(QtGui.QWidget): ``theme`` The theme to delete. """ - self.themelist.remove(theme) + self.theme_list.remove(theme) thumb = u'%s.png' % theme delete_file(os.path.join(self.path, thumb)) - delete_file(os.path.join(self.thumbPath, thumb)) + delete_file(os.path.join(self.thumb_path, thumb)) try: encoding = get_filesystem_encoding() shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) @@ -386,10 +386,10 @@ class ThemeManager(QtGui.QWidget): Receiver.send_message(u'cursor_busy') if path: SettingsManager.set_last_dir(self.settingsSection, path, 1) - themePath = os.path.join(path, theme + u'.otz') + theme_path = os.path.join(path, theme + u'.otz') zip = None try: - zip = zipfile.ZipFile(themePath, u'w') + zip = zipfile.ZipFile(theme_path, u'w') source = os.path.join(self.path, theme) for files in os.walk(source): for name in files[2]: @@ -439,9 +439,8 @@ class ThemeManager(QtGui.QWidget): The plugins will call back in to get the real list if they want it. """ log.debug(u'Load themes from dir') - self.themelist = [] + self.theme_list = [] self.themeListWidget.clear() - dirList = os.listdir(self.path) files = SettingsManager.get_files(self.settingsSection, u'.png') if firstTime: self.firstTime() @@ -465,22 +464,22 @@ class ThemeManager(QtGui.QWidget): # check to see file is in theme root directory theme = os.path.join(self.path, name) if os.path.exists(theme): - textName = os.path.splitext(name)[0] - if textName == self.global_theme: + text_name = os.path.splitext(name)[0] + if text_name == self.global_theme: name = unicode(translate('OpenLP.ThemeManager', - '%s (default)')) % textName + '%s (default)')) % text_name else: - name = textName - thumb = os.path.join(self.thumbPath, u'%s.png' % textName) + name = text_name + thumb = os.path.join(self.thumb_path, u'%s.png' % text_name) item_name = QtGui.QListWidgetItem(name) if validate_thumb(theme, thumb): icon = build_icon(thumb) else: icon = create_thumb(theme, thumb) item_name.setIcon(icon) - item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName)) + item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(text_name)) self.themeListWidget.addItem(item_name) - self.themelist.append(textName) + self.theme_list.append(text_name) self._pushThemes() def _pushThemes(self): @@ -493,7 +492,7 @@ class ThemeManager(QtGui.QWidget): """ Return the list of loaded themes """ - return self.themelist + return self.theme_list def getThemeData(self, theme_name): """ @@ -503,9 +502,9 @@ class ThemeManager(QtGui.QWidget): Name of the theme to load from file """ log.debug(u'getthemedata for theme %s', theme_name) - xmlFile = os.path.join(self.path, unicode(theme_name), + xml_file = os.path.join(self.path, unicode(theme_name), unicode(theme_name) + u'.xml') - xml = get_text_file_string(xmlFile) + xml = get_text_file_string(xml_file) if not xml: log.debug("No theme data - using default theme") return ThemeXML() @@ -536,16 +535,16 @@ class ThemeManager(QtGui.QWidget): file_xml = None try: zip = zipfile.ZipFile(file_name) - xmlfile = filter(lambda name: + xml_file = filter(lambda name: os.path.splitext(name)[1].lower() == u'.xml', zip.namelist()) - if len(xmlfile) != 1: - log.exception(u'Theme contains "%s" XML files' % len(xmlfile)) + if len(xml_file) != 1: + log.exception(u'Theme contains "%s" XML files' % len(xml_file)) raise Exception(u'validation') - xml_tree = ElementTree(element=XML(zip.read(xmlfile[0]))).getroot() + xml_tree = ElementTree(element=XML(zip.read(xml_file[0]))).getroot() v1_background = xml_tree.find(u'BackgroundType') if v1_background is not None: theme_name, file_xml, out_file, abort_import = self.unzipVersion122(dir, zip, - xmlfile[0], xml_tree, v1_background, out_file) + xml_file[0], xml_tree, v1_background, out_file) else: theme_name = xml_tree.find(u'name').text.strip() theme_folder = os.path.join(dir, theme_name) @@ -563,18 +562,18 @@ class ThemeManager(QtGui.QWidget): u' "%s"' % name.decode(u'utf-8', u'replace')) raise Exception(u'validation') uname = unicode(QtCore.QDir.toNativeSeparators(uname)) - splitname = uname.split(os.path.sep) - if splitname[-1] == u'' or len(splitname) == 1: + spli_tname = uname.split(os.path.sep) + if spli_tname[-1] == u'' or len(spli_tname) == 1: # is directory or preview file continue - fullname = os.path.join(dir, uname) - check_directory_exists(os.path.dirname(fullname)) + full_name = os.path.join(dir, uname) + check_directory_exists(os.path.dirname(full_name)) if os.path.splitext(uname)[1].lower() == u'.xml': file_xml = unicode(zip.read(name), u'utf-8') - out_file = open(fullname, u'w') + out_file = open(full_name, u'w') out_file.write(file_xml.encode(u'utf-8')) else: - out_file = open(fullname, u'wb') + out_file = open(full_name, u'wb') out_file.write(zip.read(name)) out_file.close() except (IOError, zipfile.BadZipfile): @@ -608,7 +607,7 @@ class ThemeManager(QtGui.QWidget): log.exception(u'Theme file does not contain XML data %s' % file_name) - def unzipVersion122(self, dir, zip, xmlfile, xml_tree, background, out_file): + def unzipVersion122(self, dir, zip, xml_file, xml_tree, background, out_file): """ Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling this method, please keep in mind, that some parameters are redundant. @@ -621,24 +620,24 @@ class ThemeManager(QtGui.QWidget): return '', '', '', True themedir = os.path.join(dir, theme_name) check_directory_exists(themedir) - file_xml = unicode(zip.read(xmlfile), u'utf-8') + file_xml = unicode(zip.read(xml_file), u'utf-8') file_xml = self._migrateVersion122(file_xml) out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w') out_file.write(file_xml.encode(u'utf-8')) out_file.close() if background.text.strip() == u'2': - imagename = xml_tree.find(u'BackgroundParameter1').text.strip() + image_name = xml_tree.find(u'BackgroundParameter1').text.strip() # image file has same extension and is in subfolder imagefile = filter(lambda name: os.path.splitext(name)[1].lower() - == os.path.splitext(imagename)[1].lower() and name.find(r'/'), + == os.path.splitext(image_name)[1].lower() and name.find(r'/'), zip.namelist()) if len(imagefile) >= 1: - out_file = open(os.path.join(themedir, imagename), u'wb') + out_file = open(os.path.join(themedir, image_name), u'wb') out_file.write(zip.read(imagefile[0])) out_file.close() else: log.exception(u'Theme file does not contain image file "%s"' % - imagename.decode(u'utf-8', u'replace')) + image_name.decode(u'utf-8', u'replace')) raise Exception(u'validation') return theme_name, file_xml, out_file, False @@ -658,20 +657,20 @@ class ThemeManager(QtGui.QWidget): return False return True - def saveTheme(self, theme, imageFrom, imageTo): + def saveTheme(self, theme, image_from, image_to): """ Called by thememaintenance Dialog to save the theme and to trigger the reload of the theme list """ - self._writeTheme(theme, imageFrom, imageTo) + self._writeTheme(theme, image_from, image_to) if theme.background_type == \ BackgroundType.to_string(BackgroundType.Image): - self.mainwindow.imageManager.update_image(theme.theme_name, + self.mainWindow.imageManager.update_image(theme.theme_name, u'theme', QtGui.QColor(theme.background_border_color)) - self.mainwindow.imageManager.process_updates() + self.mainWindow.imageManager.process_updates() self.loadThemes() - def _writeTheme(self, theme, imageFrom, imageTo): + def _writeTheme(self, theme, image_from, image_to): """ Writes the theme to the disk and handles the background image if necessary @@ -682,9 +681,9 @@ class ThemeManager(QtGui.QWidget): theme_dir = os.path.join(self.path, name) check_directory_exists(theme_dir) theme_file = os.path.join(theme_dir, name + u'.xml') - if self.oldBackgroundImage and \ - imageTo != self.oldBackgroundImage: - delete_file(self.oldBackgroundImage) + if self.old_background_image and \ + image_to != self.old_background_image: + delete_file(self.old_background_image) out_file = None try: out_file = open(theme_file, u'w') @@ -694,12 +693,12 @@ class ThemeManager(QtGui.QWidget): finally: if out_file: out_file.close() - if imageFrom and imageFrom != imageTo: + if image_from and image_from != image_to: try: encoding = get_filesystem_encoding() shutil.copyfile( - unicode(imageFrom).encode(encoding), - unicode(imageTo).encode(encoding)) + unicode(image_from).encode(encoding), + unicode(image_to).encode(encoding)) except IOError: log.exception(u'Failed to save theme image') self.generateAndSaveImage(self.path, name, theme) @@ -707,39 +706,39 @@ class ThemeManager(QtGui.QWidget): def generateAndSaveImage(self, dir, name, theme): log.debug(u'generateAndSaveImage %s %s', dir, name) frame = self.generateImage(theme) - samplepathname = os.path.join(self.path, name + u'.png') - if os.path.exists(samplepathname): - os.unlink(samplepathname) - frame.save(samplepathname, u'png') - thumb = os.path.join(self.thumbPath, u'%s.png' % name) - create_thumb(samplepathname, thumb, False) - log.debug(u'Theme image written to %s', samplepathname) + sample_path_name = os.path.join(self.path, name + u'.png') + if os.path.exists(sample_path_name): + os.unlink(sample_path_name) + frame.save(sample_path_name, u'png') + thumb = os.path.join(self.thumb_path, u'%s.png' % name) + create_thumb(sample_path_name, thumb, False) + log.debug(u'Theme image written to %s', sample_path_name) def updatePreviewImages(self): """ Called to update the themes' preview images. """ - self.mainwindow.displayProgressBar(len(self.themelist)) - for theme in self.themelist: - self.mainwindow.incrementProgressBar() + self.mainWindow.displayProgressBar(len(self.theme_list)) + for theme in self.theme_list: + self.mainWindow.incrementProgressBar() self.generateAndSaveImage( self.path, theme, self.getThemeData(theme)) - self.mainwindow.finishedProgressBar() + self.mainWindow.finishedProgressBar() self.loadThemes() - def generateImage(self, themeData, forcePage=False): + def generateImage(self, theme_data, forcePage=False): """ Call the renderer to build a Sample Image - ``themeData`` + ``theme_data`` The theme to generated a preview for. ``forcePage`` Flag to tell message lines per page need to be generated. """ - log.debug(u'generateImage \n%s ', themeData) - return self.mainwindow.renderer.generate_preview( - themeData, forcePage) + log.debug(u'generateImage \n%s ', theme_data) + return self.mainWindow.renderer.generate_preview( + theme_data, forcePage) def getPreviewImage(self, theme): """ @@ -752,15 +751,15 @@ class ThemeManager(QtGui.QWidget): image = os.path.join(self.path, theme + u'.png') return image - def _createThemeFromXml(self, themeXml, path): + def _createThemeFromXml(self, theme_xml, path): """ Return a theme object using information parsed from XML - ``themeXml`` + ``theme_xml`` The XML data to load into the theme """ theme = ThemeXML() - theme.parse(themeXml) + theme.parse(theme_xml) theme.extend_image_filename(path) return theme @@ -792,7 +791,7 @@ class ThemeManager(QtGui.QWidget): return False # check for use in the system else where. if testPlugin: - for plugin in self.mainwindow.pluginManager.plugins: + for plugin in self.mainWindow.pluginManager.plugins: if plugin.usesTheme(theme): critical_error_message_box( translate('OpenLP.ThemeManager', @@ -815,53 +814,53 @@ class ThemeManager(QtGui.QWidget): Version 1 theme to convert """ theme = Theme(xml_data) - newtheme = ThemeXML() - newtheme.theme_name = self.bad_v1_name_chars.sub(u'', theme.Name) + new_theme = ThemeXML() + new_theme.theme_name = self.bad_v1_name_chars.sub(u'', theme.Name) if theme.BackgroundType == 0: - newtheme.background_type = \ + new_theme.background_type = \ BackgroundType.to_string(BackgroundType.Solid) - newtheme.background_color = \ + new_theme.background_color = \ unicode(theme.BackgroundParameter1.name()) elif theme.BackgroundType == 1: - newtheme.background_type = \ + new_theme.background_type = \ BackgroundType.to_string(BackgroundType.Gradient) - newtheme.background_direction = \ + new_theme.background_direction = \ BackgroundGradientType. \ to_string(BackgroundGradientType.Horizontal) if theme.BackgroundParameter3.name() == 1: - newtheme.background_direction = \ + new_theme.background_direction = \ BackgroundGradientType. \ to_string(BackgroundGradientType.Horizontal) - newtheme.background_start_color = \ + new_theme.background_start_color = \ unicode(theme.BackgroundParameter1.name()) - newtheme.background_end_color = \ + new_theme.background_end_color = \ unicode(theme.BackgroundParameter2.name()) elif theme.BackgroundType == 2: - newtheme.background_type = \ + new_theme.background_type = \ BackgroundType.to_string(BackgroundType.Image) - newtheme.background_filename = unicode(theme.BackgroundParameter1) + new_theme.background_filename = unicode(theme.BackgroundParameter1) elif theme.BackgroundType == 3: - newtheme.background_type = \ + new_theme.background_type = \ BackgroundType.to_string(BackgroundType.Transparent) - newtheme.font_main_name = theme.FontName - newtheme.font_main_color = unicode(theme.FontColor.name()) - newtheme.font_main_size = theme.FontProportion * 3 - newtheme.font_footer_name = theme.FontName - newtheme.font_footer_color = unicode(theme.FontColor.name()) - newtheme.font_main_shadow = False + new_theme.font_main_name = theme.FontName + new_theme.font_main_color = unicode(theme.FontColor.name()) + new_theme.font_main_size = theme.FontProportion * 3 + new_theme.font_footer_name = theme.FontName + new_theme.font_footer_color = unicode(theme.FontColor.name()) + new_theme.font_main_shadow = False if theme.Shadow == 1: - newtheme.font_main_shadow = True - newtheme.font_main_shadow_color = unicode(theme.ShadowColor.name()) + new_theme.font_main_shadow = True + new_theme.font_main_shadow_color = unicode(theme.ShadowColor.name()) if theme.Outline == 1: - newtheme.font_main_outline = True - newtheme.font_main_outline_color = \ + new_theme.font_main_outline = True + new_theme.font_main_outline_color = \ unicode(theme.OutlineColor.name()) vAlignCorrection = VerticalType.Top if theme.VerticalAlign == 2: vAlignCorrection = VerticalType.Middle elif theme.VerticalAlign == 1: vAlignCorrection = VerticalType.Bottom - newtheme.display_horizontal_align = theme.HorizontalAlign - newtheme.display_vertical_align = vAlignCorrection - return newtheme.extract_xml() + new_theme.display_horizontal_align = theme.HorizontalAlign + new_theme.display_vertical_align = vAlignCorrection + return new_theme.extract_xml() From 24b817cccf63072b332f2ef4347644467c9499fd Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 16:14:07 +0000 Subject: [PATCH 4/7] More minor fixes --- openlp/core/ui/thememanager.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index eb022bb25..d3762654d 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -513,9 +513,9 @@ class ThemeManager(QtGui.QWidget): def overWriteMessageBox(self, theme_name): ret = QtGui.QMessageBox.question(self, - translate('OpenLP.ThemeManager', 'Theme Already Exists!'), + translate('OpenLP.ThemeManager', 'Theme Already Exists.'), translate('OpenLP.ThemeManager', - 'The theme %s already exists. Do you want to replace it?' + 'Theme %s already exists. Do you want to replace it?' % theme_name), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), @@ -617,7 +617,7 @@ class ThemeManager(QtGui.QWidget): theme_folder = os.path.join(dir, theme_name) theme_exists = os.path.exists(theme_folder) if theme_exists and not self.overWriteMessageBox(theme_name): - return '', '', '', True + return '', '', '', True themedir = os.path.join(dir, theme_name) check_directory_exists(themedir) file_xml = unicode(zip.read(xml_file), u'utf-8') From df5447098868c76cf54502324ab4b366d67b6dc3 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 16:44:58 +0000 Subject: [PATCH 5/7] Few more minor fixes --- openlp/core/ui/thememanager.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index d3762654d..a9ef4be14 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -52,9 +52,9 @@ class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. """ - def __init__(self, mainWindow, parent=None): + def __init__(self, main_window, parent=None): QtGui.QWidget.__init__(self, parent) - self.mainWindow = mainWindow + self.main_window = main_window self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) @@ -282,7 +282,7 @@ class ThemeManager(QtGui.QWidget): old_theme_data = self.getThemeData(old_theme_name) self.cloneThemeData(old_theme_data, new_theme_name) self.deleteTheme(old_theme_name) - for plugin in self.mainWindow.pluginManager.plugins: + for plugin in self.main_window.pluginManager.plugins: if plugin.usesTheme(old_theme_name): plugin.renameTheme(old_theme_name, new_theme_name) self.loadThemes() @@ -295,7 +295,7 @@ class ThemeManager(QtGui.QWidget): old_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString()) self.fileRenameForm.fileNameEdit.setText( unicode(translate('OpenLP.ThemeManager', - 'Copy of %s','Copy of ')) % old_theme_name) + 'Copy of %s', 'Copy of ')) % old_theme_name) if self.fileRenameForm.exec_(True): new_theme_name = unicode(self.fileRenameForm.fileNameEdit.text()) if self.checkIfThemeExists(new_theme_name): @@ -513,7 +513,7 @@ class ThemeManager(QtGui.QWidget): def overWriteMessageBox(self, theme_name): ret = QtGui.QMessageBox.question(self, - translate('OpenLP.ThemeManager', 'Theme Already Exists.'), + translate('OpenLP.ThemeManager', 'Theme Already Exists'), translate('OpenLP.ThemeManager', 'Theme %s already exists. Do you want to replace it?' % theme_name), @@ -562,8 +562,8 @@ class ThemeManager(QtGui.QWidget): u' "%s"' % name.decode(u'utf-8', u'replace')) raise Exception(u'validation') uname = unicode(QtCore.QDir.toNativeSeparators(uname)) - spli_tname = uname.split(os.path.sep) - if spli_tname[-1] == u'' or len(spli_tname) == 1: + split_name = uname.split(os.path.sep) + if split_name[-1] == u'' or len(split_name) == 1: # is directory or preview file continue full_name = os.path.join(dir, uname) @@ -614,7 +614,7 @@ class ThemeManager(QtGui.QWidget): """ theme_name = xml_tree.find(u'Name').text.strip() theme_name = self.bad_v1_name_chars.sub(u'', theme_name) - theme_folder = os.path.join(dir, theme_name) + theme_folder = os.path.join(dir, theme_name) theme_exists = os.path.exists(theme_folder) if theme_exists and not self.overWriteMessageBox(theme_name): return '', '', '', True From f8021d315ea8045be1abcef31c3f6ab54a39417e Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 17:13:19 +0000 Subject: [PATCH 6/7] fixed mainWindow this time! --- openlp/core/ui/thememanager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a9ef4be14..5782ea39f 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -665,9 +665,9 @@ class ThemeManager(QtGui.QWidget): self._writeTheme(theme, image_from, image_to) if theme.background_type == \ BackgroundType.to_string(BackgroundType.Image): - self.mainWindow.imageManager.update_image(theme.theme_name, + self.main_window.imageManager.update_image(theme.theme_name, u'theme', QtGui.QColor(theme.background_border_color)) - self.mainWindow.imageManager.process_updates() + self.main_window.imageManager.process_updates() self.loadThemes() def _writeTheme(self, theme, image_from, image_to): @@ -718,12 +718,12 @@ class ThemeManager(QtGui.QWidget): """ Called to update the themes' preview images. """ - self.mainWindow.displayProgressBar(len(self.theme_list)) + self.main_window.displayProgressBar(len(self.theme_list)) for theme in self.theme_list: - self.mainWindow.incrementProgressBar() + self.main_window.incrementProgressBar() self.generateAndSaveImage( self.path, theme, self.getThemeData(theme)) - self.mainWindow.finishedProgressBar() + self.main_window.finishedProgressBar() self.loadThemes() def generateImage(self, theme_data, forcePage=False): @@ -737,7 +737,7 @@ class ThemeManager(QtGui.QWidget): Flag to tell message lines per page need to be generated. """ log.debug(u'generateImage \n%s ', theme_data) - return self.mainWindow.renderer.generate_preview( + return self.main_window.renderer.generate_preview( theme_data, forcePage) def getPreviewImage(self, theme): @@ -791,7 +791,7 @@ class ThemeManager(QtGui.QWidget): return False # check for use in the system else where. if testPlugin: - for plugin in self.mainWindow.pluginManager.plugins: + for plugin in self.main_window.pluginManager.plugins: if plugin.usesTheme(theme): critical_error_message_box( translate('OpenLP.ThemeManager', From 8f0e2ba8ec72f4cd36c7bf3785dbda3a8ec2eeb4 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Mar 2012 22:18:52 +0000 Subject: [PATCH 7/7] Fixed mainwindow bug --- openlp/core/ui/thememanager.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 5782ea39f..6ba2e87c2 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -52,9 +52,9 @@ class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. """ - def __init__(self, main_window, parent=None): + def __init__(self, mainwindow, parent=None): QtGui.QWidget.__init__(self, parent) - self.main_window = main_window + self.mainwindow = mainwindow self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) @@ -282,7 +282,7 @@ class ThemeManager(QtGui.QWidget): old_theme_data = self.getThemeData(old_theme_name) self.cloneThemeData(old_theme_data, new_theme_name) self.deleteTheme(old_theme_name) - for plugin in self.main_window.pluginManager.plugins: + for plugin in self.mainwindow.pluginManager.plugins: if plugin.usesTheme(old_theme_name): plugin.renameTheme(old_theme_name, new_theme_name) self.loadThemes() @@ -665,9 +665,9 @@ class ThemeManager(QtGui.QWidget): self._writeTheme(theme, image_from, image_to) if theme.background_type == \ BackgroundType.to_string(BackgroundType.Image): - self.main_window.imageManager.update_image(theme.theme_name, + self.mainwindow.imageManager.update_image(theme.theme_name, u'theme', QtGui.QColor(theme.background_border_color)) - self.main_window.imageManager.process_updates() + self.mainwindow.imageManager.process_updates() self.loadThemes() def _writeTheme(self, theme, image_from, image_to): @@ -718,12 +718,12 @@ class ThemeManager(QtGui.QWidget): """ Called to update the themes' preview images. """ - self.main_window.displayProgressBar(len(self.theme_list)) + self.mainwindow.displayProgressBar(len(self.theme_list)) for theme in self.theme_list: - self.main_window.incrementProgressBar() + self.mainwindow.incrementProgressBar() self.generateAndSaveImage( self.path, theme, self.getThemeData(theme)) - self.main_window.finishedProgressBar() + self.mainwindow.finishedProgressBar() self.loadThemes() def generateImage(self, theme_data, forcePage=False): @@ -737,7 +737,7 @@ class ThemeManager(QtGui.QWidget): Flag to tell message lines per page need to be generated. """ log.debug(u'generateImage \n%s ', theme_data) - return self.main_window.renderer.generate_preview( + return self.mainwindow.renderer.generate_preview( theme_data, forcePage) def getPreviewImage(self, theme): @@ -791,7 +791,7 @@ class ThemeManager(QtGui.QWidget): return False # check for use in the system else where. if testPlugin: - for plugin in self.main_window.pluginManager.plugins: + for plugin in self.mainwindow.pluginManager.plugins: if plugin.usesTheme(theme): critical_error_message_box( translate('OpenLP.ThemeManager',