eaglexmw / seascope

Automatically exported from code.google.com/p/seascope
Other
0 stars 0 forks source link

experimental write support: Corrupts UTF-8 files #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Open some UTF-8 file for editing
2. Make modification
3. Try to save file -> will result empty file

What is the expected output? What do you see instead?
Should write the file.

What version of the product are you using? On what operating system?
Latest from mercurial repository

Possible fix(I am not Python programmer but following patch seems to fix the 
issue):

diff -r 8651d7e03a59 src/view/EdViewRW.py
--- a/src/view/EdViewRW.py      Sun Sep 02 18:59:11 2012 -0700
+++ b/src/view/EdViewRW.py      Tue Sep 11 16:55:28 2012 +0300
@@ -40,7 +40,7 @@
                self.show()

                ## Show this file in the editor
-               self.setText(open(filename).read())
+               self.setText(open(filename).read().decode("UTF-8"))

                ## process for modifiled.
                self.setModified(False)
@@ -63,7 +63,7 @@
                if(self.isModified()):
                        fobj = open(filename, 'w')
                        if (not fobj.closed):
-                               fobj.write(str(self.text()))
+                               fobj.write(self.text().toUtf8())
                                fobj.flush()
                                fobj.close()
                                self.setModified(False)

Original issue reported on code.google.com by tuomas.t...@gmail.com on 11 Sep 2012 at 1:58

GoogleCodeExporter commented 9 years ago
Thanks tuomas.

Dang,
Can you mix the fix.
Probably you can explore alternatives in PyQt library ways of dealing with file?

Original comment by anil.om...@gmail.com on 17 Sep 2012 at 10:49

GoogleCodeExporter commented 9 years ago

Original comment by anil.om...@gmail.com on 17 Sep 2012 at 10:50

GoogleCodeExporter commented 9 years ago
I was worrying that what happens with some other encodings. But this seems to 
work for ASCII and UTF-8 because ASCII characters are subset of UTF-8. For 
example ISO-8859-15 it does not allow to open the file because it cannot decode 
file for utf-8.
So i hope that someone who knows the Python and QTScintilla knows more 
sophisticated solution.

Original comment by tuomas.t...@gmail.com on 18 Sep 2012 at 8:58

GoogleCodeExporter commented 9 years ago
This might of some interest 
http://lists.trolltech.com/qt-interest/2008-03/thread00233-0.html

Original comment by anil.om...@gmail.com on 22 Sep 2012 at 6:48

GoogleCodeExporter commented 9 years ago
Fixed as per patch

Original comment by anil.om...@gmail.com on 28 Sep 2012 at 8:58