pythonxmlwxpythonrichtextctrl

can't load xml file in wx python RichtextCtrl


iam new to wxpython. iam trying to load xml in richtextctrl but it's showing blank. iam using richtextctrl for display xml and images.

class TestFrame(wx.Frame):
 def __init__(self, parent):
    wx.Frame.__init__(self, parent, -1, "A Grid", size=(500, 300))
    panel = wx.Panel(self, -1)


 self.__editor = editor = self.rtc = rt.RichTextCtrl(self, wx.ID_ANY, pos=wx.DefaultPosition, size=(390, 388), style=0);

    bsizer = wx.BoxSizer()
    bsizer.Add(editor, 1, wx.EXPAND)
    self.SetSizerAndFit(bsizer)

    self.rtc.Freeze()

    xml_file = open("E:/books.xml", "r")
    xml = xml_file.read()
    xml_file.close()       

    handler = rt.RichTextXMLHandler()
    handler.SetFlags(rt.RICHTEXT_HANDLER_INCLUDE_STYLESHEET)

    rt_buffer = self.rtc.GetBuffer()
    #rt_buffer.AddHandler(handler)
    output = StringIO(xml);    

    handler.LoadStream(rt_buffer,  output)  

    self.rtc.Refresh()

    self.rtc.Thaw()

app = wx.App()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()

and i tried following method also. but still no result.

    self.rtc.GetBuffer().AddHandler(rt.RichTextXMLHandler())        
    stream = StringIO(xml);
    rt_buffer = self.rtc.GetBuffer()
    rt_buffer.LoadStream(stream, rt.RICHTEXT_TYPE_XML)

please tell me what is missing here.


Solution

  • The RichTextCtrl uses its own XML format according to the documentation. That XML is used for styling text. This widget is not for viewing regular XML. For that, I would recommend just using a regular wx.TextCtrl.