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.
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?
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.
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()
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. 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:
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.
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.