mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-24 00:05:18 -05:00
[pyqgis-console] encoding to utf-8 when open or save a script file: again fixes for non-ascii chars
This commit is contained in:
parent
39f289816e
commit
d821bcc31b
@ -35,6 +35,7 @@ import datetime
|
||||
import pyclbr
|
||||
from operator import itemgetter
|
||||
import traceback
|
||||
import codecs
|
||||
|
||||
class KeyFilter(QObject):
|
||||
SHORTCUTS = {
|
||||
@ -486,7 +487,7 @@ class Editor(QsciScintilla):
|
||||
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)
|
||||
@ -758,7 +759,7 @@ class EditorTab(QWidget):
|
||||
|
||||
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))
|
||||
@ -804,7 +805,7 @@ class EditorTab(QWidget):
|
||||
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)
|
||||
@ -1007,7 +1008,7 @@ class EditorTabWidget(QTabWidget):
|
||||
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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user