← Back to team overview

sikuli-driver team mailing list archive

[Question #248307]: put RTF formated data into clipboard

 

New question #248307 on Sikuli:
https://answers.launchpad.net/sikuli/+question/248307

Hi all!

I need put the RTF formated string and "text/rtf" DataFlavor into clipboard . Here is code what I started:

from java.awt import Toolkit
from java.awt.datatransfer import Clipboard, StringSelection, DataFlavor, UnsupportedFlavorException
from java.io import *

def ClipboardPutRtfString(rtf_str):
    cb_data = StringSelection(rtf_str)
    cb = Toolkit.getDefaultToolkit().getSystemClipboard()
    RTF_FLAVOR = DataFlavor("text/rtf", "Rich Text Format")
    p = (cb_data, RTF_FLAVOR)
    cb.setContents(p, None) 
if __name__ == '__main__' :
    RTF_STRING = u"{\\rtf1\\ansi\\deff0\r\n{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;}\r\nThis line is the default color\\line\r\n\\cf2\r\nThis line is красная\\line\r\n\\cf1\r\nThis line is the default color\r\n}\r\n}"
    ClipboardPutRtfString(RTF_STRING)

But now I'm sticked with how prepare transferable p object in Jython to pass it to setContents method, because my example gets error:

[error] TypeError ( setContents(): 1st arg can't be coerced to java.awt.datatransfer.Transferable )
[error] --- Traceback --- error source first line: module ( function ) statement ##: main ( ClipboardPutRtfString ) cb.setContents(p, None)
[error] --- Traceback --- end --------------

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.