Add saving of selected Bible names in Quick and Advanced.

Clean up combo box selection code (General)

Fixes: https://launchpad.net/bugs/755687
This commit is contained in:
Tim Bentley 2011-04-10 07:18:31 +01:00
parent 24e63ede84
commit 29ef34b569
7 changed files with 51 additions and 52 deletions

View File

@ -315,3 +315,20 @@ def create_valign_combo(form, parent, layout):
form.verticalComboBox.addItem(UiStrings.Bottom) form.verticalComboBox.addItem(UiStrings.Bottom)
verticalLabel.setBuddy(form.verticalComboBox) verticalLabel.setBuddy(form.verticalComboBox)
layout.addRow(verticalLabel, 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)

View File

@ -35,7 +35,8 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \
Receiver, build_icon, ItemCapabilities, SettingsManager, translate Receiver, build_icon, ItemCapabilities, SettingsManager, translate
from openlp.core.lib.theme import ThemeLevel 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 import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.ui.printserviceform import PrintServiceForm
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ 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, action = context_menu_action(self.serviceManagerList, None, theme,
self.onThemeChangeAction) self.onThemeChangeAction)
self.themeMenu.addAction(action) self.themeMenu.addAction(action)
index = self.themeComboBox.findText(self.service_theme, find_in_combo_box(self.themeComboBox, self.service_theme)
QtCore.Qt.MatchExactly)
# Not Found
if index == -1:
index = 0
self.service_theme = u''
self.themeComboBox.setCurrentIndex(index)
self.mainwindow.renderManager.set_service_theme(self.service_theme) self.mainwindow.renderManager.set_service_theme(self.service_theme)
self.regenerateServiceItems() self.regenerateServiceItems()

View File

@ -28,7 +28,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab, Receiver, translate from openlp.core.lib import SettingsTab, Receiver, translate
from openlp.core.lib.theme import ThemeLevel 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): class ThemesTab(SettingsTab):
""" """
@ -185,12 +185,7 @@ class ThemesTab(SettingsTab):
self.DefaultComboBox.clear() self.DefaultComboBox.clear()
for theme in theme_list: for theme in theme_list:
self.DefaultComboBox.addItem(theme) self.DefaultComboBox.addItem(theme)
id = self.DefaultComboBox.findText( find_in_combo_box(self.DefaultComboBox, self.global_theme)
self.global_theme, QtCore.Qt.MatchExactly)
if id == -1:
id = 0 # Not Found
self.global_theme = u''
self.DefaultComboBox.setCurrentIndex(id)
self.parent.renderManager.set_global_theme( self.parent.renderManager.set_global_theme(
self.global_theme, self.theme_level) self.global_theme, self.theme_level)
if self.global_theme is not u'': if self.global_theme is not u'':

View File

@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, SettingsTab, translate from openlp.core.lib import Receiver, SettingsTab, translate
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle
from openlp.core.lib.ui import find_in_combo_box
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -208,10 +209,4 @@ class BiblesTab(SettingsTab):
self.BibleThemeComboBox.addItem(u'') self.BibleThemeComboBox.addItem(u'')
for theme in theme_list: for theme in theme_list:
self.BibleThemeComboBox.addItem(theme) self.BibleThemeComboBox.addItem(theme)
index = self.BibleThemeComboBox.findText( find_in_combo_box(self.BibleThemeComboBox, self.bible_theme)
unicode(self.bible_theme), QtCore.Qt.MatchExactly)
if index == -1:
# Not Found.
index = 0
self.bible_theme = u''
self.BibleThemeComboBox.setCurrentIndex(index)

View File

@ -32,7 +32,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
translate translate
from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings, add_widget_completer, \ 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.forms import BibleImportForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \ from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
VerseReferenceList, get_reference_match VerseReferenceList, get_reference_match
@ -274,7 +274,7 @@ class BibleMediaItem(MediaManagerItem):
log.debug(u'bible manager initialise') log.debug(u'bible manager initialise')
self.parent.manager.media = self self.parent.manager.media = self
self.loadBibles() self.loadBibles()
self.updateAutoCompleter() self.updateAutoCompleter(False)
self.configUpdated() self.configUpdated()
log.debug(u'bible manager initialise complete') log.debug(u'bible manager initialise complete')
@ -298,23 +298,25 @@ class BibleMediaItem(MediaManagerItem):
bibles = self.parent.manager.get_bibles().keys() bibles = self.parent.manager.get_bibles().keys()
bibles.sort() bibles.sort()
# Load the bibles into the combo boxes. # Load the bibles into the combo boxes.
first = True
for bible in bibles: for bible in bibles:
if bible: if bible:
self.quickVersionComboBox.addItem(bible) self.quickVersionComboBox.addItem(bible)
self.quickSecondComboBox.addItem(bible) self.quickSecondComboBox.addItem(bible)
self.advancedVersionComboBox.addItem(bible) self.advancedVersionComboBox.addItem(bible)
self.advancedSecondComboBox.addItem(bible) self.advancedSecondComboBox.addItem(bible)
if first: # set the default value
first = False book = QtCore.QSettings().value(
self.initialiseBible(bible) self.settingsSection + u'/advanced bible',
QtCore.QVariant(u'')).toString()
find_in_combo_box(self.advancedVersionComboBox, book)
self.initialiseAdvancedBible(unicode(book))
def reloadBibles(self): def reloadBibles(self):
log.debug(u'Reloading Bibles') log.debug(u'Reloading Bibles')
self.parent.manager.reload_bibles() self.parent.manager.reload_bibles()
self.loadBibles() self.loadBibles()
def initialiseBible(self, bible): def initialiseAdvancedBible(self, bible):
""" """
This initialises the given bible, which means that its book names and This initialises the given bible, which means that its book names and
their chapter numbers is added to the combo boxes on the their chapter numbers is added to the combo boxes on the
@ -324,7 +326,7 @@ class BibleMediaItem(MediaManagerItem):
``bible`` ``bible``
The bible to initialise (unicode). 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) book_data = self.parent.manager.get_books(bible)
self.advancedBookComboBox.clear() self.advancedBookComboBox.clear()
first = True first = True
@ -354,12 +356,20 @@ class BibleMediaItem(MediaManagerItem):
self.adjustComboBox(1, verse_count, self.advancedFromVerse) self.adjustComboBox(1, verse_count, self.advancedFromVerse)
self.adjustComboBox(1, verse_count, self.advancedToVerse) 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 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 completion depends on the bible. It is only updated when we are doing a
reference search, otherwise the auto completion list is removed. 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 = [] books = []
# We have to do a 'Reference Search'. # We have to do a 'Reference Search'.
if self.quickSearchEdit.currentSearchType() == BibleSearch.Reference: if self.quickSearchEdit.currentSearchType() == BibleSearch.Reference:
@ -372,7 +382,9 @@ class BibleMediaItem(MediaManagerItem):
add_widget_completer(books, self.quickSearchEdit) add_widget_completer(books, self.quickSearchEdit)
def onAdvancedVersionComboBox(self): def onAdvancedVersionComboBox(self):
self.initialiseBible( QtCore.QSettings().setValue(self.settingsSection + u'/advanced bible',
QtCore.QVariant(self.advancedVersionComboBox.currentText()))
self.initialiseAdvancedBible(
unicode(self.advancedVersionComboBox.currentText())) unicode(self.advancedVersionComboBox.currentText()))
def onAdvancedBookComboBox(self): def onAdvancedBookComboBox(self):

View File

@ -29,7 +29,7 @@ import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, translate 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 import CustomXMLBuilder, CustomXMLParser
from openlp.plugins.custom.lib.db import CustomSlide from openlp.plugins.custom.lib.db import CustomSlide
from editcustomdialog import Ui_CustomEditDialog from editcustomdialog import Ui_CustomEditDialog
@ -98,11 +98,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
for slide in slideList: for slide in slideList:
self.slideListView.addItem(slide[1]) self.slideListView.addItem(slide[1])
theme = self.customSlide.theme_name theme = self.customSlide.theme_name
id = self.themeComboBox.findText(theme, QtCore.Qt.MatchExactly) find_in_combo_box(self.themeComboBox, theme)
# No theme match
if id == -1:
id = 0
self.themeComboBox.setCurrentIndex(id)
# If not preview hide the preview button. # If not preview hide the preview button.
self.previewButton.setVisible(False) self.previewButton.setVisible(False)
if preview: if preview:

View File

@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, translate from openlp.core.lib import Receiver, translate
from openlp.core.lib.ui import UiStrings, add_widget_completer, \ 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.forms import EditVerseForm
from openlp.plugins.songs.lib import SongXML, VerseType, clean_song from openlp.plugins.songs.lib import SongXML, VerseType, clean_song
from openlp.plugins.songs.lib.db import Book, Song, Author, Topic 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'') self.alternativeEdit.setText(u'')
if self.song.song_book_id != 0: if self.song.song_book_id != 0:
book_name = self.manager.get_object(Book, self.song.song_book_id) book_name = self.manager.get_object(Book, self.song.song_book_id)
id = self.songBookComboBox.findText( find_in_combo_box(self.songBookComboBox, unicode(book_name.name))
unicode(book_name.name), QtCore.Qt.MatchExactly)
if id == -1:
# Not Found
id = 0
self.songBookComboBox.setCurrentIndex(id)
if self.song.theme_name: if self.song.theme_name:
id = self.themeComboBox.findText( find_in_combo_box(self.themeComboBox, unicode(self.song.theme_name))
unicode(self.song.theme_name), QtCore.Qt.MatchExactly)
if id == -1:
# Not Found
id = 0
self.song.theme_name = None
self.themeComboBox.setCurrentIndex(id)
if self.song.copyright: if self.song.copyright:
self.copyrightEdit.setText(self.song.copyright) self.copyrightEdit.setText(self.song.copyright)
else: else: