From ae852466ecc12075af304da427fc5c149a8583f0 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 14 Dec 2014 16:54:25 +0000 Subject: [PATCH 01/13] Fix selecting items in media manager using the keyboard when preview media items when clicked is set --- openlp/core/ui/slidecontroller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index c2c00856f..26d8ab06d 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -863,7 +863,8 @@ class SlideController(DisplayController, RegistryProperties): if service_item.is_media(): self.on_media_start(service_item) self.slide_selected(True) - self.preview_widget.setFocus() + if service_item.from_service: + self.preview_widget.setFocus() if old_item: # Close the old item after the new one is opened # This avoids the service theme/desktop flashing on screen From e93eda152b54944d9ed6502b425c78073d94a57c Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 14 Dec 2014 16:56:48 +0000 Subject: [PATCH 02/13] fixes bug1390236 by limiting the selection in the media manager when a large number of results are returned --- openlp/plugins/bibles/lib/mediaitem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 76f91071a..47822d98b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -713,7 +713,8 @@ class BibleMediaItem(MediaManagerItem): items = self.build_display_results(bible, second_bible, self.search_results) for bible_verse in items: self.list_view.addItem(bible_verse) - self.list_view.selectAll() + if len(items) < 100: + self.list_view.selectAll() self.search_results = {} self.second_search_results = {} From cb0e4dc7ba8d16ca47b498e1ca9f4888317a7b5e Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 19 Dec 2014 22:01:15 +0000 Subject: [PATCH 03/13] added copyright header to test --- .../openlp_plugins/songs/test_mediaitem.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 2f844b891..44b716ad2 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### """ This module contains tests for the lib submodule of the Songs plugin. """ From 4a9a7f282988c374bef6cf3988c98c6dbdf9bccf Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 19 Dec 2014 22:02:45 +0000 Subject: [PATCH 04/13] adds tests for bible media item --- .../openlp_plugins/bibles/test_mediaitem.py | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 tests/functional/openlp_plugins/bibles/test_mediaitem.py diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py new file mode 100644 index 000000000..0232f1d60 --- /dev/null +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +This module contains tests for the lib submodule of the Presentations plugin. +""" +from unittest import TestCase +from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem +from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin + + +class TestMediaItem(TestCase, TestMixin): + """ + Test the bible mediaitem methods. + """ + + def setUp(self): + """ + Set up the components need for all tests. + """ + with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\ + patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'): + self.media_item = BibleMediaItem(None, MagicMock()) + self.setup_application() + + def display_results_no_results_test(self): + """ + Test the display_results method when called with a single bible, returning no results + """ + + # GIVEN: A mocked build_display_results which returns an empty list + with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \ + as mocked_build_display_results: + mocked_list_view = MagicMock() + self.media_item.search_results = 'results' + self.media_item.list_view = mocked_list_view + + # WHEN: Calling display_results with a single bible version + self.media_item.display_results('NIV') + + # THEN: No items should be added to the list, and select all should have been called. + mocked_build_display_results.assert_called_once_with('NIV', '', 'results') + self.assertFalse(mocked_list_view.addItem.called) + mocked_list_view.selectAll.assert_called_once_with() + self.assertEqual(self.media_item.search_results, {}) + self.assertEqual(self.media_item.second_search_results, {}) + + def display_results_two_bibles_no_results_test(self): + """ + Test the display_results method when called with two bibles, returning no results + """ + + # GIVEN: A mocked build_display_results which returns an empty list + with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \ + as mocked_build_display_results: + mocked_list_view = MagicMock() + self.media_item.search_results = 'results' + self.media_item.list_view = mocked_list_view + + # WHEN: Calling display_results with two single bible versions + self.media_item.display_results('NIV', 'GNB') + + # THEN: build_display_results should have been called with two bible versions. + # No items should be added to the list, and select all should have been called. + mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results') + self.assertFalse(mocked_list_view.addItem.called) + mocked_list_view.selectAll.assert_called_once_with() + self.assertEqual(self.media_item.search_results, {}) + self.assertEqual(self.media_item.second_search_results, {}) + + def display_results_returns_lots_of_results_test_test(self): + """ + Test the display_results method a large number of results (> 100) are returned + """ + + # GIVEN: A mocked build_displat_results which returns a large list of results + long_list = list(range(100)) + with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': long_list})\ + as mocked_build_display_results: + mocked_list_view = MagicMock() + self.media_item.search_results = 'results' + self.media_item.list_view = mocked_list_view + + # WHEN: Calling display_results + self.media_item.display_results('NIV', 'GNB') + + # THEN: addItem should have been called 100 times, and the lsit items should not be selected. + mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results') + self.assertEqual(mocked_list_view.addItem.call_count, 100) + self.assertFalse(mocked_list_view.selectAll.called) + self.assertEqual(self.media_item.search_results, {}) + self.assertEqual(self.media_item.second_search_results, {}) From 5d1eac9ded10f6c6910355a8a5dd4a17bb6abe9e Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 30 Dec 2014 08:48:46 +0000 Subject: [PATCH 05/13] Add function to provide elided text Fixes: https://launchpad.net/bugs/1405260 --- openlp/core/ui/slidecontroller.py | 5 ++++- openlp/core/utils/__init__.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index e912688eb..7f80bcfc7 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -43,6 +43,7 @@ from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageS ScreenList, build_icon, build_html from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType from openlp.core.lib.ui import create_action +from openlp.core.utils import elide_text from openlp.core.utils.actions import ActionList, CategoryOrder from openlp.core.ui.listpreviewwidget import ListPreviewWidget @@ -161,6 +162,7 @@ class SlideController(DisplayController, RegistryProperties): # Info label for the title of the current item, at the top of the slide controller self.info_label = QtGui.QLabel(self.panel) self.info_label.setAlignment(QtCore.Qt.AlignCenter) + self.info_label.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred) self.panel_layout.addWidget(self.info_label) # Splitter self.splitter = QtGui.QSplitter(self.panel) @@ -808,7 +810,8 @@ class SlideController(DisplayController, RegistryProperties): if service_item.is_command(): Registry().execute( '%s_start' % service_item.name.lower(), [self.service_item, self.is_live, self.hide_mode(), slide_no]) - self.info_label.setText(self.service_item.title) + self.info_label.setText(elide_text(self.service_item.title, self.info_label.font(), self.info_label.width())) + self.info_label.setToolTip(self.service_item.title) self.slide_list = {} if self.is_live: self.song_menu.menu().clear() diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 0510c832b..0c3eb6634 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -506,6 +506,17 @@ def get_natural_key(string): return [b''] + key return key +def elide_text(text, font, width): + """ + Add an ellipsis to text if it is wider than width. + + :param text: The string to elide + :param font: The font that the text is being desplayed in + :param width: The width that the elided text string needs to fill + :return: The elided string or just text + """ + font_metrics = QtGui.QFontMetrics(font) + return font_metrics.elidedText(text, QtCore.Qt.ElideRight, width) from .languagemanager import LanguageManager from .actions import ActionList From d87c39de44f112bbe7dd48b040279d3b331cccca Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 30 Dec 2014 08:55:16 +0000 Subject: [PATCH 06/13] revert previous changes --- openlp/plugins/bibles/lib/mediaitem.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 47822d98b..76f91071a 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -713,8 +713,7 @@ class BibleMediaItem(MediaManagerItem): items = self.build_display_results(bible, second_bible, self.search_results) for bible_verse in items: self.list_view.addItem(bible_verse) - if len(items) < 100: - self.list_view.selectAll() + self.list_view.selectAll() self.search_results = {} self.second_search_results = {} From 3cf2a21ca20d25984b71771121b063d17774f9d4 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 30 Dec 2014 09:03:35 +0000 Subject: [PATCH 07/13] fix tests --- tests/functional/openlp_plugins/bibles/test_mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py index 0232f1d60..e9ca2c8d1 100644 --- a/tests/functional/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -113,6 +113,6 @@ class TestMediaItem(TestCase, TestMixin): # THEN: addItem should have been called 100 times, and the lsit items should not be selected. mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results') self.assertEqual(mocked_list_view.addItem.call_count, 100) - self.assertFalse(mocked_list_view.selectAll.called) + mocked_list_view.selectAll.assert_called_once_with() self.assertEqual(self.media_item.search_results, {}) self.assertEqual(self.media_item.second_search_results, {}) From 19cb16d65b88c038fde9ffd3a055770a0ad53e8d Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 30 Dec 2014 11:21:06 +0000 Subject: [PATCH 08/13] Moved 'eliding' code to a sublass of qlabel to enable the text to be rendrawn when resized --- openlp/core/ui/slidecontroller.py | 34 ++++++++++++++++--- .../functional/openlp_core_utils/test_init.py | 1 + .../openlp_plugins/bibles/test_mediaitem.py | 18 ++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7f80bcfc7..7791604c1 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -106,6 +106,34 @@ class DisplayController(QtGui.QWidget): Registry().execute('%s' % sender, [controller, args]) +class InfoLabel(QtGui.QLabel): + """ + InfoLabel is a subclassed QLabel. Created to provide the ablilty add a ellipsis if the text is cut off. Original + source: https://stackoverflow.com/questions/11446478/pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize + """ + + def paintEvent(self, event): + """ + Reimplemented to allow the drawing of elided text if the text is longer than the width of the label + """ + painter = QtGui.QPainter(self) + metrics = QtGui.QFontMetrics(self.font()) + elided = metrics.elidedText(self.text(), QtCore.Qt.ElideRight, self.width()) + if elided == self.text(): + alignment = QtCore.Qt.AlignCenter + else: + alignment = QtCore.Qt.AlignLeft + painter.drawText(self.rect(), alignment, elided) + + + def setText(self, text): + """ + Reimplemented to set the tool tip text. + """ + self.setToolTip(text) + super().setText(text) + + class SlideController(DisplayController, RegistryProperties): """ SlideController is the slide controller widget. This widget is what the @@ -160,8 +188,7 @@ class SlideController(DisplayController, RegistryProperties): self.type_label.setText(UiStrings().Preview) self.panel_layout.addWidget(self.type_label) # Info label for the title of the current item, at the top of the slide controller - self.info_label = QtGui.QLabel(self.panel) - self.info_label.setAlignment(QtCore.Qt.AlignCenter) + self.info_label = InfoLabel(self.panel) self.info_label.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred) self.panel_layout.addWidget(self.info_label) # Splitter @@ -810,8 +837,7 @@ class SlideController(DisplayController, RegistryProperties): if service_item.is_command(): Registry().execute( '%s_start' % service_item.name.lower(), [self.service_item, self.is_live, self.hide_mode(), slide_no]) - self.info_label.setText(elide_text(self.service_item.title, self.info_label.font(), self.info_label.width())) - self.info_label.setToolTip(self.service_item.title) + self.info_label.setText(self.service_item.title) self.slide_list = {} if self.is_live: self.song_menu.menu().clear() diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index 563f0dc5b..6979be7b3 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -133,3 +133,4 @@ class TestInitFunctions(TestMixin, TestCase): # THEN: The connection parameters should be set for socket self.assertEqual(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' ' "--accept=socket,host=localhost,port=2002;urp;"') + diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py index e9ca2c8d1..131a679f0 100644 --- a/tests/functional/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -29,6 +29,8 @@ """ This module contains tests for the lib submodule of the Presentations plugin. """ +from PyQt4 import QtGui + from unittest import TestCase from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem from tests.functional import MagicMock, patch @@ -116,3 +118,19 @@ class TestMediaItem(TestCase, TestMixin): mocked_list_view.selectAll.assert_called_once_with() self.assertEqual(self.media_item.search_results, {}) self.assertEqual(self.media_item.second_search_results, {}) + + + def elide_text_short_text_test(self): + result = elide_text('Test String', QtGui.QFont(),) + +def elide_text(text, font, width): + """ + Add an ellipsis to text if it is wider than width. + + :param text: The string to elide + :param font: The font that the text is being desplayed in + :param width: The width that the elided text string needs to fill + :return: The elided string or just text + """ + font_metrics = QtGui.QFontMetrics(font) + return font_metrics.elidedText(text, QtCore.Qt.ElideRight, width) \ No newline at end of file From 52c7d89706e9fc02299bea7437e1f4b11058c3c5 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Tue, 30 Dec 2014 11:23:01 +0000 Subject: [PATCH 09/13] removal of util function --- openlp/core/ui/slidecontroller.py | 2 +- openlp/core/utils/__init__.py | 12 ------------ tests/functional/openlp_core_utils/test_init.py | 1 - .../openlp_plugins/bibles/test_mediaitem.py | 16 ---------------- 4 files changed, 1 insertion(+), 30 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7791604c1..0ca6968df 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -132,7 +132,7 @@ class InfoLabel(QtGui.QLabel): """ self.setToolTip(text) super().setText(text) - + class SlideController(DisplayController, RegistryProperties): """ diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 0c3eb6634..148b351ed 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -506,18 +506,6 @@ def get_natural_key(string): return [b''] + key return key -def elide_text(text, font, width): - """ - Add an ellipsis to text if it is wider than width. - - :param text: The string to elide - :param font: The font that the text is being desplayed in - :param width: The width that the elided text string needs to fill - :return: The elided string or just text - """ - font_metrics = QtGui.QFontMetrics(font) - return font_metrics.elidedText(text, QtCore.Qt.ElideRight, width) - from .languagemanager import LanguageManager from .actions import ActionList diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index 6979be7b3..563f0dc5b 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -133,4 +133,3 @@ class TestInitFunctions(TestMixin, TestCase): # THEN: The connection parameters should be set for socket self.assertEqual(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' ' "--accept=socket,host=localhost,port=2002;urp;"') - diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py index 131a679f0..305870d24 100644 --- a/tests/functional/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -118,19 +118,3 @@ class TestMediaItem(TestCase, TestMixin): mocked_list_view.selectAll.assert_called_once_with() self.assertEqual(self.media_item.search_results, {}) self.assertEqual(self.media_item.second_search_results, {}) - - - def elide_text_short_text_test(self): - result = elide_text('Test String', QtGui.QFont(),) - -def elide_text(text, font, width): - """ - Add an ellipsis to text if it is wider than width. - - :param text: The string to elide - :param font: The font that the text is being desplayed in - :param width: The width that the elided text string needs to fill - :return: The elided string or just text - """ - font_metrics = QtGui.QFontMetrics(font) - return font_metrics.elidedText(text, QtCore.Qt.ElideRight, width) \ No newline at end of file From 20d927b270d0a63998481b025398708805b58d92 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 2 Jan 2015 11:40:07 +0000 Subject: [PATCH 10/13] Rework to use a subclassed QLabel to allow dynamic resizing --- openlp/core/ui/slidecontroller.py | 2 +- .../openlp_core_ui/test_slidecontroller.py | 83 ++++++++++++++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 0ca6968df..0d0cc8eff 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -43,7 +43,6 @@ from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageS ScreenList, build_icon, build_html from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType from openlp.core.lib.ui import create_action -from openlp.core.utils import elide_text from openlp.core.utils.actions import ActionList, CategoryOrder from openlp.core.ui.listpreviewwidget import ListPreviewWidget @@ -119,6 +118,7 @@ class InfoLabel(QtGui.QLabel): painter = QtGui.QPainter(self) metrics = QtGui.QFontMetrics(self.font()) elided = metrics.elidedText(self.text(), QtCore.Qt.ElideRight, self.width()) + # If the text is elided align it left to stop it jittering as the label is resized if elided == self.text(): alignment = QtCore.Qt.AlignCenter else: diff --git a/tests/functional/openlp_core_ui/test_slidecontroller.py b/tests/functional/openlp_core_ui/test_slidecontroller.py index d8663c20c..0137c5096 100644 --- a/tests/functional/openlp_core_ui/test_slidecontroller.py +++ b/tests/functional/openlp_core_ui/test_slidecontroller.py @@ -29,12 +29,13 @@ """ Package to test the openlp.core.ui.slidecontroller package. """ +from PyQt4 import QtCore, QtGui + from unittest import TestCase from openlp.core import Registry from openlp.core.lib import ServiceItemAction - from openlp.core.ui import SlideController -from openlp.core.ui.slidecontroller import WIDE_MENU, NON_TEXT_MENU +from openlp.core.ui.slidecontroller import InfoLabel, WIDE_MENU, NON_TEXT_MENU from tests.interfaces import MagicMock, patch @@ -558,3 +559,81 @@ class TestSlideController(TestCase): self.assertEqual(0, mocked_update_preview.call_count, 'Update preview should not have been called') mocked_preview_widget.change_slide.assert_called_once_with(7) mocked_slide_selected.assert_called_once_with() + +class TestInfoLabel(TestCase): + + def paint_event_text_fits_test(self): + """ + Test the paintEvent method when text fits the label + """ + font = QtGui.QFont() + metrics = QtGui.QFontMetrics(font) + + with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \ + patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: + + # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods + info_label = InfoLabel() + test_string = 'Label Text' + mocked_rect = MagicMock() + mocked_text = MagicMock() + mocked_width = MagicMock() + mocked_text.return_value = test_string + info_label.rect = mocked_rect + info_label.text = mocked_text + info_label.width = mocked_width + + # WHEN: The instance is wider than its text, and the paintEvent method is called + info_label.width.return_value = metrics.boundingRect(test_string).width() + 10 + info_label.paintEvent(MagicMock()) + + # THEN: The text should be drawn centered with the complete test_string + mocked_qpainter().drawText.assert_called_once_with(mocked_rect(), QtCore.Qt.AlignCenter, test_string) + + def paint_event_text_doesnt_fit_test(self): + """ + Test the paintEvent method when text fits the label + """ + font = QtGui.QFont() + metrics = QtGui.QFontMetrics(font) + + with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \ + patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: + + # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods + info_label = InfoLabel() + test_string = 'Label Text' + mocked_rect = MagicMock() + mocked_text = MagicMock() + mocked_width = MagicMock() + mocked_text.return_value = test_string + info_label.rect = mocked_rect + info_label.text = mocked_text + info_label.width = mocked_width + + # WHEN: The instance is narrower than its text, and the paintEvent method is called + label_width = metrics.boundingRect(test_string).width() - 10 + info_label.width.return_value = label_width + info_label.paintEvent(MagicMock()) + + # THEN: The text should be drawn aligned left with an elided test_string + elided_test_string = metrics.elidedText(test_string, QtCore.Qt.ElideRight, label_width) + mocked_qpainter().drawText.assert_called_once_with(mocked_rect(), QtCore.Qt.AlignLeft, elided_test_string) + + def set_text_test(self): + """ + Test the reimplemented setText method + """ + with patch('builtins.super') as mocked_super: + + # GIVEN: An instance of InfoLabel and mocked setToolTip method + info_label = InfoLabel() + set_tool_tip_mock = MagicMock() + info_label.setToolTip = set_tool_tip_mock + + # WHEN: Calling the instance method setText + info_label.setText('Label Text') + + # THEN: The setToolTip and super class setText methods should have been called with the same text + set_tool_tip_mock.assert_called_once_with('Label Text') + mocked_super().setText.assert_called_once_with('Label Text') From 9fef267fd33039ca76f69ca3f0536c0668bc09bc Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 2 Jan 2015 11:42:17 +0000 Subject: [PATCH 11/13] Changed the year --- tests/functional/openlp_plugins/bibles/test_mediaitem.py | 4 ++-- tests/functional/openlp_plugins/songs/test_mediaitem.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py index 305870d24..2614dda37 100644 --- a/tests/functional/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -4,8 +4,8 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2014 Raoul Snyman # -# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Copyright (c) 2008-2015 Raoul Snyman # +# Portions copyright (c) 2008-2015 Tim Bentley, Gerald Britton, Jonathan # # Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # # Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # # Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 44b716ad2..3b382f230 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -4,8 +4,8 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2014 Raoul Snyman # -# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Copyright (c) 2008-2015 Raoul Snyman # +# Portions copyright (c) 2008-2015 Tim Bentley, Gerald Britton, Jonathan # # Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # # Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # # Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # From 3cafbfd0ed5124fefc1a307e6261bd82730021a0 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 2 Jan 2015 11:54:42 +0000 Subject: [PATCH 12/13] Typo in comments fixed --- tests/functional/openlp_plugins/bibles/test_mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/bibles/test_mediaitem.py b/tests/functional/openlp_plugins/bibles/test_mediaitem.py index 2614dda37..d9d341d54 100644 --- a/tests/functional/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/functional/openlp_plugins/bibles/test_mediaitem.py @@ -101,7 +101,7 @@ class TestMediaItem(TestCase, TestMixin): Test the display_results method a large number of results (> 100) are returned """ - # GIVEN: A mocked build_displat_results which returns a large list of results + # GIVEN: A mocked build_display_results which returns a large list of results long_list = list(range(100)) with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': long_list})\ as mocked_build_display_results: From c27c875f339fcd152f78b356fd1535e3aee0f0d3 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Fri, 2 Jan 2015 11:58:44 +0000 Subject: [PATCH 13/13] Readded deleted line. One more comment typo --- openlp/core/ui/slidecontroller.py | 2 +- openlp/core/utils/__init__.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 4d63a4229..ee627fc6c 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -107,7 +107,7 @@ class DisplayController(QtGui.QWidget): class InfoLabel(QtGui.QLabel): """ - InfoLabel is a subclassed QLabel. Created to provide the ablilty add a ellipsis if the text is cut off. Original + InfoLabel is a subclassed QLabel. Created to provide the ablilty to add a ellipsis if the text is cut off. Original source: https://stackoverflow.com/questions/11446478/pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize """ diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 81fc1ff2d..ece8011ac 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -506,6 +506,7 @@ def get_natural_key(string): return [b''] + key return key + from .languagemanager import LanguageManager from .actions import ActionList