Search code examples
wxpythonrichtextbox

text from RichTextCtrl


I want to get the xml string from a rich text control into a string variable (to store in a database). I can save to file and then read it back out as a string, but there must be a better way (buffer?).

I've tried

  buffer = self.rtc.GetBuffer()

but how do you get the string from the buffer?

Can someone please help me. I've searched documentation and examples but can't find what I neeed.


Solution

  • This is a supplementary to the above:

    I have saved the xml as desired, but when I read it back I get an error:

    XML parsing error: 'no element found' at line 1
    

    My code is

    def OnLstStrategyDClick(self,e):
      index=e.GetSelection()
      self.txtStrategyID.SetValue(self.StrategyList[index][0])
      self.txtDescription.SetValue(self.StrategyList[index][1])
      #print self.StrategyList[index][2]
    
      out = StringIO()
      handler = wx.richtext.RichTextXMLHandler()
      buffer = self.txtBidStrategy.GetBuffer()
      buffer.AddHandler(handler)
      out.write(self.StrategyList[index][2])
      out.seek(0)
      handler.LoadStream(buffer, out)
      self.txtBidStrategy.Refresh()
    
      self.txtBidStrategy.SetValue(self.StrategyList[index][2])
    

    The xml code looks fine (well, it has been generated by the handler)