Tests and added icon

This commit is contained in:
Philip Ridout 2017-04-02 21:28:55 +01:00
parent 53b210d9cd
commit eee14a654a
8 changed files with 53 additions and 13 deletions

View File

@ -125,6 +125,15 @@ class ListWidgetWithDnD(QtWidgets.QListWidget):
else: else:
event.ignore() event.ignore()
def allItems(self):
"""
An generator to list all the items in the widget
:return: a generator
"""
for row in range(self.count()):
yield self.item(row)
def paintEvent(self, event): def paintEvent(self, event):
""" """
Re-implement paintEvent so that we can add 'No Results' text when the listWidget is empty. Re-implement paintEvent so that we can add 'No Results' text when the listWidget is empty.

View File

@ -84,8 +84,7 @@ class BibleMediaItem(MediaManagerItem):
:param kwargs: Keyword arguments to pass to the super method. (dict) :param kwargs: Keyword arguments to pass to the super method. (dict)
""" """
self.clear_icon = build_icon(':/bibles/bibles_search_clear.png') self.clear_icon = build_icon(':/bibles/bibles_search_clear.png')
self.lock_icon = build_icon(':/bibles/bibles_search_lock.png') self.save_results_icon = build_icon(':/bibles/bibles_save_results.png')
self.unlock_icon = build_icon(':/bibles/bibles_search_unlock.png')
self.sort_icon = build_icon(':/bibles/bibles_book_sort.png') self.sort_icon = build_icon(':/bibles/bibles_book_sort.png')
self.bible = None self.bible = None
self.second_bible = None self.second_bible = None
@ -191,7 +190,7 @@ class BibleMediaItem(MediaManagerItem):
self.clear_button = QtWidgets.QToolButton(self) self.clear_button = QtWidgets.QToolButton(self)
self.clear_button.setIcon(self.clear_icon) self.clear_button.setIcon(self.clear_icon)
self.save_results_button = QtWidgets.QToolButton(self) self.save_results_button = QtWidgets.QToolButton(self)
self.save_results_button.setIcon(self.unlock_icon) self.save_results_button.setIcon(self.save_results_icon)
self.search_button_layout.addWidget(self.clear_button) self.search_button_layout.addWidget(self.clear_button)
self.search_button_layout.addWidget(self.save_results_button) self.search_button_layout.addWidget(self.save_results_button)
self.search_button = QtWidgets.QPushButton(self) self.search_button = QtWidgets.QPushButton(self)
@ -201,6 +200,7 @@ class BibleMediaItem(MediaManagerItem):
self.results_view_tab = QtWidgets.QTabBar(self) self.results_view_tab = QtWidgets.QTabBar(self)
self.results_view_tab.addTab('') self.results_view_tab.addTab('')
self.results_view_tab.addTab('') self.results_view_tab.addTab('')
self.results_view_tab.setCurrentIndex(ResultsTab.Search)
self.page_layout.addWidget(self.results_view_tab) self.page_layout.addWidget(self.results_view_tab)
def setupUi(self): def setupUi(self):
@ -492,18 +492,18 @@ class BibleMediaItem(MediaManagerItem):
:return: None :return: None
""" """
current_index = self.results_view_tab.currentIndex() current_index = self.results_view_tab.currentIndex()
for item in self.list_view.selectedItems():
self.list_view.takeItem(self.list_view.row(item))
results = [item.data(QtCore.Qt.UserRole) for item in self.list_view.allItems()]
if current_index == ResultsTab.Saved: if current_index == ResultsTab.Saved:
self.saved_results = [] self.saved_results = results
elif current_index == ResultsTab.Search: elif current_index == ResultsTab.Search:
self.current_results = [] self.current_results = results
self.search_edit.clear()
self.on_focus()
self.on_results_view_tab_total_update(current_index) self.on_results_view_tab_total_update(current_index)
self.list_view.clear()
def on_save_results_button_clicked(self): def on_save_results_button_clicked(self):
""" """
Toggle the lock button. Add the selected verses to the saved_results list.
:return: None :return: None
""" """

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 B

View File

@ -34,8 +34,7 @@
<file>bibles_search_text.png</file> <file>bibles_search_text.png</file>
<file>bibles_search_reference.png</file> <file>bibles_search_reference.png</file>
<file>bibles_search_clear.png</file> <file>bibles_search_clear.png</file>
<file>bibles_search_unlock.png</file> <file>bibles_save_results.png</file>
<file>bibles_search_lock.png</file>
</qresource> </qresource>
<qresource prefix="plugins"> <qresource prefix="plugins">
<file>plugin_alerts.png</file> <file>plugin_alerts.png</file>
@ -144,7 +143,6 @@
</qresource> </qresource>
<qresource prefix="remote"> <qresource prefix="remote">
<file>network_server.png</file> <file>network_server.png</file>
<file>network_ssl.png</file>
<file>network_auth.png</file> <file>network_auth.png</file>
</qresource> </qresource>
<qresource prefix="songusage"> <qresource prefix="songusage">

View File

@ -23,6 +23,7 @@
This module contains tests for the openlp.core.lib.listwidgetwithdnd module This module contains tests for the openlp.core.lib.listwidgetwithdnd module
""" """
from unittest import TestCase from unittest import TestCase
from types import GeneratorType
from openlp.core.common.uistrings import UiStrings from openlp.core.common.uistrings import UiStrings
from openlp.core.ui.lib.listwidgetwithdnd import ListWidgetWithDnD from openlp.core.ui.lib.listwidgetwithdnd import ListWidgetWithDnD
@ -59,6 +60,38 @@ class TestListWidgetWithDnD(TestCase):
# THEN: The results text should be the 'short results' text. # THEN: The results text should be the 'short results' text.
self.assertEqual(widget.no_results_text, UiStrings().ShortResults) self.assertEqual(widget.no_results_text, UiStrings().ShortResults)
def test_all_items_no_list_items(self):
"""
Test allItems when there are no items in the list widget
"""
# GIVEN: An instance of ListWidgetWithDnD
widget = ListWidgetWithDnD()
with patch.object(widget, 'count', return_value=0), \
patch.object(widget, 'item', side_effect=lambda x: [][x]):
# WHEN: Calling allItems
result = widget.allItems()
# THEN: An instance of a Generator object should be returned. The generator should not yeild any results
self.assertIsInstance(result, GeneratorType)
self.assertEqual(list(result), [])
def test_all_items_list_items(self):
"""
Test allItems when the list widget contains some items.
"""
# GIVEN: An instance of ListWidgetWithDnD
widget = ListWidgetWithDnD()
with patch.object(widget, 'count', return_value=2), \
patch.object(widget, 'item', side_effect=lambda x: [5, 3][x]):
# WHEN: Calling allItems
result = widget.allItems()
# THEN: An instance of a Generator object should be returned. The generator should not yeild any results
self.assertIsInstance(result, GeneratorType)
self.assertEqual(list(result), [5, 3])
def test_paint_event(self): def test_paint_event(self):
""" """
Test the paintEvent method when the list is not empty Test the paintEvent method when the list is not empty