I have a wxPython GUI with a wx.stc.StyledTextCtrl text editor. It is possible that its content contain some unicode characters such as Greek letters. I have noticed that StyledTextCtrl.SaveFile() method works only when the content has no unicode characters. Otherwise the saved file ends up being an empty file.
I tried calling StyledTextCtrl.SetCodePage(stc.STC_CP_UTF8) but it did not help either. So, I am not quite sure whether there is a bug in the StyledTextCtrl code, or that I am missing something. Any help is appreciated.
Saving code uses
wxConvCurrent
, so you could try setting it towxConvUTF8
to ensure that UTF-8 is used even when it's not the encoding of the current locale (which is never the case under Windows).Unfortunately I'm not sure if you can change
wxConvCurrent
from Python. If you can't, the simplest solution would probably be to just writewxStyledTextCtrl::GetValue()
to a file yourself instead of relying on itsSaveFile()
method. Don't forget to callSetSavePoint()
after saving successfully if you do this.