1

I'm trying to display some string (html formatted) in a Richtext Ctrl. In my code 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?

wxpydon
  • 61
  • 1
  • 6
  • check result of `htmlhandler.LoadStream(buffer, out)`, false means it failed (not that I knew why, still working on that) – Piotr Kamoda Nov 08 '15 at 17:30

1 Answers1

0

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())
Lauro Oliveira
  • 2,362
  • 1
  • 18
  • 12
  • Changed to out.getvalue() but I have now "TypeError: Expected wx.InputStream or Python file-like object." – wxpydon Jun 15 '10 at 08:20