From 29ef34b569d9f9c1561201f8a1bb7d8d559fd3ef Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 10 Apr 2011 07:18:31 +0100 Subject: [PATCH] Add saving of selected Bible names in Quick and Advanced. Clean up combo box selection code (General) Fixes: https://launchpad.net/bugs/755687 --- openlp/core/lib/ui.py | 17 ++++++++++ openlp/core/ui/servicemanager.py | 11 ++----- openlp/core/ui/themestab.py | 9 ++---- openlp/plugins/bibles/lib/biblestab.py | 9 ++---- openlp/plugins/bibles/lib/mediaitem.py | 32 +++++++++++++------ openlp/plugins/custom/forms/editcustomform.py | 8 ++--- openlp/plugins/songs/forms/editsongform.py | 17 ++-------- 7 files changed, 51 insertions(+), 52 deletions(-) diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index c1a9f8b35..ffcc32414 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -315,3 +315,20 @@ def create_valign_combo(form, parent, layout): form.verticalComboBox.addItem(UiStrings.Bottom) verticalLabel.setBuddy(form.verticalComboBox) layout.addRow(verticalLabel, form.verticalComboBox) + +def find_in_combo_box(combo_box, value_to_find): + """ + Find a string in a combo box and set it as the selected item if present + + ``combo_box`` + The combo box to check for selected items + + ``value_to_find`` + The value to find + """ + index = combo_box.findText(value_to_find, + QtCore.Qt.MatchExactly) + if index == -1: + # Not Found. + index = 0 + combo_box.setCurrentIndex(index) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 9c1c63917..a07d7f970 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -35,7 +35,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ Receiver, build_icon, ItemCapabilities, SettingsManager, translate from openlp.core.lib.theme import ThemeLevel -from openlp.core.lib.ui import UiStrings, critical_error_message_box +from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ + find_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ @@ -1261,13 +1262,7 @@ class ServiceManager(QtGui.QWidget): action = context_menu_action(self.serviceManagerList, None, theme, self.onThemeChangeAction) self.themeMenu.addAction(action) - index = self.themeComboBox.findText(self.service_theme, - QtCore.Qt.MatchExactly) - # Not Found - if index == -1: - index = 0 - self.service_theme = u'' - self.themeComboBox.setCurrentIndex(index) + find_in_combo_box(self.themeComboBox, self.service_theme) self.mainwindow.renderManager.set_service_theme(self.service_theme) self.regenerateServiceItems() diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 1b76d2198..3307b94fe 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -28,7 +28,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import SettingsTab, Receiver, translate from openlp.core.lib.theme import ThemeLevel -from openlp.core.lib.ui import UiStrings +from openlp.core.lib.ui import UiStrings, find_in_combo_box class ThemesTab(SettingsTab): """ @@ -185,12 +185,7 @@ class ThemesTab(SettingsTab): self.DefaultComboBox.clear() for theme in theme_list: self.DefaultComboBox.addItem(theme) - id = self.DefaultComboBox.findText( - self.global_theme, QtCore.Qt.MatchExactly) - if id == -1: - id = 0 # Not Found - self.global_theme = u'' - self.DefaultComboBox.setCurrentIndex(id) + find_in_combo_box(self.DefaultComboBox, self.global_theme) self.parent.renderManager.set_global_theme( self.global_theme, self.theme_level) if self.global_theme is not u'': diff --git a/openlp/plugins/bibles/lib/biblestab.py b/openlp/plugins/bibles/lib/biblestab.py index 7a631ad09..d2e6ad8d9 100644 --- a/openlp/plugins/bibles/lib/biblestab.py +++ b/openlp/plugins/bibles/lib/biblestab.py @@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, SettingsTab, translate from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle +from openlp.core.lib.ui import find_in_combo_box log = logging.getLogger(__name__) @@ -208,10 +209,4 @@ class BiblesTab(SettingsTab): self.BibleThemeComboBox.addItem(u'') for theme in theme_list: self.BibleThemeComboBox.addItem(theme) - index = self.BibleThemeComboBox.findText( - unicode(self.bible_theme), QtCore.Qt.MatchExactly) - if index == -1: - # Not Found. - index = 0 - self.bible_theme = u'' - self.BibleThemeComboBox.setCurrentIndex(index) + find_in_combo_box(self.BibleThemeComboBox, self.bible_theme) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index a9694fd0c..5c77a75d7 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -32,7 +32,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ translate from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import UiStrings, add_widget_completer, \ - media_item_combo_box, critical_error_message_box + media_item_combo_box, critical_error_message_box, find_in_combo_box from openlp.plugins.bibles.forms import BibleImportForm from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \ VerseReferenceList, get_reference_match @@ -274,7 +274,7 @@ class BibleMediaItem(MediaManagerItem): log.debug(u'bible manager initialise') self.parent.manager.media = self self.loadBibles() - self.updateAutoCompleter() + self.updateAutoCompleter(False) self.configUpdated() log.debug(u'bible manager initialise complete') @@ -298,23 +298,25 @@ class BibleMediaItem(MediaManagerItem): bibles = self.parent.manager.get_bibles().keys() bibles.sort() # Load the bibles into the combo boxes. - first = True for bible in bibles: if bible: self.quickVersionComboBox.addItem(bible) self.quickSecondComboBox.addItem(bible) self.advancedVersionComboBox.addItem(bible) self.advancedSecondComboBox.addItem(bible) - if first: - first = False - self.initialiseBible(bible) + # set the default value + book = QtCore.QSettings().value( + self.settingsSection + u'/advanced bible', + QtCore.QVariant(u'')).toString() + find_in_combo_box(self.advancedVersionComboBox, book) + self.initialiseAdvancedBible(unicode(book)) def reloadBibles(self): log.debug(u'Reloading Bibles') self.parent.manager.reload_bibles() self.loadBibles() - def initialiseBible(self, bible): + def initialiseAdvancedBible(self, bible): """ This initialises the given bible, which means that its book names and their chapter numbers is added to the combo boxes on the @@ -324,7 +326,7 @@ class BibleMediaItem(MediaManagerItem): ``bible`` The bible to initialise (unicode). """ - log.debug(u'initialiseBible %s', bible) + log.debug(u'initialiseAdvancedBible %s', bible) book_data = self.parent.manager.get_books(bible) self.advancedBookComboBox.clear() first = True @@ -354,12 +356,20 @@ class BibleMediaItem(MediaManagerItem): self.adjustComboBox(1, verse_count, self.advancedFromVerse) self.adjustComboBox(1, verse_count, self.advancedToVerse) - def updateAutoCompleter(self): + def updateAutoCompleter(self, updateConfig=True): """ This updates the bible book completion list for the search field. The completion depends on the bible. It is only updated when we are doing a reference search, otherwise the auto completion list is removed. """ + if updateConfig: + QtCore.QSettings().setValue(self.settingsSection + u'/quick bible', + QtCore.QVariant(self.quickVersionComboBox.currentText())) + else: + book = QtCore.QSettings().value( + self.settingsSection + u'/quick bible', + QtCore.QVariant(u'')).toString() + find_in_combo_box(self.quickVersionComboBox, book) books = [] # We have to do a 'Reference Search'. if self.quickSearchEdit.currentSearchType() == BibleSearch.Reference: @@ -372,7 +382,9 @@ class BibleMediaItem(MediaManagerItem): add_widget_completer(books, self.quickSearchEdit) def onAdvancedVersionComboBox(self): - self.initialiseBible( + QtCore.QSettings().setValue(self.settingsSection + u'/advanced bible', + QtCore.QVariant(self.advancedVersionComboBox.currentText())) + self.initialiseAdvancedBible( unicode(self.advancedVersionComboBox.currentText())) def onAdvancedBookComboBox(self): diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index f81bd4c7d..3ebd5f984 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -29,7 +29,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate -from openlp.core.lib.ui import critical_error_message_box +from openlp.core.lib.ui import critical_error_message_box, find_in_combo_box from openlp.plugins.custom.lib import CustomXMLBuilder, CustomXMLParser from openlp.plugins.custom.lib.db import CustomSlide from editcustomdialog import Ui_CustomEditDialog @@ -98,11 +98,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): for slide in slideList: self.slideListView.addItem(slide[1]) theme = self.customSlide.theme_name - id = self.themeComboBox.findText(theme, QtCore.Qt.MatchExactly) - # No theme match - if id == -1: - id = 0 - self.themeComboBox.setCurrentIndex(id) + find_in_combo_box(self.themeComboBox, theme) # If not preview hide the preview button. self.previewButton.setVisible(False) if preview: diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 2f21e57cd..8dfae1736 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate from openlp.core.lib.ui import UiStrings, add_widget_completer, \ - critical_error_message_box + critical_error_message_box, find_in_combo_box from openlp.plugins.songs.forms import EditVerseForm from openlp.plugins.songs.lib import SongXML, VerseType, clean_song from openlp.plugins.songs.lib.db import Book, Song, Author, Topic @@ -208,20 +208,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.alternativeEdit.setText(u'') if self.song.song_book_id != 0: book_name = self.manager.get_object(Book, self.song.song_book_id) - id = self.songBookComboBox.findText( - unicode(book_name.name), QtCore.Qt.MatchExactly) - if id == -1: - # Not Found - id = 0 - self.songBookComboBox.setCurrentIndex(id) + find_in_combo_box(self.songBookComboBox, unicode(book_name.name)) if self.song.theme_name: - id = self.themeComboBox.findText( - unicode(self.song.theme_name), QtCore.Qt.MatchExactly) - if id == -1: - # Not Found - id = 0 - self.song.theme_name = None - self.themeComboBox.setCurrentIndex(id) + find_in_combo_box(self.themeComboBox, unicode(self.song.theme_name)) if self.song.copyright: self.copyrightEdit.setText(self.song.copyright) else: