Discussion:
can't load xml file in wx python RichtextCtrl
Nagarajan Babu
2014-09-08 11:57:30 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Roberts
2014-09-08 17:23:32 UTC
Permalink
Post by Nagarajan Babu
Iam new to wxpython. iam trying to load xml in richtextctrl but it's
showing blank. iam using richtextctrl for display xml and images.
I want to make sure you understand that the XML handler for the
RichTextCtrl is not intended as a general-purpose XML renderer. The
only XML you can load is XML that has been previously saved from an
RTC. It has to follow the RTC DTD.

As an experiment, try doing
editor.AppendText( "This is some text" )
and instead of loading your content, try:
handler.SaveFile( rt_buffer, "lookatme.xml" )
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nagarajan Babu
2014-09-09 05:17:16 UTC
Permalink
I got it now. Thanks.
Post by Tim Roberts
Post by Nagarajan Babu
Iam new to wxpython. iam trying to load xml in richtextctrl but it's
showing blank. iam using richtextctrl for display xml and images.
I want to make sure you understand that the XML handler for the
RichTextCtrl is not intended as a general-purpose XML renderer. The
only XML you can load is XML that has been previously saved from an
RTC. It has to follow the RTC DTD.
As an experiment, try doing
editor.AppendText( "This is some text" )
handler.SaveFile( rt_buffer, "lookatme.xml" )
--
Providenza & Boekelheide, Inc.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...