~ubuntu-branches/ubuntu/wily/spyder/wily

« back to all changes in this revision

Viewing changes to spyderlib/widgets/texteditor.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2015-01-15 12:20:11 UTC
  • mfrom: (18.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150115122011-cc7j5dhy2h9uo13m
Tags: 2.3.2+dfsg-1ubuntu1
Backport patch to support pylint3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from spyderlib.baseconfig import _
18
18
from spyderlib.guiconfig import get_font
19
19
from spyderlib.utils.qthelpers import get_icon
20
 
from spyderlib.py3compat import to_text_string
 
20
from spyderlib.py3compat import (to_text_string, to_binary_string,
 
21
                                 is_binary_string)
21
22
 
22
23
 
23
24
class TextEditor(QDialog):
34
35
        
35
36
        self.text = None
36
37
        
37
 
        self._conv = str if isinstance(text, str) else to_text_string
 
38
        # Display text as unicode if it comes as bytes, so users see 
 
39
        # its right representation
 
40
        if is_binary_string(text):
 
41
            self.is_binary = True
 
42
            text = to_text_string(text, 'utf8')
 
43
        else:
 
44
            self.is_binary = False
38
45
        
39
46
        self.layout = QVBoxLayout()
40
47
        self.setLayout(self.layout)
68
75
    
69
76
    def text_changed(self):
70
77
        """Text has changed"""
71
 
        self.text = self._conv(self.edit.toPlainText())
 
78
        # Save text as bytes, if it was initially bytes
 
79
        if self.is_binary:
 
80
            self.text = to_binary_string(self.edit.toPlainText(), 'utf8')
 
81
        else:
 
82
            self.text = to_text_string(self.edit.toPlainText())
72
83
        
73
84
    def get_value(self):
74
85
        """Return modified text"""