I'm currently implementing paste from the clipboard in a wx.grid.Grid derived class.
All works fine except for pasting from Excel on a Mac, where the data string converted from the clipboard using a wx.TextDataObject has two '\n' characters separating rows instead of one.
Example code:
def Paste(self, mode = 0):
clipboard = wx.TextDataObject()
wx.TheClipboard.GetData(clipboard)
wx.TheClipboard.Close()
data = clipboard.GetText()
if data[-1] == "\n":
data = data[:-1]
print(repr(data))
for three rows containing 1,2,3 produces '1\n2\n3' normally, and '1\n\n2\n\n3' from Excel.
Current fix is a special paste command that splits the clipboard data string using "\n\n" instead of "\n", but I'd like to improve this by using automatic format detection instead of manual paste command choice.
The OSX clipboard viewer shows that the copy from Excel is RTF format. Is there a function for detecting RTF format clipboard in wxPython/normal Python?
Thanks!