Fix Theme Image copy Bug

Clean up Theme Rename and Copy bugs

bzr-revno: 1271
Fixes: https://launchpad.net/bugs/712097
This commit is contained in:
Tim Bentley 2011-02-05 11:04:26 +00:00
commit 7b30ceb0f3
2 changed files with 20 additions and 12 deletions

View File

@ -241,7 +241,7 @@ class ThemeManager(QtGui.QWidget):
QtCore.QVariant(self.global_theme)) QtCore.QVariant(self.global_theme))
Receiver.send_message(u'theme_update_global', Receiver.send_message(u'theme_update_global',
self.global_theme) self.global_theme)
self.pushThemes() self._pushThemes()
def onAddTheme(self): def onAddTheme(self):
""" """
@ -268,11 +268,12 @@ class ThemeManager(QtGui.QWidget):
newThemeName = unicode(self.fileRenameForm.fileNameEdit.text()) newThemeName = unicode(self.fileRenameForm.fileNameEdit.text())
if self.checkIfThemeExists(newThemeName): if self.checkIfThemeExists(newThemeName):
oldThemeData = self.getThemeData(oldThemeName) oldThemeData = self.getThemeData(oldThemeName)
self.deleteTheme(oldThemeName)
self.cloneThemeData(oldThemeData, newThemeName) self.cloneThemeData(oldThemeData, newThemeName)
self.deleteTheme(oldThemeName)
for plugin in self.mainwindow.pluginManager.plugins: for plugin in self.mainwindow.pluginManager.plugins:
if plugin.usesTheme(oldThemeName): if plugin.usesTheme(oldThemeName):
plugin.renameTheme(oldThemeName, newThemeName) plugin.renameTheme(oldThemeName, newThemeName)
self.loadThemes()
def onCopyTheme(self): def onCopyTheme(self):
""" """
@ -300,6 +301,7 @@ class ThemeManager(QtGui.QWidget):
os.path.split(unicode(themeData.background_filename))[1]) os.path.split(unicode(themeData.background_filename))[1])
saveFrom = themeData.background_filename saveFrom = themeData.background_filename
themeData.theme_name = newThemeName themeData.theme_name = newThemeName
themeData.extend_image_filename(self.path)
self.saveTheme(themeData, saveFrom, saveTo) self.saveTheme(themeData, saveFrom, saveTo)
def onEditTheme(self): def onEditTheme(self):
@ -332,6 +334,10 @@ class ThemeManager(QtGui.QWidget):
row = self.themeListWidget.row(item) row = self.themeListWidget.row(item)
self.themeListWidget.takeItem(row) self.themeListWidget.takeItem(row)
self.deleteTheme(theme) self.deleteTheme(theme)
# As we do not reload the themes, push out the change
# Reaload the list as the internal lists and events need
# to be triggered
self._pushThemes()
def deleteTheme(self, theme): def deleteTheme(self, theme):
""" """
@ -349,10 +355,6 @@ class ThemeManager(QtGui.QWidget):
shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
except OSError: except OSError:
log.exception(u'Error deleting theme %s', theme) log.exception(u'Error deleting theme %s', theme)
# As we do not reload the themes push out the change
# Reaload the list as the internal lists and events need
# to be triggered
self.pushThemes()
def onExportTheme(self): def onExportTheme(self):
""" """
@ -449,9 +451,9 @@ class ThemeManager(QtGui.QWidget):
QtCore.QVariant(textName)) QtCore.QVariant(textName))
self.themeListWidget.addItem(item_name) self.themeListWidget.addItem(item_name)
self.themelist.append(textName) self.themelist.append(textName)
self.pushThemes() self._pushThemes()
def pushThemes(self): def _pushThemes(self):
""" """
Notify listeners that the theme list has been updated Notify listeners that the theme list has been updated
""" """
@ -571,6 +573,14 @@ class ThemeManager(QtGui.QWidget):
Called by thememaintenance Dialog to save the theme Called by thememaintenance Dialog to save the theme
and to trigger the reload of the theme list and to trigger the reload of the theme list
""" """
self._writeTheme(theme, imageFrom, imageTo)
self.loadThemes()
def _writeTheme(self, theme, imageFrom, imageTo):
"""
Writes the theme to the disk and handles the background image if
necessary
"""
name = theme.theme_name name = theme.theme_name
theme_pretty_xml = theme.extract_formatted_xml() theme_pretty_xml = theme.extract_formatted_xml()
log.debug(u'saveTheme %s %s', name, theme_pretty_xml) log.debug(u'saveTheme %s %s', name, theme_pretty_xml)
@ -598,12 +608,9 @@ class ThemeManager(QtGui.QWidget):
except IOError: except IOError:
log.exception(u'Failed to save theme image') log.exception(u'Failed to save theme image')
self.generateAndSaveImage(self.path, name, theme) self.generateAndSaveImage(self.path, name, theme)
self.loadThemes()
self.pushThemes()
def generateAndSaveImage(self, dir, name, theme): def generateAndSaveImage(self, dir, name, theme):
log.debug(u'generateAndSaveImage %s %s', dir, name) log.debug(u'generateAndSaveImage %s %s', dir, name)
theme_xml = theme.extract_xml()
frame = self.generateImage(theme) frame = self.generateImage(theme)
samplepathname = os.path.join(self.path, name + u'.png') samplepathname = os.path.join(self.path, name + u'.png')
if os.path.exists(samplepathname): if os.path.exists(samplepathname):

View File

@ -102,7 +102,7 @@ class BiblePlugin(Plugin):
Called to find out if the bible plugin is currently using a theme. Called to find out if the bible plugin is currently using a theme.
Returns True if the theme is being used, otherwise returns False. Returns True if the theme is being used, otherwise returns False.
""" """
if self.settings_tab.bible_theme == theme: if unicode(self.settings_tab.bible_theme) == theme:
return True return True
return False return False
@ -119,6 +119,7 @@ class BiblePlugin(Plugin):
The new name the plugin should now use. The new name the plugin should now use.
""" """
self.settings_tab.bible_theme = newTheme self.settings_tab.bible_theme = newTheme
self.settings_tab.save()
def setPluginTextStrings(self): def setPluginTextStrings(self):
""" """