1

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.

happyhuman
  • 1,541
  • 1
  • 16
  • 30
  • It is very possible that there is a bug. I did not test this one (I would just get the text and save it myself), but I got problems with methods needing position in text like `StartStyling`. It counts bytes instead of characters. Imagine the mess with UTF-8 text. – Fenikso Dec 12 '13 at 07:45

1 Answers1

0

Saving code uses wxConvCurrent, so you could try setting it to wxConvUTF8 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 write wxStyledTextCtrl::GetValue() to a file yourself instead of relying on its SaveFile() method. Don't forget to call SetSavePoint() after saving successfully if you do this.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • Thanks for your helpful answer. I decided to write my own Save/Load methods, and calling SetSavePoint() after both those calls made it all work at the end. – happyhuman Dec 12 '13 at 19:05