RichTextCtrl Dummy Question :-D

Hi All,

    I am thinking of replacing in my database-based application the
StyledTextCtrl with RichTextCtrl, mostly to be able to paste images,
tables etc... My problem is, the data for RichTextCtrl is stored
inside the database, so I cannot use LoadFile on it. I also don't
think I could use SetValue() or AppendText(), as these methods do not
hold formatting informations about the saved text. Is there a way in
which I could load the text, formatting, images and so on from the
database and assign it to the RichTextCtrl?

Sorry for the dummy question, I have never used RichTextCtrl :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

    I am thinking of replacing in my database-based
application the StyledTextCtrl with RichTextCtrl, mostly to
be able to paste images, tables etc... My problem is, the
data for RichTextCtrl is stored inside the database, so I
cannot use LoadFile on it. I also don't think I could use
SetValue() or AppendText(), as these methods do not hold
formatting informations about the saved text. Is there a way
in which I could load the text, formatting, images and so on
from the database and assign it to the RichTextCtrl?

Sorry for the dummy question, I have never used RichTextCtrl :smiley:

Forgive me if I send you in the wrong direction - what I have done in
the past is use the base64 module to encode the original file to a
cStringIO stream. You will end up with a long stream of characters
(similar to email attachements and mime encoding) that are quite safe
for storing in the db.
To retreive and load the file, read the string back from the db, decode
it and store it as a temp file then load the temp file into the
RichTextCtrl. When done editing, reverse the process.

Of course you will want to remove the tempfile on exit too !

I am not familiar with the controls mentioned, but hope that helps.

Hope that helps.

G.

Andrea Gavana wrote:

Hi All,

    I am thinking of replacing in my database-based application the
StyledTextCtrl with RichTextCtrl, mostly to be able to paste images,
tables etc... My problem is, the data for RichTextCtrl is stored
inside the database, so I cannot use LoadFile on it. I also don't
think I could use SetValue() or AppendText(), as these methods do not
hold formatting informations about the saved text. Is there a way in
which I could load the text, formatting, images and so on from the
database and assign it to the RichTextCtrl?

Take a look at OnFileViewHTML in the demo, it saves the contents of the RTC to a StringIO directly from the RichTextHTMLHandler, and then lets you view it as from a HtmlWindow. I think you can probably do something similar for saving to and loading from a StringIO using the RichTextXMLHandler. It already saves the image data in the xml, so that shoudl already be taken care of, you just need to be able to deal with using the StringIO stream to load and save.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!