From ec19cc5f078eb33a579a7dddf18481ac3a75c86f Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 30 Oct 2016 08:29:22 +0000 Subject: [PATCH] Modified some resources and added test --- openlp/core/lib/__init__.py | 15 +- openlp/core/ui/settingsform.py | 2 +- resources/images/openlp-logo.svg | 347 ++++--------------- tests/functional/openlp_core_lib/test_lib.py | 38 +- 4 files changed, 99 insertions(+), 303 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 24399a915..284724552 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -119,7 +119,7 @@ def str_to_bool(string_value): return str(string_value).strip().lower() in ('true', 'yes', 'y') -def build_icon(icon, size=None): +def build_icon(icon): """ Build a QIcon instance from an existing QIcon, a resource location, or a physical file location. If the icon is a QIcon instance, that icon is simply returned. If not, it builds a QIcon instance from the resource or file name. @@ -127,23 +127,18 @@ def build_icon(icon, size=None): :param icon: The icon to build. This can be a QIcon, a resource string in the form ``:/resource/file.png``, or a file location like ``/path/to/file.png``. However, the **recommended** way is to specify a resource string. - :param size: - The size of the icon to generate :return: The build icon. """ if isinstance(icon, QtGui.QIcon): return icon + pix_map = None button_icon = QtGui.QIcon() if isinstance(icon, str): - if icon.startswith(':/'): - pix_map = QtGui.QPixmap(icon) - else: - pix_map = QtGui.QPixmap.fromImage(QtGui.QImage(icon)) + pix_map = QtGui.QPixmap(icon) elif isinstance(icon, QtGui.QImage): pix_map = QtGui.QPixmap.fromImage(icon) - if size: - pix_map = pix_map.scaled(size, size, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) - button_icon.addPixmap(pix_map, QtGui.QIcon.Normal, QtGui.QIcon.Off) + if pix_map: + button_icon.addPixmap(pix_map, QtGui.QIcon.Normal, QtGui.QIcon.Off) return button_icon diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 4b605e162..42558b830 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -89,7 +89,7 @@ class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): # add the tab to get it to display in the correct part of the screen self.stacked_layout.addWidget(tab_widget) if is_visible: - list_item = QtWidgets.QListWidgetItem(build_icon(tab_widget.icon_path, 16), tab_widget.tab_title_visible) + list_item = QtWidgets.QListWidgetItem(build_icon(tab_widget.icon_path), tab_widget.tab_title_visible) list_item.setData(QtCore.Qt.UserRole, tab_widget.tab_title) self.setting_list_widget.addItem(list_item) diff --git a/resources/images/openlp-logo.svg b/resources/images/openlp-logo.svg index c5e7985e1..d1ff61bec 100644 --- a/resources/images/openlp-logo.svg +++ b/resources/images/openlp-logo.svg @@ -1,6 +1,4 @@ - - + id="svg5740" + height="467.39178" + width="467.39178"> + style="stop-color:#ffffff;stop-opacity:0.25098041;" /> + style="stop-color:#ffffff;stop-opacity:0;" /> + style="stop-color:#cdcdff;stop-opacity:1;" /> + style="stop-color:#ebebff;stop-opacity:1;" /> + style="stop-color:#000d26;stop-opacity:1;" /> + style="stop-color:#507fda;stop-opacity:1;" /> - + color-interpolation-filters="sRGB" + id="filter6926"> + id="feGaussianBlur6928" + stdDeviation="3.5771872" /> - - - - - - - - - - - - - - - + xlink:href="#linearGradient3195" /> - + + y1="276.68851" + x1="470.25891" + gradientTransform="matrix(0.7247086,0,0,0.7843464,-109.42065,-2.1325924)" + gradientUnits="userSpaceOnUse" + id="linearGradient4057" + xlink:href="#linearGradient3208" /> - @@ -273,92 +88,56 @@ image/svg+xml + + id="layer1" /> + id="layer5" /> + id="layer3" /> + id="layer2" /> + id="layer6"> + transform="translate(9.8817328,9.8817328)" + id="g4018"> - + + id="path6317" + d="M 833.03006,395.26932 A 357.71872,357.71872 0 0 1 475.31134,752.98804 357.71872,357.71872 0 0 1 117.59262,395.26932 357.71872,357.71872 0 0 1 475.31134,37.550598 357.71872,357.71872 0 0 1 833.03006,395.26932 Z" + transform="matrix(0.6317287,0,0,0.6317287,-64.581662,-12.716988)" /> + id="path6327" /> + id="path3203" /> diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 145be21f4..db95044fd 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -189,16 +189,14 @@ class TestLib(TestCase): """ Test the build_icon() function with a QIcon instance """ - with patch('openlp.core.lib.QtGui') as MockedQtGui: - # GIVEN: A mocked QIcon - MockedQtGui.QIcon = MagicMock - mocked_icon = MockedQtGui.QIcon() + # GIVEN: An icon QIcon + icon = QtGui.QIcon() - # WHEN: We pass a QIcon instance in - result = build_icon(mocked_icon) + # WHEN: We pass a QIcon instance in + result = build_icon(icon) - # THEN: The result should be our mocked QIcon - self.assertIs(mocked_icon, result, 'The result should be the mocked QIcon') + # THEN: The result should be the same icon as we passed in + self.assertIs(icon, result, 'The result should be the same icon as we passed in') def test_build_icon_with_resource(self): """ @@ -223,6 +221,30 @@ class TestLib(TestCase): self.assertIsInstance(result, MagicMock, 'The result should be a MagicMock, because we mocked it out') def test_image_to_byte(self): + """ + Test the image_to_byte() function + """ + with patch('openlp.core.lib.QtCore') as MockedQtCore: + # GIVEN: A set of mocked-out Qt classes + mocked_byte_array = MagicMock() + MockedQtCore.QByteArray.return_value = mocked_byte_array + mocked_buffer = MagicMock() + MockedQtCore.QBuffer.return_value = mocked_buffer + MockedQtCore.QIODevice.WriteOnly = 'writeonly' + mocked_image = MagicMock() + + # WHEN: We convert an image to a byte array + result = image_to_byte(mocked_image, base_64=False) + + # THEN: We should receive the mocked_buffer + MockedQtCore.QByteArray.assert_called_with() + MockedQtCore.QBuffer.assert_called_with(mocked_byte_array) + mocked_buffer.open.assert_called_with('writeonly') + mocked_image.save.assert_called_with(mocked_buffer, "PNG") + self.assertFalse(mocked_byte_array.toBase64.called) + self.assertEqual(mocked_byte_array, result, 'The mocked out byte array should be returned') + + def test_image_to_byte_base_64(self): """ Test the image_to_byte() function """