after saving from richtxtctrl to db, how do I go the other way ?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

after saving from richtxtctrl to db, how do I go the other way ?

asaag

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


out = BytesIO() handler = wx.richtext.RichTextXMLHandler() rt_buffer = self.text.GetBuffer() handler.SaveFile(rt_buffer, out) self.xml_content = out.getvalue() cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content)) self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

Marcos del Amo
I do it like this:

conn = psycopg2.connect(conn_string) # user, password and such
cur = conn.cursor()
cur.execute(query)
rows = cur.fetchall() # We have the rows returned from the db
if rows: # for every parameter used
msg = "Please wait while we process your request..."
busyDlg = wx.BusyInfo(msg)
for r in rows:
 # here you would insert it in the rictextctrl

Hope this  helps

El martes, 29 de agosto de 2017, 4:54:09 (UTC+2), dennis spera escribió:

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


out = BytesIO() handler = wx.richtext.RichTextXMLHandler() rt_buffer = self.text.GetBuffer() handler.SaveFile(rt_buffer, out) self.xml_content = out.getvalue() cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content)) self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

asaag
In reply to this post by asaag
thanks, the issue is that when I retrieve the xml from the database and
insert it into the richtextctrl it is just inserting the text of the xml like
this:

<?xml version="1.0" encoding="UTF-8"?>

<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">

<paragraphlayout textcolor="#000000" fontpointsize="9" fontfamily="70" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Segoe UI" alignment="1" parspacingafter="10" parspacingbefore="0" linespacing="10" margin-left="5,4098" margin-right="5,4098" margin-top="5,4098" margin-bottom="5,4098">

<paragraph>

<text>aaa</text>

</paragraph>

</paragraphlayout>

</richtext>


it is not rendering the attributes like setting font, etc

I want it restored like it was when the text was changed in

the richtextctrl



On Mon, Aug 28, 2017 at 9:00 PM, dennis spera <[hidden email]> wrote:

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


out = BytesIO() handler = wx.richtext.RichTextXMLHandler() rt_buffer = self.text.GetBuffer() handler.SaveFile(rt_buffer, out) self.xml_content = out.getvalue() cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content)) self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Dennis Spera
Oracle 12c DBA

 



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

asaag
I am using wxpython 4.x, I think the code you posted will only
work for 3.x from what I have read or are you using 4.x as well ?

On Tue, Aug 29, 2017 at 12:55 PM, David Woods <[hidden email]> wrote:

I use the RichTextXMLHandler that's included in the wx.richtext module:


try:

     # We need to setup a StringIO object to emulate a file

     stream = cStringIO.StringIO(text)

     # Create an XML Handler

     handler = wx.richtext.RichTextXMLHandler()

     # Load the XML text via the XML Handler.

     # Note that for XML, the BUFFER is passed.

     handler.LoadStream(self.GetBuffer(), stream)

     # exception handling

except:

     print "XML Handler Load failed"

     print

     print sys.exc_info()[0], sys.exc_info()[1]

     print traceback.print_exc()

I've also written RTF and DOCx parsers for the RichTextCtrl which work well enough for my needs.

David



On 08/29/2017 11:50 AM, dennis spera wrote:
thanks, the issue is that when I retrieve the xml from the database and
insert it into the richtextctrl it is just inserting the text of the xml like
this:

<?xml version="1.0" encoding="UTF-8"?>

<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">

<paragraphlayout textcolor="#000000" fontpointsize="9" fontfamily="70" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Segoe UI" alignment="1" parspacingafter="10" parspacingbefore="0" linespacing="10" margin-left="5,4098" margin-right="5,4098" margin-top="5,4098" margin-bottom="5,4098">

<paragraph>

<text>aaa</text>

</paragraph>

</paragraphlayout>

</richtext>


it is not rendering the attributes like setting font, etc

I want it restored like it was when the text was changed in

the richtextctrl



On Mon, Aug 28, 2017 at 9:00 PM, dennis spera <[hidden email]> wrote:

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


        out = BytesIO()
        handler = wx.richtext.RichTextXMLHandler()
        rt_buffer = self.text.GetBuffer()
        handler.SaveFile(rt_buffer, out)
        self.xml_content = out.getvalue()
        cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content))
        self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Dennis Spera
Oracle 12c DBA

 



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.




--

Dennis Spera
Oracle 12c DBA

 



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

Marcos del Amo
 I'm using 2.7 so as you said my code my not work for 4.x.
Have you tried to extract the tags from the xml and using setFont and the like to use the attributes again?
You could easily use a regular expresion to search for fontpointsize=9 and use SetFontSize(9), textcolor"#000000" -> SetForegroundText(000000).

I have not used an XMLControl but this is how I would do it for a wx.RichTextControl.

El martes, 29 de agosto de 2017, 19:05:42 (UTC+2), dennis spera escribió:
I am using wxpython 4.x, I think the code you posted will only
work for 3.x from what I have read or are you using 4.x as well ?

On Tue, Aug 29, 2017 at 12:55 PM, David Woods <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="e8MWli44AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">tran...@...> wrote:

I use the RichTextXMLHandler that's included in the wx.richtext module:


try:

     # We need to setup a StringIO object to emulate a file

     stream = cStringIO.StringIO(text)

     # Create an XML Handler

     handler = wx.richtext.RichTextXMLHandler()

     # Load the XML text via the XML Handler.

     # Note that for XML, the BUFFER is passed.

     handler.LoadStream(self.GetBuffer(), stream)

     # exception handling

except:

     print "XML Handler Load failed"

     print

     print sys.exc_info()[0], sys.exc_info()[1]

     print traceback.print_exc()

I've also written RTF and DOCx parsers for the RichTextCtrl which work well enough for my needs.

David



On 08/29/2017 11:50 AM, dennis spera wrote:
thanks, the issue is that when I retrieve the xml from the database and
insert it into the richtextctrl it is just inserting the text of the xml like
this:

<?xml version="1.0" encoding="UTF-8"?>

<richtext version="1.0.0.0" xmlns="<a href="http://www.wxwidgets.org" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.wxwidgets.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEk7zI6GT6kOv2QEYBJ6cGZp8v0ZA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.wxwidgets.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEk7zI6GT6kOv2QEYBJ6cGZp8v0ZA&#39;;return true;">http://www.wxwidgets.org">

<paragraphlayout textcolor="#000000" fontpointsize="9" fontfamily="70" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Segoe UI" alignment="1" parspacingafter="10" parspacingbefore="0" linespacing="10" margin-left="5,4098" margin-right="5,4098" margin-top="5,4098" margin-bottom="5,4098">

<paragraph>

<text>aaa</text>

</paragraph>

</paragraphlayout>

</richtext>


it is not rendering the attributes like setting font, etc

I want it restored like it was when the text was changed in

the richtextctrl



On Mon, Aug 28, 2017 at 9:00 PM, dennis spera <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="e8MWli44AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dennis...@...> wrote:

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


        out = BytesIO()
        handler = wx.richtext.RichTextXMLHandler()
        rt_buffer = self.text.GetBuffer()
        handler.SaveFile(rt_buffer, out)
        self.xml_content = out.getvalue()
        cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content))
        self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e8MWli44AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--

Dennis Spera
<a href="http://www.linkedin.com/pub/dennis-spera/34/810/1a8/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;">Oracle 12c DBA

  <a href="http://www.linkedin.com/pub/dennis-spera/34/810/1a8/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;">



--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e8MWli44AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.




--

Dennis Spera
<a href="http://www.linkedin.com/pub/dennis-spera/34/810/1a8/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;">Oracle 12c DBA

  <a href="http://www.linkedin.com/pub/dennis-spera/34/810/1a8/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdennis-spera%2F34%2F810%2F1a8%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa8zqjf8IMz3Jcb5xtBcC_K32e9w&#39;;return true;">



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

GadgetSteve


On 08/09/2017 07:38, Marcos del Amo wrote:
>   I'm using 2.7 so as you said my code my not work for 4.x.
> Have you tried to extract the tags from the xml and using setFont and
> the like to use the attributes again?

Just to let you know that wxPython 4 (Sphinx) works just fine under
python 2.7 for me at least - just pip install wxpython does the trick.

There are some areas where there were things that you could get away
with in 3 now cause asserts but in the vast majority of cases once they
are resolved for wxpython 4 they still work or work better under 3.

Of course it is well worth transitioning to wxPython 4 as it also works
with python 3 and 2020 is looming.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
http://www.avg.com

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: after saving from richtxtctrl to db, how do I go the other way ?

asaag
In reply to this post by Marcos del Amo
No, I guess I thought that was a method for automating
the applying the tags. But what you say is a good
idea and I think I will take that approach. Thanks.

On Fri, Sep 8, 2017 at 2:38 AM, Marcos del Amo <[hidden email]> wrote:
 I'm using 2.7 so as you said my code my not work for 4.x.
Have you tried to extract the tags from the xml and using setFont and the like to use the attributes again?
You could easily use a regular expresion to search for fontpointsize=9 and use SetFontSize(9), textcolor"#000000" -> SetForegroundText(000000).

I have not used an XMLControl but this is how I would do it for a wx.RichTextControl.

El martes, 29 de agosto de 2017, 19:05:42 (UTC+2), dennis spera escribió:
I am using wxpython 4.x, I think the code you posted will only
work for 3.x from what I have read or are you using 4.x as well ?

On Tue, Aug 29, 2017 at 12:55 PM, David Woods <[hidden email]> wrote:

I use the RichTextXMLHandler that's included in the wx.richtext module:


try:

     # We need to setup a StringIO object to emulate a file

     stream = cStringIO.StringIO(text)

     # Create an XML Handler

     handler = wx.richtext.RichTextXMLHandler()

     # Load the XML text via the XML Handler.

     # Note that for XML, the BUFFER is passed.

     handler.LoadStream(self.GetBuffer(), stream)

     # exception handling

except:

     print "XML Handler Load failed"

     print

     print sys.exc_info()[0], sys.exc_info()[1]

     print traceback.print_exc()

I've also written RTF and DOCx parsers for the RichTextCtrl which work well enough for my needs.

David



On 08/29/2017 11:50 AM, dennis spera wrote:
thanks, the issue is that when I retrieve the xml from the database and
insert it into the richtextctrl it is just inserting the text of the xml like
this:

<?xml version="1.0" encoding="UTF-8"?>

<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">

<paragraphlayout textcolor="#000000" fontpointsize="9" fontfamily="70" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Segoe UI" alignment="1" parspacingafter="10" parspacingbefore="0" linespacing="10" margin-left="5,4098" margin-right="5,4098" margin-top="5,4098" margin-bottom="5,4098">

<paragraph>

<text>aaa</text>

</paragraph>

</paragraphlayout>

</richtext>


it is not rendering the attributes like setting font, etc

I want it restored like it was when the text was changed in

the richtextctrl



On Mon, Aug 28, 2017 at 9:00 PM, dennis spera <[hidden email]> wrote:

the following loads contents of richtextctrl (text) into db, when I query db it looks correct.


        out = BytesIO()
        handler = wx.richtext.RichTextXMLHandler()
        rt_buffer = self.text.GetBuffer()
        handler.SaveFile(rt_buffer, out)
        self.xml_content = out.getvalue()
        cx.execute("insert into notes (key, data) values (?, ?)", (key, self.xml_content))
        self.conn.commit()


question how do I get it back from db and load into richtextctrl ?

--
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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Dennis Spera
Oracle 12c DBA

 



--
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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




--

Dennis Spera
Oracle 12c DBA

 



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Dennis Spera
Oracle 12c DBA

 



--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.