Skip to content

Commit

Permalink
Merge from 3.x: PR #3906
Browse files Browse the repository at this point in the history
Fixes #3673
  • Loading branch information
ccordoba12 committed Jun 1, 2017
2 parents daf231b + 51e8a02 commit 8967e05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions spyder/widgets/variableexplorer/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,12 @@ def createEditor(self, parent, option, index):
return editor
#---editor = TextEditor
elif is_text_string(value) and len(value) > 40:
editor = TextEditor(value, key)
self.create_dialog(editor, dict(model=index.model(), editor=editor,
key=key, readonly=readonly))
te = TextEditor(None)
if te.setup_and_check(value):
editor = TextEditor(value, key)
self.create_dialog(editor, dict(model=index.model(),
editor=editor, key=key,
readonly=readonly))
return None
#---editor = QLineEdit
elif is_editable_type(value):
Expand Down
11 changes: 11 additions & 0 deletions spyder/widgets/variableexplorer/tests/test_texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

# Local imports
from spyder.py3compat import PY2
from spyder.widgets.variableexplorer.texteditor import TextEditor

@pytest.fixture
Expand All @@ -31,6 +32,16 @@ def test_texteditor(qtbot):
dlg_text = texteditor.get_value()
assert text == dlg_text

def test_texteditor_setup_and_check():
if PY2:
import string
dig_its = string.digits;
translate_digits = string.maketrans(dig_its,len(dig_its)*' ')
editor = TextEditor(None)
assert not editor.setup_and_check(translate_digits)
else:
assert True


if __name__ == "__main__":
pytest.main()
8 changes: 8 additions & 0 deletions spyder/widgets/variableexplorer/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def get_value(self):
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
return self.text

def setup_and_check(self, value):
"""Verify if TextEditor is able to display strings passed to it."""
try:
to_text_string(value, 'utf8')
return True
except:
return False


#==============================================================================
# Tests
Expand Down

0 comments on commit 8967e05

Please sign in to comment.