Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Don't show TextEditor if it fails to be initialized #3906

Merged
merged 5 commits into from
Jun 1, 2017
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
9 changes: 6 additions & 3 deletions spyder/widgets/variableexplorer/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,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