Navigation Menu

Skip to content

Commit

Permalink
[pyqgis-console] encoding to utf-8 when open or save a script file: a…
Browse files Browse the repository at this point in the history
…gain fixes for non-ascii chars
  • Loading branch information
slarosa committed Aug 7, 2013
1 parent 39f2898 commit d821bcc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/console/console_editor.py
Expand Up @@ -35,6 +35,7 @@
import pyclbr
from operator import itemgetter
import traceback
import codecs

class KeyFilter(QObject):
SHORTCUTS = {
Expand Down Expand Up @@ -486,7 +487,7 @@ def createTempFile(self):
import tempfile
fd, path = tempfile.mkstemp()
tmpFileName = path + '.py'
with open(path, "w") as f:
with codecs.open(path, "w", encoding='utf-8') as f:
f.write(self.text())
os.close(fd)
os.rename(path, tmpFileName)
Expand Down Expand Up @@ -758,7 +759,7 @@ def __init__(self, parent, parentConsole, filename, readOnly):

def loadFile(self, filename, modified):
self.newEditor.lastModified = QFileInfo(filename).lastModified()
fn = open(unicode(filename), "rb")
fn = codecs.open(unicode(filename), "rb", encoding='utf-8')
txt = fn.read()
fn.close()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Expand Down Expand Up @@ -804,7 +805,7 @@ def save(self, fileName=None):
os.remove(temp_path)
os.rename(path, temp_path)
# Save the new contents
with open(path, "w") as f:
with codecs.open(path, "w", encoding='utf-8') as f:
f.write(self.newEditor.text())
if overwrite:
os.remove(temp_path)
Expand Down Expand Up @@ -1007,7 +1008,7 @@ def newTabEditor(self, tabName=None, filename=None):
if filename:
readOnly = not QFileInfo(filename).isWritable()
try:
fn = open(unicode(filename), "rb")
fn = codecs.open(unicode(filename), "rb", encoding='utf-8')
txt = fn.read()
fn.close()
except IOError, error:
Expand Down

0 comments on commit d821bcc

Please sign in to comment.