forked from openlp/openlp
Allow editing of author types and fix bug in servicemanager
bzr-revno: 2403
This commit is contained in:
commit
6c40962afb
@ -1103,7 +1103,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
|
||||
Moves the cursor selection up the window. Called by the up arrow.
|
||||
"""
|
||||
item = self.service_manager_list.currentItem()
|
||||
item_before = self.service_manager_list.item_above(item)
|
||||
item_before = self.service_manager_list.itemAbove(item)
|
||||
if item_before is None:
|
||||
return
|
||||
self.service_manager_list.setCurrentItem(item_before)
|
||||
|
@ -138,6 +138,9 @@ class Ui_EditSongDialog(object):
|
||||
self.author_remove_layout = QtGui.QHBoxLayout()
|
||||
self.author_remove_layout.setObjectName('author_remove_layout')
|
||||
self.author_remove_layout.addStretch()
|
||||
self.author_edit_button = QtGui.QPushButton(self.authors_group_box)
|
||||
self.author_edit_button.setObjectName('author_edit_button')
|
||||
self.author_remove_layout.addWidget(self.author_edit_button)
|
||||
self.author_remove_button = QtGui.QPushButton(self.authors_group_box)
|
||||
self.author_remove_button.setObjectName('author_remove_button')
|
||||
self.author_remove_layout.addWidget(self.author_remove_button)
|
||||
@ -305,6 +308,7 @@ class Ui_EditSongDialog(object):
|
||||
translate('SongsPlugin.EditSongForm', 'Title && Lyrics'))
|
||||
self.authors_group_box.setTitle(SongStrings.Authors)
|
||||
self.author_add_button.setText(translate('SongsPlugin.EditSongForm', '&Add to Song'))
|
||||
self.author_edit_button.setText(translate('SongsPlugin.EditSongForm', '&Edit Author Type'))
|
||||
self.author_remove_button.setText(translate('SongsPlugin.EditSongForm', '&Remove'))
|
||||
self.maintenance_button.setText(translate('SongsPlugin.EditSongForm', '&Manage Authors, Topics, Song Books'))
|
||||
self.topics_group_box.setTitle(SongStrings.Topic)
|
||||
|
@ -70,6 +70,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
|
||||
self.setupUi(self)
|
||||
# Connecting signals and slots
|
||||
self.author_add_button.clicked.connect(self.on_author_add_button_clicked)
|
||||
self.author_edit_button.clicked.connect(self.on_author_edit_button_clicked)
|
||||
self.author_remove_button.clicked.connect(self.on_author_remove_button_clicked)
|
||||
self.authors_list_view.itemClicked.connect(self.on_authors_list_view_clicked)
|
||||
self.topic_add_button.clicked.connect(self.on_topic_add_button_clicked)
|
||||
@ -334,6 +335,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
|
||||
"""
|
||||
self.verse_edit_button.setEnabled(False)
|
||||
self.verse_delete_button.setEnabled(False)
|
||||
self.author_edit_button.setEnabled(False)
|
||||
self.author_remove_button.setEnabled(False)
|
||||
self.topic_remove_button.setEnabled(False)
|
||||
|
||||
@ -354,12 +356,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
|
||||
|
||||
# Types
|
||||
self.author_types_combo_box.clear()
|
||||
self.author_types_combo_box.addItem('')
|
||||
# Don't iterate over the dictionary to give them this specific order
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Words], AuthorType.Words)
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Music], AuthorType.Music)
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.WordsAndMusic], AuthorType.WordsAndMusic)
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[AuthorType.Translation], AuthorType.Translation)
|
||||
for author_type in AuthorType.SortedTypes:
|
||||
self.author_types_combo_box.addItem(AuthorType.Types[author_type], author_type)
|
||||
|
||||
def load_topics(self):
|
||||
"""
|
||||
@ -596,9 +595,32 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
|
||||
"""
|
||||
Run a set of actions when an author in the list is selected (mainly enable the delete button).
|
||||
"""
|
||||
if self.authors_list_view.count() > 1:
|
||||
count = self.authors_list_view.count()
|
||||
if count > 0:
|
||||
self.author_edit_button.setEnabled(True)
|
||||
if count > 1:
|
||||
# There must be at least one author
|
||||
self.author_remove_button.setEnabled(True)
|
||||
|
||||
def on_author_edit_button_clicked(self):
|
||||
"""
|
||||
Show a dialog to change the type of an author when the edit button is clicked
|
||||
"""
|
||||
self.author_edit_button.setEnabled(False)
|
||||
item = self.authors_list_view.currentItem()
|
||||
author_id, author_type = item.data(QtCore.Qt.UserRole)
|
||||
choice, ok = QtGui.QInputDialog.getItem(self, translate('SongsPlugin.EditSongForm', 'Edit Author Type'),
|
||||
translate('SongsPlugin.EditSongForm', 'Choose type for this author'),
|
||||
AuthorType.TranslatedTypes,
|
||||
current=AuthorType.SortedTypes.index(author_type),
|
||||
editable=False)
|
||||
if not ok:
|
||||
return
|
||||
author = self.manager.get_object(Author, author_id)
|
||||
author_type = AuthorType.from_translated_text(choice)
|
||||
item.setData(QtCore.Qt.UserRole, (author_id, author_type))
|
||||
item.setText(author.get_display_name(author_type))
|
||||
|
||||
def on_author_remove_button_clicked(self):
|
||||
"""
|
||||
Remove the author from the list when the delete button is clicked.
|
||||
|
@ -69,17 +69,42 @@ class AuthorType(object):
|
||||
|
||||
The 'words+music' type is not an official type, but is provided for convenience.
|
||||
"""
|
||||
NoType = ''
|
||||
Words = 'words'
|
||||
Music = 'music'
|
||||
WordsAndMusic = 'words+music'
|
||||
Translation = 'translation'
|
||||
Types = {
|
||||
NoType: '',
|
||||
Words: translate('SongsPlugin.AuthorType', 'Words', 'Author who wrote the lyrics of a song'),
|
||||
Music: translate('SongsPlugin.AuthorType', 'Music', 'Author who wrote the music of a song'),
|
||||
WordsAndMusic: translate('SongsPlugin.AuthorType', 'Words and Music',
|
||||
'Author who wrote both lyrics and music of a song'),
|
||||
Translation: translate('SongsPlugin.AuthorType', 'Translation', 'Author who translated the song')
|
||||
}
|
||||
SortedTypes = [
|
||||
NoType,
|
||||
Words,
|
||||
Music,
|
||||
WordsAndMusic
|
||||
]
|
||||
TranslatedTypes = [
|
||||
Types[NoType],
|
||||
Types[Words],
|
||||
Types[Music],
|
||||
Types[WordsAndMusic]
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def from_translated_text(translated_type):
|
||||
"""
|
||||
Get the AuthorType from a translated string.
|
||||
:param translated_type: Translated Author type.
|
||||
"""
|
||||
for key, value in AuthorType.Types.items():
|
||||
if value == translated_type:
|
||||
return key
|
||||
return AuthorType.NoType
|
||||
|
||||
|
||||
class Book(BaseModel):
|
||||
|
@ -112,3 +112,16 @@ class TestDB(TestCase):
|
||||
# THEN: It should have been removed and the other author should still be there
|
||||
self.assertEqual(1, len(song.authors_songs))
|
||||
self.assertEqual(None, song.authors_songs[0].author_type)
|
||||
|
||||
def test_get_author_type_from_translated_text(self):
|
||||
"""
|
||||
Test getting an author type from translated text
|
||||
"""
|
||||
# GIVEN: A string with an author type
|
||||
author_type_name = AuthorType.Types[AuthorType.Words]
|
||||
|
||||
# WHEN: We call the method
|
||||
author_type = AuthorType.from_translated_text(author_type_name)
|
||||
|
||||
# THEN: The type should be correct
|
||||
self.assertEqual(author_type, AuthorType.Words)
|
||||
|
Loading…
Reference in New Issue
Block a user