I’m
migrating an application that was originally developed in Python 2 and wxPython 3.0.2 to Python 3 and wxPython 4.0.0. The last thing I get stuck with is the use of the XML format in RichTextCtrl to keep the layout
For backup, in python 2, I wrote this (where rtc is a RichTextCtrl and txt a string then saved in a database) :
stream = io.StringIO()
handler = wx.richtext.RichTextXMLHandler()
buffer = rtc.GetBuffer()
buffer.AddHandler(handler)
stream.write(txt)
stream.seek(0)
handler.LoadStream(buffer, stream)
With wxPython 4.0.0, this way does not work as RichTextXMLHandler has no longer methods "LoadStream" and "SaveStream". There are now methods "ImportXML" and "ExportXML" but I have not found any examples to understand how to use them.
Thank you in advance for your answer
Try LoadFile(buffer, stream) instead of LoadStream().
Scott
···
On Thu, 27 Apr 2017, Guillaume DURIAUD wrote:
I'm migrating an application that was originally developed in Python 2 and
wxPython 3.0.2 to Python 3 and wxPython 4.0.0. The last thing I get stuck
with is the use of the XML format in RichTextCtrl to keep the layout
For backup, in python 2, I wrote this (where rtc is a RichTextCtrl and txt
a string then saved in a database) :
import cStringIO as io handler = wx.richtext.RichTextXMLHandler() stream = io.StringIO() handler.SaveStream(rtc.GetBuffer(), stream) stream.seek(0) txt = stream.read()
For reading :
stream = io.StringIO() handler = wx.richtext.RichTextXMLHandler() buffer = rtc.GetBuffer() buffer.AddHandler(handler) stream.write(txt) stream.seek(0) handler.LoadStream(buffer, stream)
With wxPython 4.0.0, this way does not work as RichTextXMLHandler has no lo
nger methods "LoadStream" and "SaveStream". There are now methods "ImportXM
L" and "ExportXML" but I have not found any examples to understand how to u
se them.
Thank you in advance for your answer
április 27., csütörtök 17:04:52 UTC+2 időpontban Guillaume DURIAUD a következőt írta:
···
Hello,
I’m
migrating an application that was originally developed in Python 2 and wxPython 3.0.2 to Python 3 and wxPython 4.0.0. The last thing I get stuck with is the use of the XML format in RichTextCtrl to keep the layout
For backup, in python 2, I wrote this (where rtc is a RichTextCtrl and txt a string then saved in a database) :
With wxPython 4.0.0, this way does not work as RichTextXMLHandler has no longer methods “LoadStream” and “SaveStream”. There are now methods “ImportXML” and “ExportXML” but I have not found any examples to understand how to use them.