0

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!

  • Have you looked at [os.linesep](https://docs.python.org/3/library/os.html#os.linesep)? – Psionman Feb 01 '23 at 17:15
  • I've checked os.linesep on MacOS, but that just reports a plain '\n', so no help. I think the origin of the problem is in the handling by wx.TextDataObject. There is also wx.RichTextBufferDataObject but I haven't managed to implement this yet, and it's likely not helpful, or overkill for this problem. – doctorafternoon Feb 02 '23 at 12:30

0 Answers0