wxPython - How can I display a html formatted string in wx.RichTextCtrl
I'm trying to display some string (html formatted) in a Richtext Ctrl. In my cod开发者_运维问答e I tried to use it this way (self.txtmain is the RichTextCtrl):
out = StringIO()
htmlhandler = rt.RichTextHTMLHandler()
buffer = self.txtmain.GetBuffer()
buffer.AddHandler(htmlhandler)
out.write(string)
out.seek(0)
htmlhandler.LoadStream(buffer, out)
self.txtmain.Refresh()
No errors are issued, but the RichTextCtrl windows is not updated. What am I missing here?
Take a look in "wx.Layout()", to update window/widget.
In certain cases i use "wx.Layout()" to redraw entire window, after add an item
for example, when i hide one and show another widget in same place...
in this case, self.Layout(), after self.txtmain.Refresh()..
out = StringIO()
htmlhandler = rt.RichTextHTMLHandler()
buffer = self.txtmain.GetBuffer()
buffer.AddHandler(htmlhandler)
out.write(string)
out.seek(0)
htmlhandler.LoadStream(buffer, out)
self.txtmain.Refresh()
self.Layout()
But, i not sure it'd work in you case...
and to retrieve a content from a StringIO() must use getvalue()
htmlhandler.LoadStream(buffer, out)
to
htmlhandler.LoadStream(buffer, out.getvalue())
精彩评论