Yuya Nishihara committed 01099e9

qscilib: convert to local encoding on reading/writing file (fixes #1719) and write() do not convert character encoding. Editing
it will mess up the content because the GUI encoding is UTF-8.

Currently readFile() has no except block because hglib.tounicode() never raise

  • Participants
  • Parent commits 601faee
  • Branches stable

Comments (0)

Files changed (1)


         return False
-    if not
+    data = str(f.readAll())
+    if f.error():
         qtlib.WarningMsgBox(_('Unable to read file'),
                             _('An error occurred while reading the file.'),
                             f.errorString(), parent=editor)
         return False
+    text = hglib.tounicode(data)
+    editor.setText(text)
     return True
 def writeFile(editor, filename):
+    text = editor.text()
+    try:
+        data = hglib.fromunicode(text)
+    except UnicodeEncodeError, inst:
+        qtlib.WarningMsgBox(_('Unable to write file'),
+                            _('Could not translate the file content to '
+                              'native encoding.'),
+                            hglib.tounicode(str(inst)), parent=editor)
+        return False
     f = QFile(filename)
     if not
         qtlib.WarningMsgBox(_('Unable to write file'),
                             _('Could not open the specified file for writing.'),
                             f.errorString(), parent=editor)
         return False
-    if not editor.write(f):
+    if f.write(data) < 0:
         qtlib.WarningMsgBox(_('Unable to write file'),
                             _('An error occurred while writing the file.'),
                             f.errorString(), parent=editor)