openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #30711
[Merge] lp:~phill-ridout/openlp/search_edit into lp:openlp
Phill has proposed merging lp:~phill-ridout/openlp/search_edit into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/search_edit/+merge/310697
Move some code in to the searchedit module
lp:~phill-ridout/openlp/search_edit (revision 2705)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1835/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1746/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1684/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1430/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/1020/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/1088/
[SUCCESS] https://ci.openlp.io/job/Branch-05b-Test_Coverage/956/
[SUCCESS] https://ci.openlp.io/job/Branch-05c-Code_Analysis2/112/
--
Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/search_edit into lp:openlp.
=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py 2016-08-09 21:37:59 +0000
+++ openlp/core/lib/mediamanageritem.py 2016-11-12 08:38:13 +0000
@@ -266,7 +266,7 @@
self.search_text_layout.setObjectName('search_text_layout')
self.search_text_label = QtWidgets.QLabel(self.search_widget)
self.search_text_label.setObjectName('search_text_label')
- self.search_text_edit = SearchEdit(self.search_widget)
+ self.search_text_edit = SearchEdit(self.search_widget, self.settings_section)
self.search_text_edit.setObjectName('search_text_edit')
self.search_text_label.setBuddy(self.search_text_edit)
self.search_text_layout.addRow(self.search_text_label, self.search_text_edit)
=== modified file 'openlp/core/lib/searchedit.py'
--- openlp/core/lib/searchedit.py 2016-05-16 13:41:26 +0000
+++ openlp/core/lib/searchedit.py 2016-11-12 08:38:13 +0000
@@ -26,6 +26,7 @@
from openlp.core.lib import build_icon
from openlp.core.lib.ui import create_widget_action
+from openlp.core.common import Settings
log = logging.getLogger(__name__)
@@ -37,11 +38,12 @@
searchTypeChanged = QtCore.pyqtSignal(QtCore.QVariant)
cleared = QtCore.pyqtSignal()
- def __init__(self, parent):
+ def __init__(self, parent, settings_section):
"""
Constructor.
"""
- super(SearchEdit, self).__init__(parent)
+ super().__init__(parent)
+ self.settings_section = settings_section
self._current_search_type = -1
self.clear_button = QtWidgets.QToolButton(self)
self.clear_button.setIcon(build_icon(':/system/clear_shortcut.png'))
@@ -100,14 +102,10 @@
menu = self.menu_button.menu()
for action in menu.actions():
if identifier == action.data():
- # setPlaceholderText has been implemented in Qt 4.7 and in at least PyQt 4.9 (I am not sure, if it was
- # implemented in PyQt 4.8).
- try:
- self.setPlaceholderText(action.placeholder_text)
- except AttributeError:
- pass
+ self.setPlaceholderText(action.placeholder_text)
self.menu_button.setDefaultAction(action)
self._current_search_type = identifier
+ Settings().setValue('{section}/last search type'.format(section=self.settings_section), identifier)
self.searchTypeChanged.emit(identifier)
return True
@@ -130,14 +128,10 @@
(2, ":/songs/authors.png", "Authors", "Search Authors...")
"""
menu = QtWidgets.QMenu(self)
- first = None
for identifier, icon, title, placeholder in items:
action = create_widget_action(
menu, text=title, icon=icon, data=identifier, triggers=self._on_menu_action_triggered)
action.placeholder_text = placeholder
- if first is None:
- first = action
- self._current_search_type = identifier
if not hasattr(self, 'menu_button'):
self.menu_button = QtWidgets.QToolButton(self)
self.menu_button.setIcon(build_icon(':/system/clear_shortcut.png'))
@@ -146,7 +140,8 @@
self.menu_button.setStyleSheet('QToolButton { border: none; padding: 0px 10px 0px 0px; }')
self.menu_button.resize(QtCore.QSize(28, 18))
self.menu_button.setMenu(menu)
- self.menu_button.setDefaultAction(first)
+ self.set_current_search_type(
+ Settings().value('{section}/last search type'.format(section=self.settings_section)))
self.menu_button.show()
self._update_style_sheet()
=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py 2016-09-16 21:43:30 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py 2016-11-12 08:38:13 +0000
@@ -199,7 +199,7 @@
self.quick_search_label = QtWidgets.QLabel(self.quickTab)
self.quick_search_label.setObjectName('quick_search_label')
self.quickLayout.addWidget(self.quick_search_label, 0, 0, QtCore.Qt.AlignRight)
- self.quick_search_edit = SearchEdit(self.quickTab)
+ self.quick_search_edit = SearchEdit(self.quickTab, self.settings_section)
self.quick_search_edit.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
self.quick_search_edit.setObjectName('quick_search_edit')
self.quick_search_label.setBuddy(self.quick_search_edit)
@@ -333,8 +333,8 @@
translate('BiblesPlugin.MediaItem', 'Text Search'),
translate('BiblesPlugin.MediaItem', 'Search Text...'))
])
- text = self.settings_section
- self.quick_search_edit.set_current_search_type(Settings().value('{text}/last search type'.format(text=text)))
+ if Settings().value(self.settings_section + '/reset to combined quick search'):
+ self.quick_search_edit.set_current_search_type(BibleSearch.Combined)
self.config_update()
log.debug('bible manager initialise complete')
@@ -444,15 +444,6 @@
only updated when we are doing reference or combined search, in text search the completion list is removed.
"""
log.debug('update_auto_completer')
- # Save the current search type to the configuration. If setting for automatically resetting the search type to
- # Combined is enabled, use that otherwise use the currently selected search type.
- # Note: This setting requires a restart to take effect.
- if Settings().value(self.settings_section + '/reset to combined quick search'):
- Settings().setValue('{section}/last search type'.format(section=self.settings_section),
- BibleSearch.Combined)
- else:
- Settings().setValue('{section}/last search type'.format(section=self.settings_section),
- self.quick_search_edit.current_search_type())
# Save the current bible to the configuration.
Settings().setValue('{section}/quick bible'.format(section=self.settings_section),
self.quickVersionComboBox.currentText())
=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
--- openlp/plugins/custom/lib/mediaitem.py 2016-10-23 19:24:53 +0000
+++ openlp/plugins/custom/lib/mediaitem.py 2016-11-12 08:38:13 +0000
@@ -105,8 +105,6 @@
[(CustomSearch.Titles, ':/songs/song_search_title.png', translate('SongsPlugin.MediaItem', 'Titles'),
translate('SongsPlugin.MediaItem', 'Search Titles...')),
(CustomSearch.Themes, ':/slides/slide_theme.png', UiStrings().Themes, UiStrings().SearchThemes)])
- text = '{section}/last search type'.format(section=self.settings_section)
- self.search_text_edit.set_current_search_type(Settings().value(text))
self.load_list(self.plugin.db_manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title))
self.config_update()
@@ -250,9 +248,6 @@
"""
Search the plugin database
"""
- # Save the current search type to the configuration.
- Settings().setValue('{section}/last search type'.format(section=self.settings_section),
- self.search_text_edit.current_search_type())
# Reload the list considering the new search type.
search_type = self.search_text_edit.current_search_type()
search_keywords = '%{search}%'.format(search=self.whitespace.sub(' ', self.search_text_edit.displayText()))
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py 2016-06-08 20:26:01 +0000
+++ openlp/plugins/songs/lib/mediaitem.py 2016-11-12 08:38:13 +0000
@@ -166,14 +166,9 @@
translate('SongsPlugin.MediaItem', 'CCLI number'),
translate('SongsPlugin.MediaItem', 'Search CCLI number...'))
])
- self.search_text_edit.set_current_search_type(
- Settings().value('{section}/last search type'.format(section=self.settings_section)))
self.config_update()
def on_search_text_button_clicked(self):
- # Save the current search type to the configuration.
- Settings().setValue('{section}/last search type'.format(section=self.settings_section),
- self.search_text_edit.current_search_type())
# Reload the list considering the new search type.
search_keywords = str(self.search_text_edit.displayText())
search_type = self.search_text_edit.current_search_type()
=== modified file 'tests/interfaces/openlp_core_lib/test_searchedit.py'
--- tests/interfaces/openlp_core_lib/test_searchedit.py 2016-05-31 21:40:13 +0000
+++ tests/interfaces/openlp_core_lib/test_searchedit.py 2016-11-12 08:38:13 +0000
@@ -23,6 +23,7 @@
Module to test the EditCustomForm.
"""
from unittest import TestCase
+from unittest.mock import MagicMock, call, patch
from PyQt5 import QtCore, QtGui, QtTest, QtWidgets
@@ -58,7 +59,12 @@
self.main_window = QtWidgets.QMainWindow()
Registry().register('main_window', self.main_window)
- self.search_edit = SearchEdit(self.main_window)
+ settings_patcher = patch(
+ 'openlp.core.lib.searchedit.Settings', return_value=MagicMock(**{'value.return_value': SearchTypes.First}))
+ self.addCleanup(settings_patcher.stop)
+ self.mocked_settings = settings_patcher.start()
+
+ self.search_edit = SearchEdit(self.main_window, 'settings_section')
# To complete set up we have to set the search types.
self.search_edit.set_search_types(SEARCH_TYPES)
@@ -78,8 +84,11 @@
# WHEN:
- # THEN: The first search type should be the first one in the list.
- assert self.search_edit.current_search_type() == SearchTypes.First, "The first search type should be selected."
+ # THEN: The first search type should be the first one in the list. The selected type should be saved in the
+ # settings
+ self.assertEqual(self.search_edit.current_search_type(), SearchTypes.First,
+ "The first search type should be selected.")
+ self.mocked_settings().setValue.assert_called_once_with('settings_section/last search type', 0)
def test_set_current_search_type(self):
"""
@@ -90,11 +99,13 @@
result = self.search_edit.set_current_search_type(SearchTypes.Second)
# THEN:
- assert result, "The call should return success (True)."
- assert self.search_edit.current_search_type() == SearchTypes.Second,\
- "The search type should be SearchTypes.Second"
- assert self.search_edit.placeholderText() == SECOND_PLACEHOLDER_TEXT,\
- "The correct placeholder text should be 'Second Placeholder Text'."
+ self.assertTrue(result, "The call should return success (True).")
+ self.assertEqual(self.search_edit.current_search_type(), SearchTypes.Second,
+ "The search type should be SearchTypes.Second")
+ self.assertEqual(self.search_edit.placeholderText(), SECOND_PLACEHOLDER_TEXT,
+ "The correct placeholder text should be 'Second Placeholder Text'.")
+ self.mocked_settings().setValue.assert_has_calls(
+ [call('settings_section/last search type', 0), call('settings_section/last search type', 1)])
def test_clear_button_visibility(self):
"""
Follow ups