from cStringIO import StringIO
# initialize a string stream with XML data
stream = StringIO( myXmlString )
# create an XML handler
handler = wx.richtext.RichTextXMLHandler()
# load the stream into the control's buffer
handler.LoadStream( myRichTextCtrl.GetBuffer(), stream )
# refresh the control
myRichTextCtrl.Refresh()
以及以特定格式获取RichTextCtrl的内容:
^{pr2}$
或者,可以直接通过缓冲区加载流。请注意,必须已经存在适当的处理程序来解释数据:
# add the handler (where you create the control)
myRichTextCtrl.GetBuffer().AddHandler(wx.richtext.RichTextXMLHandler())
stream = StringIO( myXmlString )
buffer = self.myRichTextCtrl.GetBuffer()
# you have to specify the type of data to load and the control
# must already have an instance of the handler to parse it
buffer.LoadStream(stream, wx.richtext.RICHTEXT_TYPE_XML)
myRichTextCtrl.Refresh()
要绕过
RichTextCtrl.LoadFile()
,必须创建一个基于RichTextFileHandler
的类,并使用其LoadStream()
方法直接写入RichTextCtrl缓冲区。在例如:
以及以特定格式获取
^{pr2}$RichTextCtrl
的内容:或者,可以直接通过缓冲区加载流。请注意,必须已经存在适当的处理程序来解释数据:
相关问题 更多 >
编程相关推荐