diff --git a/securedrop_client/gui/__init__.py b/securedrop_client/gui/__init__.py index 76a3d2fc4..363efaba7 100644 --- a/securedrop_client/gui/__init__.py +++ b/securedrop_client/gui/__init__.py @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ +import textwrap from typing import Union @@ -167,8 +168,11 @@ def __init__( flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), ): super().__init__(parent, flags) + self.setWordWrap(True) self.setText(text) def setText(self, text: str) -> None: self.setTextFormat(Qt.PlainText) - super().setText(text) + # Wraps text at default of 70 characters. + wrapped = "\n".join(textwrap.wrap(text)) + super().setText(wrapped) diff --git a/tests/gui/test_init.py b/tests/gui/test_init.py index bb29ae289..85b0d9123 100644 --- a/tests/gui/test_init.py +++ b/tests/gui/test_init.py @@ -1,6 +1,7 @@ """ Tests for the gui helper functions in __init__.py """ +import textwrap from PyQt5.QtCore import QSize, Qt from PyQt5.QtWidgets import QApplication @@ -169,3 +170,15 @@ def test_SecureQLabel_setText(mocker): def test_SecureQLabel_quotes_not_escaped_for_readability(): sl = SecureQLabel("'hello'") assert sl.text() == "'hello'" + + +def test_SecureQLabel_wraps_on_70(): + msg = ( + "thisisaverylongmessagethatwillnotwrapunlessthistestpassesproperly1234" + "thisisaverylongmessagethatwillnotwrapunlessthistestpassesproperly1234" + "thisisaverylongmessagethatwillnotwrapunlessthistestpassesproperly1234" + ) + sl = SecureQLabel(msg) + expected = "\n".join(textwrap.wrap(msg)) + assert sl.text() == expected + assert sl.wordWrap() is True