Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import textwrap

from typing import Union

Expand Down Expand Up @@ -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)
13 changes: 13 additions & 0 deletions tests/gui/test_init.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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