openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #02452
[Merge] lp:~meths/openlp/testing into lp:openlp
Jon Tibble has proposed merging lp:~meths/openlp/testing into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Properly handles theme name editing.
--
https://code.launchpad.net/~meths/openlp/testing/+merge/29747
Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/testing into lp:openlp.
=== modified file 'openlp/core/lib/plugin.py'
--- openlp/core/lib/plugin.py 2010-07-05 16:00:48 +0000
+++ openlp/core/lib/plugin.py 2010-07-12 21:22:47 +0000
@@ -269,8 +269,22 @@
if self.settings_tab:
self.settingsForm.insertTab(self.settings_tab, self.weight)
- def canDeleteTheme(self, theme):
- """
- Called to ask the plugin if a theme can be deleted
- """
- return True
\ No newline at end of file
+ def usesTheme(self, theme):
+ """
+ Called to find out if a plugin is currently using a theme.
+
+ Returns True if the theme is being used, otherwise returns False.
+ """
+ return False
+
+ def renameTheme(self, oldTheme, newTheme):
+ """
+ Renames a theme a plugin is using making the plugin use the new name.
+
+ ``oldTheme``
+ The name of the theme the plugin should stop using.
+
+ ``newTheme``
+ The new name the plugin should now use.
+ """
+ pass
=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py 2010-07-06 12:58:33 +0000
+++ openlp/core/ui/amendthemeform.py 2010-07-12 21:22:47 +0000
@@ -36,15 +36,21 @@
log = logging.getLogger(u'AmendThemeForm')
class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
-
+ """
+ The :class:`AmendThemeForm` class provides the user interface to set up
+ new and edit existing themes.
+ """
def __init__(self, parent):
+ """
+ Initialise the theme editor user interface
+ """
QtGui.QDialog.__init__(self, parent)
self.thememanager = parent
self.path = None
self.theme = ThemeXML()
self.setupUi(self)
- #define signals
- #Buttons
+ # define signals
+ # Buttons
QtCore.QObject.connect(self.Color1PushButton,
QtCore.SIGNAL(u'pressed()'), self.onColor1PushButtonClicked)
QtCore.QObject.connect(self.Color2PushButton,
@@ -60,7 +66,7 @@
QtCore.SIGNAL(u'pressed()'), self.onShadowColorPushButtonClicked)
QtCore.QObject.connect(self.ImageToolButton,
QtCore.SIGNAL(u'pressed()'), self.onImageToolButtonClicked)
- #Combo boxes
+ # Combo boxes
QtCore.QObject.connect(self.BackgroundComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onBackgroundComboBoxSelected)
QtCore.QObject.connect(self.BackgroundTypeComboBox,
@@ -82,16 +88,13 @@
QtCore.SIGNAL(u'activated(int)'), self.onHorizontalComboBoxSelected)
QtCore.QObject.connect(self.VerticalComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onVerticalComboBoxSelected)
- #Spin boxes
+ # Spin boxes
QtCore.QObject.connect(self.FontMainSizeSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onFontMainSizeSpinBoxChanged)
QtCore.QObject.connect(self.FontFooterSizeSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onFontFooterSizeSpinBoxChanged)
- QtCore.QObject.connect(self.FontMainDefaultCheckBox,
- QtCore.SIGNAL(u'stateChanged(int)'),
- self.onFontMainDefaultCheckBoxChanged)
QtCore.QObject.connect(self.FontMainXSpinBox,
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainXSpinBoxChanged)
QtCore.QObject.connect(self.FontMainYSpinBox,
@@ -108,9 +111,6 @@
QtCore.QObject.connect(self.FontMainLineSpacingSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onFontMainLineSpacingSpinBoxChanged)
- QtCore.QObject.connect(self.FontFooterDefaultCheckBox,
- QtCore.SIGNAL(u'stateChanged(int)'),
- self.onFontFooterDefaultCheckBoxChanged)
QtCore.QObject.connect(self.FontFooterXSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onFontFooterXSpinBoxChanged)
@@ -123,16 +123,23 @@
QtCore.QObject.connect(self.FontFooterHeightSpinBox,
QtCore.SIGNAL(u'editingFinished()'),
self.onFontFooterHeightSpinBoxChanged)
+ QtCore.QObject.connect(self.ShadowSpinBox,
+ QtCore.SIGNAL(u'editingFinished()'),
+ self.onShadowSpinBoxChanged)
+ QtCore.QObject.connect(self.OutlineSpinBox,
+ QtCore.SIGNAL(u'editingFinished()'),
+ self.onOutlineSpinBoxChanged)
+ # CheckBoxes
+ QtCore.QObject.connect(self.FontMainDefaultCheckBox,
+ QtCore.SIGNAL(u'stateChanged(int)'),
+ self.onFontMainDefaultCheckBoxChanged)
+ QtCore.QObject.connect(self.FontFooterDefaultCheckBox,
+ QtCore.SIGNAL(u'stateChanged(int)'),
+ self.onFontFooterDefaultCheckBoxChanged)
QtCore.QObject.connect(self.OutlineCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'), self.onOutlineCheckBoxChanged)
- QtCore.QObject.connect(self.ShadowSpinBox,
- QtCore.SIGNAL(u'editingFinished()'),
- self.onShadowSpinBoxChanged)
QtCore.QObject.connect(self.ShadowCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'), self.onShadowCheckBoxChanged)
- QtCore.QObject.connect(self.OutlineSpinBox,
- QtCore.SIGNAL(u'editingFinished()'),
- self.onOutlineSpinBoxChanged)
QtCore.QObject.connect(self.SlideTransitionCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onSlideTransitionCheckBoxChanged)
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2010-07-05 16:00:48 +0000
+++ openlp/core/ui/thememanager.py 2010-07-12 21:22:47 +0000
@@ -48,6 +48,7 @@
QtGui.QWidget.__init__(self, parent)
self.parent = parent
self.settingsSection = u'themes'
+ self.serviceComboBox = self.parent.ServiceManagerContents.ThemeComboBox
self.Layout = QtGui.QVBoxLayout(self)
self.Layout.setSpacing(0)
self.Layout.setMargin(0)
@@ -182,9 +183,13 @@
Loads the settings for the theme that is to be edited and launches the
theme editing form so the user can make their changes.
"""
+ self.editingDefault = False
if check_item_selected(self.ThemeListWidget, translate('ThemeManager',
'You must select a theme to edit.')):
item = self.ThemeListWidget.currentItem()
+ themeName = unicode(item.text())
+ if themeName != unicode(item.data(QtCore.Qt.UserRole).toString()):
+ self.editingDefault = True
theme = self.getThemeData(
unicode(item.data(QtCore.Qt.UserRole).toString()))
self.amendThemeForm.loadTheme(theme)
@@ -208,41 +213,48 @@
QtGui.QMessageBox.critical(self,
translate('ThemeManager', 'Error'),
translate('ThemeManager',
- 'You are unable to delete the default theme.'),
+ 'You are unable to delete the default theme.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
else:
for plugin in self.parent.plugin_manager.plugins:
- if not plugin.canDeleteTheme(theme):
+ if plugin.usesTheme(theme):
QtGui.QMessageBox.critical(self,
translate('ThemeManager', 'Error'),
unicode(translate('ThemeManager',
- 'Theme %s is use in %s plugin.')) % \
- (theme, plugin.name))
+ 'Theme %s is use in %s plugin.')) % \
+ (theme, plugin.name))
return
- if unicode(self.parent.ServiceManagerContents.ThemeComboBox \
- .currentText()) == theme:
+ if unicode(self.serviceComboBox.currentText()) == theme:
QtGui.QMessageBox.critical(self,
translate('ThemeManager', 'Error'),
unicode(translate('ThemeManager',
- 'Theme %s is use by the service manager.')) % theme)
+ 'Theme %s is use by the service manager.')) % theme)
return
- self.themelist.remove(theme)
- th = theme + u'.png'
row = self.ThemeListWidget.row(item)
self.ThemeListWidget.takeItem(row)
- try:
- os.remove(os.path.join(self.path, th))
- os.remove(os.path.join(self.thumbPath, th))
- encoding = get_filesystem_encoding()
- shutil.rmtree(
- os.path.join(self.path, theme).encode(encoding))
- except OSError:
- #if not present do not worry
- pass
- # 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()
+ self.deleteTheme(theme)
+
+ def deleteTheme(self, theme):
+ """
+ Delete a theme.
+
+ ``theme``
+ The theme to delete.
+ """
+ self.themelist.remove(theme)
+ th = theme + u'.png'
+ try:
+ os.remove(os.path.join(self.path, th))
+ os.remove(os.path.join(self.thumbPath, th))
+ encoding = get_filesystem_encoding()
+ shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
+ except OSError:
+ #if not present do not worry
+ pass
+ # 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):
"""
@@ -532,16 +544,23 @@
os.mkdir(os.path.join(self.path, name))
theme_file = os.path.join(theme_dir, name + u'.xml')
log.debug(theme_file)
+ editedServiceTheme = False
result = QtGui.QMessageBox.Yes
if self.saveThemeName != name:
if os.path.exists(theme_file):
result = QtGui.QMessageBox.question(self,
translate('ThemeManager', 'Theme Exists'),
- translate('ThemeManager',
- 'A theme with this name already exists. '
- 'Would you like to overwrite it?'),
+ translate('ThemeManager', 'A theme with this name already '
+ 'exists. Would you like to overwrite it?'),
(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
+ if self.saveThemeName != u'':
+ for plugin in self.parent.plugin_manager.plugins:
+ if plugin.usesTheme(self.saveThemeName):
+ plugin.renameTheme(self.saveThemeName, name)
+ if unicode(self.serviceComboBox.currentText()) == name:
+ editedServiceTheme = True
+ self.deleteTheme(self.saveThemeName)
if result == QtGui.QMessageBox.Yes:
# Save the theme, overwriting the existing theme if necessary.
outfile = None
@@ -563,6 +582,26 @@
log.exception(u'Failed to save theme image')
self.generateAndSaveImage(self.path, name, theme_xml)
self.loadThemes()
+ # Check if we need to set a new service theme
+ if editedServiceTheme:
+ newThemeIndex = self.serviceComboBox.findText(name)
+ if newThemeIndex != -1:
+ self.serviceComboBox.setCurrentIndex(newThemeIndex)
+ if self.editingDefault:
+ newThemeItem = self.ThemeListWidget.findItems(name,
+ QtCore.Qt.MatchExactly)[0]
+ newThemeIndex = self.ThemeListWidget.indexFromItem(
+ newThemeItem).row()
+ self.global_theme = unicode(
+ self.ThemeListWidget.item(newThemeIndex).text())
+ newName = unicode(translate('ThemeManager', '%s (default)')) % \
+ self.global_theme
+ self.ThemeListWidget.item(newThemeIndex).setText(newName)
+ QtCore.QSettings().setValue(
+ self.settingsSection + u'/global theme',
+ QtCore.QVariant(self.global_theme))
+ Receiver.send_message(u'theme_update_global', self.global_theme)
+ self.pushThemes()
else:
# Don't close the dialog - allow the user to change the name of
# the theme or to cancel the theme dialog completely.
=== modified file 'openlp/plugins/bibles/bibleplugin.py'
--- openlp/plugins/bibles/bibleplugin.py 2010-07-10 01:01:14 +0000
+++ openlp/plugins/bibles/bibleplugin.py 2010-07-12 21:22:47 +0000
@@ -95,7 +95,26 @@
'displayed on the screen during the service.')
return about_text
- def canDeleteTheme(self, theme):
+ def usesTheme(self, 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.
+ """
if self.settings_tab.bible_theme == theme:
- return False
- return True
\ No newline at end of file
+ return True
+ return False
+
+ def renameTheme(self, oldTheme, newTheme):
+ """
+ Rename the theme the bible plugin is using making the plugin use the
+ new name.
+
+ ``oldTheme``
+ The name of the theme the plugin should stop using. Unused for
+ this particular plugin.
+
+ ``newTheme``
+ The new name the plugin should now use.
+ """
+ self.settings_tab.bible_theme = newTheme
=== modified file 'openlp/plugins/custom/customplugin.py'
--- openlp/plugins/custom/customplugin.py 2010-07-10 01:01:14 +0000
+++ openlp/plugins/custom/customplugin.py 2010-07-12 21:22:47 +0000
@@ -69,8 +69,30 @@
'songs plugin.<br>')
return about_text
- def canDeleteTheme(self, theme):
- if not self.custommanager.get_all_objects_filtered(CustomSlide,
+ def usesTheme(self, theme):
+ """
+ Called to find out if the custom plugin is currently using a theme.
+
+ Returns True if the theme is being used, otherwise returns False.
+ """
+ if self.custommanager.get_all_objects_filtered(CustomSlide,
CustomSlide.theme_name == theme):
return True
- return False
\ No newline at end of file
+ return False
+
+ def renameTheme(self, oldTheme, newTheme):
+ """
+ Renames a theme the custom plugin is using making the plugin use the
+ new name.
+
+ ``oldTheme``
+ The name of the theme the plugin should stop using.
+
+ ``newTheme``
+ The new name the plugin should now use.
+ """
+ customsUsingTheme = self.custommanager.get_all_objects_filtered(
+ CustomSlide, CustomSlide.theme_name == oldTheme)
+ for custom in customsUsingTheme:
+ custom.theme_name = newTheme
+ self.custommanager.save_object(custom)
=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py 2010-07-10 01:01:14 +0000
+++ openlp/plugins/songs/songsplugin.py 2010-07-12 21:22:47 +0000
@@ -192,8 +192,30 @@
'This plugin allows songs to be managed and displayed.')
return about_text
- def canDeleteTheme(self, theme):
- if not self.manager.get_all_objects_filtered(Song,
+ def usesTheme(self, theme):
+ """
+ Called to find out if the song plugin is currently using a theme.
+
+ Returns True if the theme is being used, otherwise returns False.
+ """
+ if self.manager.get_all_objects_filtered(Song,
Song.theme_name == theme):
return True
- return False
\ No newline at end of file
+ return False
+
+ def renameTheme(self, oldTheme, newTheme):
+ """
+ Renames a theme the song plugin is using making the plugin use the new
+ name.
+
+ ``oldTheme``
+ The name of the theme the plugin should stop using.
+
+ ``newTheme``
+ The new name the plugin should now use.
+ """
+ songsUsingTheme = self.manager.get_all_objects_filtered(Song,
+ Song.theme_name == oldTheme)
+ for song in songsUsingTheme:
+ song.theme_name = newTheme
+ self.custommanager.save_object(song)
Follow ups