Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

wx.stc.StyledTextCtrl.SaveFile and LoadFile uses inconsistent encoding

Open komoto48g opened this issue 3 years ago • 2 comments

Operating system: Windows 10 wxPython version & source: 4.1.1 (pypi) and 4.1.2a1.dev* Python version & source: 3.8.6, 3.9.9, 3.10.4

Description of the problem: wx.stc.StyledTextCtrl.SaveFile seems to save the text with platform-dependent encoding (e.g., sjis in Japanese Windows 10), but LoadFile loads with 'utf-8', which results in text garbling.

Code Example (click to expand)
import sys
import wx
import wx.stc

print("Python {}".format(sys.version))
print("wxPython {}".format(wx.version()))

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        ed = wx.stc.StyledTextCtrl(self)
        
        ed.Text = "こんにちは wxPython!" # saying 'Hello' in Japanese
        
        ed.SaveFile('temp.txt') # saved as sjis (windows)
        ed.LoadFile('temp.txt') # loaded as utf-8

if __name__ == "__main__":
    app = wx.App()
    frm = Frame(None)
    frm.Show()
    app.MainLoop()

issue-stc-encoding

komoto48g avatar May 24 '22 03:05 komoto48g

This issue has been mentioned on Discuss wxPython. There might be relevant details there:

https://discuss.wxpython.org/t/save-file-in-stc-and-utf-8/36034/2

RobinD42 avatar Jun 26 '22 11:06 RobinD42

Yes Even by change codepage have a same problem . the function do not have an argument about encoding or codepage I run this code with this detail: Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] wxPython 4.1.1 msw (phoenix) wxWidgets 3.1.5 in Windows 10

Srcfount avatar Jun 26 '22 21:06 Srcfount