views:

47

answers:

1

Hello,

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?

A: 

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())
olarva
Changed to out.getvalue() but I have now "TypeError: Expected wx.InputStream or Python file-like object."
wxpydon