Clean up custom plugin

This commit is contained in:
Tim Bentley 2013-02-19 21:23:56 +00:00
parent 17e367c6ba
commit 5ca6d36935
18 changed files with 267 additions and 263 deletions

View File

@ -148,7 +148,7 @@ class Plugin(QtCore.QObject):
QtCore.QObject.__init__(self)
self.name = name
self.textStrings = {}
self.setPluginTextStrings()
self.set_plugin_text_strings()
self.nameStrings = self.textStrings[StringContent.Name]
if version:
self.version = version
@ -319,7 +319,7 @@ class Plugin(QtCore.QObject):
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.name), loaded_list)
settings.endGroup()
def usesTheme(self, theme):
def uses_theme(self, theme):
"""
Called to find out if a plugin is currently using a theme.
@ -327,7 +327,7 @@ class Plugin(QtCore.QObject):
"""
return False
def renameTheme(self, oldTheme, newTheme):
def rename_theme(self, oldTheme, newTheme):
"""
Renames a theme a plugin is using making the plugin use the new name.

View File

@ -269,8 +269,8 @@ class ThemeManager(QtGui.QWidget):
self.cloneThemeData(old_theme_data, new_theme_name)
self.delete_theme(old_theme_name)
for plugin in self.plugin_manager.plugins:
if plugin.usesTheme(old_theme_name):
plugin.renameTheme(old_theme_name, new_theme_name)
if plugin.uses_theme(old_theme_name):
plugin.rename_theme(old_theme_name, new_theme_name)
self.renderer.update_theme(new_theme_name, old_theme_name)
self.load_themes()
@ -755,7 +755,7 @@ class ThemeManager(QtGui.QWidget):
# check for use in the system else where.
if testPlugin:
for plugin in self.plugin_manager.plugins:
if plugin.usesTheme(theme):
if plugin.uses_theme(theme):
critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'),
translate('OpenLP.ThemeManager', 'Theme %s is used in the %s plugin.') %
(theme, plugin.name))

View File

@ -184,7 +184,7 @@ class AlertsPlugin(Plugin):
'<br />The alert plugin controls the displaying of nursery alerts on the display screen.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -164,7 +164,7 @@ class BiblePlugin(Plugin):
'verses from different sources during the service.')
return about_text
def usesTheme(self, theme):
def uses_theme(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
@ -172,7 +172,7 @@ class BiblePlugin(Plugin):
"""
return unicode(self.settingsTab.bible_theme) == theme
def renameTheme(self, oldTheme, newTheme):
def rename_theme(self, oldTheme, newTheme):
"""
Rename the theme the bible plugin is using making the plugin use the
new name.
@ -187,7 +187,7 @@ class BiblePlugin(Plugin):
self.settingsTab.bible_theme = newTheme
self.settingsTab.save()
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -73,7 +73,7 @@ class CustomPlugin(Plugin):
'the same way songs are. This plugin provides greater freedom over the songs plugin.')
return about_text
def usesTheme(self, theme):
def uses_theme(self, theme):
"""
Called to find out if the custom plugin is currently using a theme.
@ -83,7 +83,7 @@ class CustomPlugin(Plugin):
return True
return False
def renameTheme(self, oldTheme, newTheme):
def rename_theme(self, oldTheme, newTheme):
"""
Renames a theme the custom plugin is using making the plugin use the
new name.
@ -94,12 +94,12 @@ class CustomPlugin(Plugin):
``newTheme``
The new name the plugin should now use.
"""
customsUsingTheme = self.manager.get_all_objects(CustomSlide, CustomSlide.theme_name == oldTheme)
for custom in customsUsingTheme:
customs_using_theme = self.manager.get_all_objects(CustomSlide, CustomSlide.theme_name == oldTheme)
for custom in customs_using_theme:
custom.theme_name = newTheme
self.manager.save_object(custom)
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -32,84 +32,86 @@ from PyQt4 import QtGui
from openlp.core.lib import UiStrings, build_icon, translate
from openlp.core.lib.ui import create_button_box, create_button
class Ui_CustomEditDialog(object):
def setupUi(self, customEditDialog):
customEditDialog.setObjectName(u'customEditDialog')
customEditDialog.resize(450, 350)
customEditDialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png'))
self.dialogLayout = QtGui.QVBoxLayout(customEditDialog)
self.dialogLayout.setObjectName(u'dialog_layout')
self.titleLayout = QtGui.QHBoxLayout()
self.titleLayout.setObjectName(u'titleLayout')
self.titleLabel = QtGui.QLabel(customEditDialog)
self.titleLabel.setObjectName(u'titleLabel')
self.titleLayout.addWidget(self.titleLabel)
self.titleEdit = QtGui.QLineEdit(customEditDialog)
self.titleLabel.setBuddy(self.titleEdit)
self.titleEdit.setObjectName(u'titleEdit')
self.titleLayout.addWidget(self.titleEdit)
self.dialogLayout.addLayout(self.titleLayout)
self.centralLayout = QtGui.QHBoxLayout()
self.centralLayout.setObjectName(u'centralLayout')
self.slideListView = QtGui.QListWidget(customEditDialog)
self.slideListView.setAlternatingRowColors(True)
self.slideListView.setObjectName(u'slideListView')
self.centralLayout.addWidget(self.slideListView)
self.buttonLayout = QtGui.QVBoxLayout()
self.buttonLayout.setObjectName(u'buttonLayout')
self.addButton = QtGui.QPushButton(customEditDialog)
self.addButton.setObjectName(u'addButton')
self.buttonLayout.addWidget(self.addButton)
self.editButton = QtGui.QPushButton(customEditDialog)
self.editButton.setEnabled(False)
self.editButton.setObjectName(u'editButton')
self.buttonLayout.addWidget(self.editButton)
self.editAllButton = QtGui.QPushButton(customEditDialog)
self.editAllButton.setObjectName(u'editAllButton')
self.buttonLayout.addWidget(self.editAllButton)
self.deleteButton = create_button(customEditDialog, u'deleteButton', role=u'delete',
click=customEditDialog.onDeleteButtonClicked)
self.deleteButton.setEnabled(False)
self.buttonLayout.addWidget(self.deleteButton)
self.buttonLayout.addStretch()
self.upButton = create_button(customEditDialog, u'upButton', role=u'up', enabled=False,
click=customEditDialog.onUpButtonClicked)
self.downButton = create_button(customEditDialog, u'downButton', role=u'down', enabled=False,
click=customEditDialog.onDownButtonClicked)
self.buttonLayout.addWidget(self.upButton)
self.buttonLayout.addWidget(self.downButton)
self.centralLayout.addLayout(self.buttonLayout)
self.dialogLayout.addLayout(self.centralLayout)
self.bottomFormLayout = QtGui.QFormLayout()
self.bottomFormLayout.setObjectName(u'bottomFormLayout')
self.themeLabel = QtGui.QLabel(customEditDialog)
self.themeLabel.setObjectName(u'themeLabel')
self.themeComboBox = QtGui.QComboBox(customEditDialog)
self.themeComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.themeComboBox.setObjectName(u'themeComboBox')
self.themeLabel.setBuddy(self.themeComboBox)
self.bottomFormLayout.addRow(self.themeLabel, self.themeComboBox)
self.creditLabel = QtGui.QLabel(customEditDialog)
self.creditLabel.setObjectName(u'creditLabel')
self.creditEdit = QtGui.QLineEdit(customEditDialog)
self.creditEdit.setObjectName(u'creditEdit')
self.creditLabel.setBuddy(self.creditEdit)
self.bottomFormLayout.addRow(self.creditLabel, self.creditEdit)
self.dialogLayout.addLayout(self.bottomFormLayout)
self.previewButton = QtGui.QPushButton()
self.button_box = create_button_box(customEditDialog, u'button_box', [u'cancel', u'save'], [self.previewButton])
self.dialogLayout.addWidget(self.button_box)
self.retranslateUi(customEditDialog)
def retranslateUi(self, customEditDialog):
customEditDialog.setWindowTitle(translate('CustomPlugin.EditCustomForm', 'Edit Custom Slides'))
self.titleLabel.setText(translate('CustomPlugin.EditCustomForm', '&Title:'))
self.addButton.setText(UiStrings().Add)
self.addButton.setToolTip(translate('CustomPlugin.EditCustomForm', 'Add a new slide at bottom.'))
self.editButton.setText(UiStrings().Edit)
self.editButton.setToolTip(translate('CustomPlugin.EditCustomForm', 'Edit the selected slide.'))
self.editAllButton.setText(translate('CustomPlugin.EditCustomForm', 'Ed&it All'))
self.editAllButton.setToolTip(translate('CustomPlugin.EditCustomForm', 'Edit all the slides at once.'))
self.themeLabel.setText(translate('CustomPlugin.EditCustomForm', 'The&me:'))
self.creditLabel.setText(translate('CustomPlugin.EditCustomForm', '&Credits:'))
self.previewButton.setText(UiStrings().SaveAndPreview)
class Ui_CustomEditDialog(object):
def setupUi(self, custom_edit_dialog):
custom_edit_dialog.setObjectName(u'custom_edit_dialog')
custom_edit_dialog.resize(450, 350)
custom_edit_dialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png'))
self.dialog_layout = QtGui.QVBoxLayout(custom_edit_dialog)
self.dialog_layout.setObjectName(u'dialog_layout')
self.title_layout = QtGui.QHBoxLayout()
self.title_layout.setObjectName(u'title_layout')
self.title_label = QtGui.QLabel(custom_edit_dialog)
self.title_label.setObjectName(u'title_label')
self.title_layout.addWidget(self.title_label)
self.title_edit = QtGui.QLineEdit(custom_edit_dialog)
self.title_label.setBuddy(self.title_edit)
self.title_edit.setObjectName(u'title_edit')
self.title_layout.addWidget(self.title_edit)
self.dialog_layout.addLayout(self.title_layout)
self.central_layout = QtGui.QHBoxLayout()
self.central_layout.setObjectName(u'central_layout')
self.slide_list_view = QtGui.QListWidget(custom_edit_dialog)
self.slide_list_view.setAlternatingRowColors(True)
self.slide_list_view.setObjectName(u'slide_list_view')
self.central_layout.addWidget(self.slide_list_view)
self.button_layout = QtGui.QVBoxLayout()
self.button_layout.setObjectName(u'button_layout')
self.add_button = QtGui.QPushButton(custom_edit_dialog)
self.add_button.setObjectName(u'add_button')
self.button_layout.addWidget(self.add_button)
self.edit_button = QtGui.QPushButton(custom_edit_dialog)
self.edit_button.setEnabled(False)
self.edit_button.setObjectName(u'edit_button')
self.button_layout.addWidget(self.edit_button)
self.edit_all_button = QtGui.QPushButton(custom_edit_dialog)
self.edit_all_button.setObjectName(u'edit_all_button')
self.button_layout.addWidget(self.edit_all_button)
self.delete_button = create_button(custom_edit_dialog, u'delete_button', role=u'delete',
click=custom_edit_dialog.on_delete_button_clicked)
self.delete_button.setEnabled(False)
self.button_layout.addWidget(self.delete_button)
self.button_layout.addStretch()
self.up_button = create_button(custom_edit_dialog, u'up_button', role=u'up', enabled=False,
click=custom_edit_dialog.on_up_button_clicked)
self.down_button = create_button(custom_edit_dialog, u'down_button', role=u'down', enabled=False,
click=custom_edit_dialog.on_down_button_clicked)
self.button_layout.addWidget(self.up_button)
self.button_layout.addWidget(self.down_button)
self.central_layout.addLayout(self.button_layout)
self.dialog_layout.addLayout(self.central_layout)
self.bottom_form_layout = QtGui.QFormLayout()
self.bottom_form_layout.setObjectName(u'bottom_form_layout')
self.theme_label = QtGui.QLabel(custom_edit_dialog)
self.theme_label.setObjectName(u'theme_label')
self.theme_combo_box = QtGui.QComboBox(custom_edit_dialog)
self.theme_combo_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.theme_combo_box.setObjectName(u'theme_combo_box')
self.theme_label.setBuddy(self.theme_combo_box)
self.bottom_form_layout.addRow(self.theme_label, self.theme_combo_box)
self.credit_label = QtGui.QLabel(custom_edit_dialog)
self.credit_label.setObjectName(u'credit_label')
self.credit_edit = QtGui.QLineEdit(custom_edit_dialog)
self.credit_edit.setObjectName(u'credit_edit')
self.credit_label.setBuddy(self.credit_edit)
self.bottom_form_layout.addRow(self.credit_label, self.credit_edit)
self.dialog_layout.addLayout(self.bottom_form_layout)
self.preview_button = QtGui.QPushButton()
self.button_box = create_button_box(custom_edit_dialog, u'button_box', [u'cancel', u'save'],
[self.preview_button])
self.dialog_layout.addWidget(self.button_box)
self.retranslateUi(custom_edit_dialog)
def retranslateUi(self, custom_edit_dialog):
custom_edit_dialog.setWindowTitle(translate('CustomPlugin.EditCustomForm', 'Edit Custom Slides'))
self.title_label.setText(translate('CustomPlugin.EditCustomForm', '&Title:'))
self.add_button.setText(UiStrings().Add)
self.add_button.setToolTip(translate('CustomPlugin.EditCustomForm', 'Add a new slide at bottom.'))
self.edit_button.setText(UiStrings().Edit)
self.edit_button.setToolTip(translate('CustomPlugin.EditCustomForm', 'Edit the selected slide.'))
self.edit_all_button.setText(translate('CustomPlugin.EditCustomForm', 'Ed&it All'))
self.edit_all_button.setToolTip(translate('CustomPlugin.EditCustomForm', 'Edit all the slides at once.'))
self.theme_label.setText(translate('CustomPlugin.EditCustomForm', 'The&me:'))
self.credit_label.setText(translate('CustomPlugin.EditCustomForm', '&Credits:'))
self.preview_button.setText(UiStrings().SaveAndPreview)

View File

@ -29,7 +29,7 @@
import logging
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from openlp.core.lib import Registry, translate
from openlp.core.lib.ui import critical_error_message_box, find_and_set_in_combo_box
@ -56,14 +56,14 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.mediaitem = mediaitem
self.setupUi(self)
# Create other objects and forms.
self.editSlideForm = EditCustomSlideForm(self)
self.edit_slide_form = EditCustomSlideForm(self)
# Connecting signals and slots
self.previewButton.clicked.connect(self.on_preview_button_clicked)
self.addButton.clicked.connect(self.on_add_button_clicked)
self.editButton.clicked.connect(self.on_edit_button_clicked)
self.editAllButton.clicked.connect(self.on_edit_all_button_clicked)
self.slideListView.currentRowChanged.connect(self.on_current_row_changed)
self.slideListView.doubleClicked.connect(self.on_edit_button_clicked)
self.preview_button.clicked.connect(self.on_preview_button_clicked)
self.add_button.clicked.connect(self.on_add_button_clicked)
self.edit_button.clicked.connect(self.on_edit_button_clicked)
self.edit_all_button.clicked.connect(self.on_edit_all_button_clicked)
self.slide_list_view.currentRowChanged.connect(self.on_current_row_changed)
self.slide_list_view.doubleClicked.connect(self.on_edit_button_clicked)
Registry().register_function(u'theme_update_list', self.load_themes)
def load_themes(self, theme_list):
@ -73,11 +73,11 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
``theme_list``
The list of themes to load.
"""
self.themeComboBox.clear()
self.themeComboBox.addItem(u'')
self.themeComboBox.addItems(theme_list)
self.theme_combo_box.clear()
self.theme_combo_box.addItem(u'')
self.theme_combo_box.addItems(theme_list)
def loadCustom(self, id, preview=False):
def load_custom(self, id, preview=False):
"""
Called when editing or creating a new custom.
@ -88,111 +88,111 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
States whether the custom is edited while being previewed in the
preview panel.
"""
self.slideListView.clear()
self.slide_list_view.clear()
if id == 0:
self.customSlide = CustomSlide()
self.titleEdit.setText(u'')
self.creditEdit.setText(u'')
self.themeComboBox.setCurrentIndex(0)
self.custom_slide = CustomSlide()
self.title_edit.set_text(u'')
self.credit_edit.set_text(u'')
self.theme_combo_box.setCurrentIndex(0)
else:
self.customSlide = self.manager.get_object(CustomSlide, id)
self.titleEdit.setText(self.customSlide.title)
self.creditEdit.setText(self.customSlide.credits)
customXML = CustomXMLParser(self.customSlide.text)
slideList = customXML.get_verses()
for slide in slideList:
self.slideListView.addItem(slide[1])
theme = self.customSlide.theme_name
find_and_set_in_combo_box(self.themeComboBox, theme)
self.titleEdit.setFocus()
self.custom_slide = self.manager.get_object(CustomSlide, id)
self.title_edit.setText(self.custom_slide.title)
self.credit_edit.setText(self.custom_slide.credits)
custom_XML = CustomXMLParser(self.custom_slide.text)
slide_list = custom_XML.get_verses()
for slide in slide_list:
self.slide_list_view.addItem(slide[1])
theme = self.custom_slide.theme_name
find_and_set_in_combo_box(self.theme_combo_box, theme)
self.title_edit.setFocus()
# If not preview hide the preview button.
self.previewButton.setVisible(preview)
self.preview_button.setVisible(preview)
def accept(self):
"""
Override the QDialog method to check if the custom slide has been saved before closing the dialog.
"""
log.debug(u'accept')
if self.saveCustom():
if self.save_custom():
QtGui.QDialog.accept(self)
def saveCustom(self):
def save_custom(self):
"""
Saves the custom.
"""
if not self._validate():
return False
sxml = CustomXMLBuilder()
for count in range(self.slideListView.count()):
sxml.add_verse_to_lyrics(u'custom', unicode(count + 1), self.slideListView.item(count).text())
self.customSlide.title = self.titleEdit.text()
self.customSlide.text = unicode(sxml.extract_xml(), u'utf-8')
self.customSlide.credits = self.creditEdit.text()
self.customSlide.theme_name = self.themeComboBox.currentText()
success = self.manager.save_object(self.customSlide)
self.mediaitem.autoSelectId = self.customSlide.id
for count in range(self.slide_list_view.count()):
sxml.add_verse_to_lyrics(u'custom', unicode(count + 1), self.slide_list_view.item(count).text())
self.custom_slide.title = self.title_edit.text()
self.custom_slide.text = unicode(sxml.extract_xml(), u'utf-8')
self.custom_slide.credits = self.credit_edit.text()
self.custom_slide.theme_name = self.theme_combo_box.currentText()
success = self.manager.save_object(self.custom_slide)
self.mediaitem.autoSelectId = self.custom_slide.id
return success
def onUpButtonClicked(self):
def on_up_button_clicked(self):
"""
Move a slide up in the list when the "Up" button is clicked.
"""
selectedRow = self.slideListView.currentRow()
selectedRow = self.slide_list_view.currentRow()
if selectedRow != 0:
qw = self.slideListView.takeItem(selectedRow)
self.slideListView.insertItem(selectedRow - 1, qw)
self.slideListView.setCurrentRow(selectedRow - 1)
qw = self.slide_list_view.takeItem(selectedRow)
self.slide_list_view.insertItem(selectedRow - 1, qw)
self.slide_list_view.setCurrentRow(selectedRow - 1)
def onDownButtonClicked(self):
def on_down_button_clicked(self):
"""
Move a slide down in the list when the "Down" button is clicked.
"""
selectedRow = self.slideListView.currentRow()
selectedRow = self.slide_list_view.currentRow()
# zero base arrays
if selectedRow != self.slideListView.count() - 1:
qw = self.slideListView.takeItem(selectedRow)
self.slideListView.insertItem(selectedRow + 1, qw)
self.slideListView.setCurrentRow(selectedRow + 1)
if selectedRow != self.slide_list_view.count() - 1:
qw = self.slide_list_view.takeItem(selectedRow)
self.slide_list_view.insertItem(selectedRow + 1, qw)
self.slide_list_view.setCurrentRow(selectedRow + 1)
def on_add_button_clicked(self):
"""
Add a new blank slide.
"""
self.editSlideForm.setText(u'')
if self.editSlideForm.exec_():
self.slideListView.addItems(self.editSlideForm.getText())
self.edit_slide_form.set_text(u'')
if self.edit_slide_form.exec_():
self.slide_list_view.addItems(self.edit_slide_form.get_text())
def on_edit_button_clicked(self):
"""
Edit the currently selected slide.
"""
self.editSlideForm.setText(self.slideListView.currentItem().text())
if self.editSlideForm.exec_():
self.updateSlideList(self.editSlideForm.getText())
self.edit_slide_form.set_text(self.slide_list_view.currentItem().text())
if self.edit_slide_form.exec_():
self.update_slide_list(self.edit_slide_form.get_text())
def on_edit_all_button_clicked(self):
"""
Edits all slides.
"""
slide_text = u''
for row in range(self.slideListView.count()):
item = self.slideListView.item(row)
for row in range(self.slide_list_view.count()):
item = self.slide_list_view.item(row)
slide_text += item.text()
if row != self.slideListView.count() - 1:
if row != self.slide_list_view.count() - 1:
slide_text += u'\n[===]\n'
self.editSlideForm.setText(slide_text)
if self.editSlideForm.exec_():
self.updateSlideList(self.editSlideForm.getText(), True)
self.edit_slide_form.set_text(slide_text)
if self.edit_slide_form.exec_():
self.update_slide_list(self.edit_slide_form.get_text(), True)
def on_preview_button_clicked(self):
"""
Save the custom item and preview it.
"""
log.debug(u'onPreview')
if self.saveCustom():
if self.save_custom():
Registry().execute(u'custom_preview')
def updateSlideList(self, slides, edit_all=False):
def update_slide_list(self, slides, edit_all=False):
"""
Updates the slide list after editing slides.
@ -203,60 +203,59 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
Indicates if all slides or only one slide has been edited.
"""
if edit_all:
self.slideListView.clear()
self.slideListView.addItems(slides)
self.slide_list_view.clear()
self.slide_list_view.addItems(slides)
else:
old_slides = []
old_row = self.slideListView.currentRow()
old_row = self.slide_list_view.currentRow()
# Create a list with all (old/unedited) slides.
old_slides = [self.slideListView.item(row).text() for row in
range(self.slideListView.count())]
self.slideListView.clear()
old_slides = [self.slide_list_view.item(row).text() for row in range(self.slide_list_view.count())]
self.slide_list_view.clear()
old_slides.pop(old_row)
# Insert all slides to make the old_slides list complete.
for slide in slides:
old_slides.insert(old_row, slide)
self.slideListView.addItems(old_slides)
self.slideListView.repaint()
self.slide_list_view.addItems(old_slides)
self.slide_list_view.repaint()
def onDeleteButtonClicked(self):
def on_delete_button_clicked(self):
"""
Removes the current row from the list.
"""
self.slideListView.takeItem(self.slideListView.currentRow())
self.on_current_row_changed(self.slideListView.currentRow())
self.slide_list_view.takeItem(self.slide_list_view.currentRow())
self.on_current_row_changed(self.slide_list_view.currentRow())
def on_current_row_changed(self, row):
"""
Called when the *slideListView*'s current row has been changed. This
Called when the *slide_list_view*'s current row has been changed. This
enables or disables buttons which require an slide to act on.
``row``
The row (int). If there is no current row, the value is -1.
"""
if row == -1:
self.deleteButton.setEnabled(False)
self.editButton.setEnabled(False)
self.upButton.setEnabled(False)
self.downButton.setEnabled(False)
self.delete_button.setEnabled(False)
self.edit_button.setEnabled(False)
self.up_button.setEnabled(False)
self.down_button.setEnabled(False)
else:
self.deleteButton.setEnabled(True)
self.editButton.setEnabled(True)
self.delete_button.setEnabled(True)
self.edit_button.setEnabled(True)
# Decide if the up/down buttons should be enabled or not.
self.downButton.setEnabled(self.slideListView.count() - 1 != row)
self.upButton.setEnabled(row != 0)
self.down_button.setEnabled(self.slide_list_view.count() - 1 != row)
self.up_button.setEnabled(row != 0)
def _validate(self):
"""
Checks whether a custom is valid or not.
"""
# We must have a title.
if not self.titleEdit.displayText():
self.titleEdit.setFocus()
if not self.title_edit.displayText():
self.title_edit.setFocus()
critical_error_message_box(message=translate('CustomPlugin.EditCustomForm', 'You need to type in a title.'))
return False
# We must have at least one slide.
if self.slideListView.count() == 0:
if self.slide_list_view.count() == 0:
critical_error_message_box(message=translate('CustomPlugin.EditCustomForm',
'You need to add at least one slide'))
return False

View File

@ -33,24 +33,25 @@ from openlp.core.lib import SpellTextEdit, UiStrings, translate
from openlp.core.lib.ui import create_button, create_button_box
class Ui_CustomSlideEditDialog(object):
def setupUi(self, customSlideEditDialog):
customSlideEditDialog.setObjectName(u'customSlideEditDialog')
customSlideEditDialog.resize(350, 300)
self.dialogLayout = QtGui.QVBoxLayout(customSlideEditDialog)
self.slideTextEdit = SpellTextEdit(self)
self.slideTextEdit.setObjectName(u'slideTextEdit')
self.dialogLayout.addWidget(self.slideTextEdit)
self.splitButton = create_button(customSlideEditDialog, u'splitButton', icon=u':/general/general_add.png')
self.insertButton = create_button(customSlideEditDialog, u'insertButton', icon=u':/general/general_add.png')
self.button_box = create_button_box(customSlideEditDialog, u'button_box', [u'cancel', u'save'],
[self.splitButton, self.insertButton])
self.dialogLayout.addWidget(self.button_box)
self.retranslateUi(customSlideEditDialog)
def setupUi(self, custom_slide_edit_dialog):
custom_slide_edit_dialog.setObjectName(u'custom_slide_edit_dialog')
custom_slide_edit_dialog.resize(350, 300)
self.dialog_layout = QtGui.QVBoxLayout(custom_slide_edit_dialog)
self.slide_text_edit = SpellTextEdit(self)
self.slide_text_edit.setObjectName(u'slide_text_edit')
self.dialog_layout.addWidget(self.slide_text_edit)
self.split_button = create_button(custom_slide_edit_dialog, u'splitButton', icon=u':/general/general_add.png')
self.insert_button = create_button(custom_slide_edit_dialog, u'insertButton',
icon=u':/general/general_add.png')
self.button_box = create_button_box(custom_slide_edit_dialog, u'button_box', [u'cancel', u'save'],
[self.split_button, self.insert_button])
self.dialog_layout.addWidget(self.button_box)
self.retranslateUi(custom_slide_edit_dialog)
def retranslateUi(self, customSlideEditDialog):
customSlideEditDialog.setWindowTitle(translate('CustomPlugin.EditVerseForm', 'Edit Slide'))
self.splitButton.setText(UiStrings().Split)
self.splitButton.setToolTip(UiStrings().SplitToolTip)
self.insertButton.setText(translate('CustomPlugin.EditCustomForm', 'Insert Slide'))
self.insertButton.setToolTip(translate('CustomPlugin.EditCustomForm',
def retranslateUi(self, custom_slide_edit_dialog):
custom_slide_edit_dialog.setWindowTitle(translate('CustomPlugin.EditVerseForm', 'Edit Slide'))
self.split_button.setText(UiStrings().Split)
self.split_button.setToolTip(UiStrings().SplitToolTip)
self.insert_button.setText(translate('CustomPlugin.EditCustomForm', 'Insert Slide'))
self.insert_button.setToolTip(translate('CustomPlugin.EditCustomForm',
'Split a slide into two by inserting a slide splitter.'))

View File

@ -50,51 +50,49 @@ class EditCustomSlideForm(QtGui.QDialog, Ui_CustomSlideEditDialog):
super(EditCustomSlideForm, self).__init__(parent)
self.setupUi(self)
# Connecting signals and slots
QtCore.QObject.connect(self.insertButton, QtCore.SIGNAL(u'clicked()'), self.onInsertButtonClicked)
QtCore.QObject.connect(self.splitButton, QtCore.SIGNAL(u'clicked()'), self.onSplitButtonClicked)
self.insert_button.clicked.connect(self.on_insert_button_clicked)
self.split_button.clicked.connect(self.on_split_button_clicked)
def setText(self, text):
def set_text(self, text):
"""
Set the text for slideTextEdit.
Set the text for slide_text_edit.
``text``
The text (unicode).
"""
self.slideTextEdit.clear()
self.slide_text_edit.clear()
if text:
self.slideTextEdit.setPlainText(text)
self.slideTextEdit.setFocus()
self.slide_text_edit.setPlainText(text)
self.slide_text_edit.setFocus()
def getText(self):
def get_text(self):
"""
Returns a list with all slides.
"""
return self.slideTextEdit.toPlainText().split(u'\n[===]\n')
return self.slide_text_edit.toPlainText().split(u'\n[===]\n')
def onInsertButtonClicked(self):
def on_insert_button_clicked(self):
"""
Adds a slide split at the cursor.
"""
self.insertSingleLineTextAtCursor(u'[===]')
self.slideTextEdit.setFocus()
self.insert_single_line_text_at_cursor(u'[===]')
self.slide_text_edit.setFocus()
def onSplitButtonClicked(self):
def on_split_button_clicked(self):
"""
Adds an optional split at cursor.
"""
self.insertSingleLineTextAtCursor(u'[---]')
self.slideTextEdit.setFocus()
self.insert_single_line_text_at_cursor(u'[---]')
self.slide_text_edit.setFocus()
def insertSingleLineTextAtCursor(self, text):
def insert_single_line_text_at_cursor(self, text):
"""
Adds ``text`` in a single line at the cursor position.
"""
full_text = self.slideTextEdit.toPlainText()
position = self.slideTextEdit.textCursor().position()
full_text = self.slide_text_edit.toPlainText()
position = self.slide_text_edit.textCursor().position()
if position and full_text[position - 1] != u'\n':
text = u'\n' + text
if position == len(full_text) or full_text[position] != u'\n':
text += u'\n'
self.slideTextEdit.insertPlainText(text)
#lint:enable
self.slide_text_edit.insertPlainText(text)

View File

@ -45,38 +45,36 @@ class CustomTab(SettingsTab):
def setupUi(self):
self.setObjectName(u'CustomTab')
SettingsTab.setupUi(self)
self.customModeGroupBox = QtGui.QGroupBox(self.leftColumn)
self.customModeGroupBox.setObjectName(u'customModeGroupBox')
self.customModeLayout = QtGui.QFormLayout(self.customModeGroupBox)
self.customModeLayout.setObjectName(u'customModeLayout')
self.displayFooterCheckBox = QtGui.QCheckBox(self.customModeGroupBox)
self.displayFooterCheckBox.setObjectName(u'displayFooterCheckBox')
self.customModeLayout.addRow(self.displayFooterCheckBox)
self.add_from_service_checkbox = QtGui.QCheckBox(self.customModeGroupBox)
self.custom_mode_group_box = QtGui.QGroupBox(self.leftColumn)
self.custom_mode_group_box.setObjectName(u'custom_mode_group_box')
self.custom_mode_layout = QtGui.QFormLayout(self.custom_mode_group_box)
self.custom_mode_layout.setObjectName(u'custom_mode_layout')
self.display_footer_check_box = QtGui.QCheckBox(self.custom_mode_group_box)
self.display_footer_check_box.setObjectName(u'display_footer_check_box')
self.custom_mode_layout.addRow(self.display_footer_check_box)
self.add_from_service_checkbox = QtGui.QCheckBox(self.custom_mode_group_box)
self.add_from_service_checkbox.setObjectName(u'add_from_service_checkbox')
self.customModeLayout.addRow(self.add_from_service_checkbox)
self.leftLayout.addWidget(self.customModeGroupBox)
self.custom_mode_layout.addRow(self.add_from_service_checkbox)
self.leftLayout.addWidget(self.custom_mode_group_box)
self.leftLayout.addStretch()
self.rightLayout.addStretch()
QtCore.QObject.connect(self.displayFooterCheckBox, QtCore.SIGNAL(u'stateChanged(int)'),
self.onDisplayFooterCheckBoxChanged)
QtCore.QObject.connect(self.add_from_service_checkbox, QtCore.SIGNAL(u'stateChanged(int)'),
self.on_add_from_service_check_box_changed)
self.display_footer_check_box.stateChanged.connect(self.on_display_footer_check_box_changed)
self.add_from_service_checkbox.stateChanged.connect(self.on_add_from_service_check_box_changed)
def retranslateUi(self):
self.customModeGroupBox.setTitle(translate('CustomPlugin.CustomTab', 'Custom Display'))
self.displayFooterCheckBox.setText(translate('CustomPlugin.CustomTab', 'Display footer'))
self.custom_mode_group_box.setTitle(translate('CustomPlugin.CustomTab', 'Custom Display'))
self.display_footer_check_box.setText(translate('CustomPlugin.CustomTab', 'Display footer'))
self.add_from_service_checkbox.setText(translate('CustomPlugin.CustomTab',
'Import missing custom slides from service files'))
def onDisplayFooterCheckBoxChanged(self, check_state):
def on_display_footer_check_box_changed(self, check_state):
"""
Toggle the setting for displaying the footer.
"""
self.displayFooter = False
self.display_footer = False
# we have a set value convert to True/False
if check_state == QtCore.Qt.Checked:
self.displayFooter = True
self.display_footer = True
def on_add_from_service_check_box_changed(self, check_state):
self.update_load = (check_state == QtCore.Qt.Checked)
@ -84,15 +82,15 @@ class CustomTab(SettingsTab):
def load(self):
settings = Settings()
settings.beginGroup(self.settingsSection)
self.displayFooter = settings.value(u'display footer')
self.display_footer = settings.value(u'display footer')
self.update_load = settings.value(u'add custom from service')
self.displayFooterCheckBox.setChecked(self.displayFooter)
self.display_footer_check_box.setChecked(self.display_footer)
self.add_from_service_checkbox.setChecked(self.update_load)
settings.endGroup()
def save(self):
settings = Settings()
settings.beginGroup(self.settingsSection)
settings.setValue(u'display footer', self.displayFooter)
settings.setValue(u'display footer', self.display_footer)
settings.setValue(u'add custom from service', self.update_load)
settings.endGroup()

View File

@ -114,7 +114,7 @@ class CustomMediaItem(MediaManagerItem):
# active trigger it and clean up so it will not update again.
def onNewClick(self):
self.edit_custom_form.loadCustom(0)
self.edit_custom_form.load_custom(0)
self.edit_custom_form.exec_()
self.onClearTextButtonClick()
self.onSelectionChange()
@ -128,7 +128,7 @@ class CustomMediaItem(MediaManagerItem):
custom_id = int(custom_id)
valid = self.manager.get_object(CustomSlide, custom_id)
if valid:
self.edit_custom_form.loadCustom(custom_id, preview)
self.edit_custom_form.load_custom(custom_id, preview)
if self.edit_custom_form.exec_() == QtGui.QDialog.Accepted:
self.remoteTriggered = True
self.remoteCustom = custom_id
@ -148,7 +148,7 @@ class CustomMediaItem(MediaManagerItem):
if check_item_selected(self.listView, UiStrings().SelectEdit):
item = self.listView.currentItem()
item_id = item.data(QtCore.Qt.UserRole)
self.edit_custom_form.loadCustom(item_id, False)
self.edit_custom_form.load_custom(item_id, False)
self.edit_custom_form.exec_()
self.autoSelectId = -1
self.onSearchTextButtonClicked()

View File

@ -65,7 +65,7 @@ class ImagePlugin(Plugin):
'provided by the theme.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -66,7 +66,7 @@ class MediaPlugin(Plugin):
'<br />The media plugin provides playback of audio and video.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -156,7 +156,7 @@ class PresentationPlugin(Plugin):
'available to the user in a drop down box.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -81,7 +81,7 @@ class RemotesPlugin(Plugin):
'browser or through the remote API.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -176,7 +176,7 @@ class SongsPlugin(Plugin):
return translate('SongsPlugin', '<strong>Songs Plugin</strong>'
'<br />The songs plugin provides the ability to display and manage songs.')
def usesTheme(self, theme):
def uses_theme(self, theme):
"""
Called to find out if the song plugin is currently using a theme.
@ -186,7 +186,7 @@ class SongsPlugin(Plugin):
return True
return False
def renameTheme(self, oldTheme, newTheme):
def rename_theme(self, oldTheme, newTheme):
"""
Renames a theme the song plugin is using making the plugin use the new
name.
@ -209,7 +209,7 @@ class SongsPlugin(Plugin):
importer.register(self.mediaItem.importWizard)
return importer
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -221,7 +221,7 @@ class SongUsagePlugin(Plugin):
'</strong><br />This plugin tracks the usage of songs in services.')
return about_text
def setPluginTextStrings(self):
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""

View File

@ -216,12 +216,15 @@ class TestServiceItem(TestCase):
assert service_item.get_frame_path(0) == test_file, u'The frame path should match the full path to the image'
assert service_item.get_frame_title(0) == image_name, u'The frame title should match the image name'
assert service_item.get_display_title() == image_name, u'The display title should match the first image name'
assert service_item.is_image() is True, u'This service item is an Image'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, u'This service item can be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, u'This service item can be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, u'This service item can be made to Loop'
assert service_item.is_image() is True, u'This service item should be of an "image" type'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
u'This service item should be able to be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
u'This service item should be able to be be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
u'This service item should be able to be run in a can be made to Loop'
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
u'This service item can have new items added'
u'This service item should be able to have new items added to it'
def serviceitem_load_image_from_local_service_test(self):
"""
@ -256,11 +259,14 @@ class TestServiceItem(TestCase):
assert service_item.get_display_title().lower() == service_item.name, \
u'The plugin name should match the display title, as there are > 1 Images'
assert service_item.is_image() is True, u'This service item should be of an "image" type'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, u'This service item can be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, u'This service item can be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, u'This service item can be made to Loop'
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
u'This service item should be able to be Maintained'
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
u'This service item should be able to be be Previewed'
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
u'This service item should be able to be run in a can be made to Loop'
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
u'This service item can have new items added'
u'This service item should be able to have new items added to it'
def convert_file_service_item(self, name):
service_file = os.path.join(TEST_PATH, name)