HTML into clipboard via wx?

I want to be able to put html into the clipboard in a platform
independent way (it has to work on Windows, OS X and Linux).

Looking at the wx clipboard interface, I can make a composite
dataobject with two formats of text (acsii & html, which in my case
need to be different content, as the text version will have to have
links inline). Unfortunately wx.DF_HTML works only on non-unicode
builds for windows, so I only get the ascii version to work. :frowning:

I surely cannot be the only one with this requirement.

Can some kindly soul please point me to a platform independent way of
achieving this or 3 plattform dependent ways?

Paul

perzonae logo-tiny.JPG

ยทยทยท

โ€“
perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com

Paul Sijben wrote:

I want to be able to put html into the clipboard in a platform independent way (it has to work on Windows, OS X and Linux).

Looking at the wx clipboard interface, I can make a composite dataobject with two formats of text (acsii & html, which in my case need to be different content, as the text version will have to have links inline). Unfortunately wx.DF_HTML works only on non-unicode builds for windows, so I only get the ascii version to work. :frowning:

Please provide a small runnable sample for us to look at so we can be sure we are looking at the same problem you are.
http://wiki.wxpython.org/MakingSampleApps

ยทยทยท

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

Paul Sijben wrote:

I want to be able to put html into the clipboard in a platform independent way (it has to work on Windows, OS X and Linux).
Looking at the wx clipboard interface, I can make a composite dataobject with two formats of text (acsii & html, which in my case need to be different content, as the text version will have to have links inline). Unfortunately wx.DF_HTML works only on non-unicode builds for windows, so I only get the ascii version to work. :-(
Please provide a small runnable sample for us to look at so we can be sure we are looking at the same problem you are.

this is my code. However the limitation for wx.DF_HTML comes straight
out of the wxpython docs (and I double checked it with the wx docs.)

def FillClipBoard(self,evt=None,val=None):

    if val==None:

        val=self.result

    else:

        self.result=val

    wx.TheClipboard.Open()

    do = wx.TextDataObject()

    do.SetText(val['text'])

    co=wx.DataObjectComposite()

    ho=wx.TextDataObject()

    ho.SetFormat(wx.DataFormat(wx.DF_HTML))

    ho.SetText(val['html'])

    co.Add(ho)

    co.Add(do)

    wx.TheClipboard.SetData(co)

    wx.TheClipboard.Close()

perzonae logo-tiny.JPG

ยทยทยท

http://wiki.wxpython.org/MakingSampleApps

perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com

Paul Sijben wrote:

Robin Dunn wrote:

Paul Sijben wrote:
  

I want to be able to put html into the clipboard in a platform independent way (it has to work on Windows, OS X and Linux).

Looking at the wx clipboard interface, I can make a composite dataobject with two formats of text (acsii & html, which in my case need to be different content, as the text version will have to have links inline). Unfortunately wx.DF_HTML works only on non-unicode builds for windows, so I only get the ascii version to work. :frowning:
    
Please provide a small runnable sample for us to look at so we can be sure we are looking at the same problem you are.
MakingSampleApps - wxPyWiki

this is my code. However the limitation for wx.DF_HTML comes straight out of the wxpython docs (and I double checked it with the wx docs.)

I'm not sure what is going on with wx.DF_HTML, but MSDN says that it (CF_HTML actually, but they are the same IDs in wxMSW) has a format name of "HTML Format" so we can construct it using a custom data format. the tricky part is that MSDN says that the data provided for this data format needs to be in a form like this:

Version:0.9
StartHTML:71
EndHTML:160
StartFragment:130
EndFragment:150
StartSelection:130
EndSelection:150
<!DOCTYPE ...>
<HTML>
<BODY>
<!--StartFragment-->
<B>bold.</B> <I><B>This is bold italic.</B></I> <I>This</I>
<!--EndFragment-->
</BODY>
</HTML>

Using the ClipSpy program I verified that this is what is in one of the data objects that FireFox puts in the clipboard when you copy a text fragment from a web page.

I've attached a quick and dirty experiment that I did to test this by deriving a class from wx.PyDataObjectSimple. I have no idea if the other platforms use this same template format, or even the same data format name. (Probably not.) Hopefully this will give you enough to get started however. Try to find a tool like ClipSpy for Linux and Mac that displays the data format names and the data values of the objects on the clipboard, and then copy some text from a web browser and see what you get.

htmldataobj.py (2.8 KB)

ยทยทยท

--
Robin Dunn
Software Craftsman

Robin,

thanks very much for this great snippet of code.

Unfortunately it does not work for all paste operations. For some
reason it allows me to paste into Word but not into Thunderbird???

Do you have any clue as to why this would be the case?

Paul

Robin Dunn wrote:

perzonae logo-tiny.JPG

ยทยทยท

http://wiki.wxpython.org/MakingSampleApps

perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com

Paul Sijben wrote:

Robin,

thanks very much for this great snippet of code.

Unfortunately it does not work for all paste operations. For some reason it allows me to paste into Word but not into Thunderbird???

Thunderbird is probably expecting some other data format. Use ClipSpy and see what Tbird puts into the clipboard when you copy text from it, that will likely match what they are prepared to accept as well.

ยทยทยท

--
Robin Dunn
Software Craftsman

will do, thanks

Robin Dunn wrote:

perzonae logo-tiny.JPG

ยทยทยท

โ€“
perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com