[request] want to put RTF-formated text to the clipboard - solution
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SikuliX |
In Progress
|
Medium
|
RaiMan |
Bug Description
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.
from java.io import *
def ClipboardPutRtf
cb_data = StringSelection
cb = Toolkit.
RTF_FLAVOR = DataFlavor(
p = (cb_data, RTF_FLAVOR)
cb.
if __name__ == '__main__' :
RTF_STRING = u"{\\rtf1\
ClipboardPu
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.
[error] --- Traceback --- error source first line: module ( function ) statement ##: main ( ClipboardPutRtf
[error] --- Traceback --- end --------------
Changed in sikuli: | |
milestone: | 2.0.0 → 2.1.0 |
Thanks for the solution:
Here is a codefix what doing what I need:
def putRTFStringToC lipboard( rtf_str) : datatransfer import StringSelection datatransfer import Clipboard tream getDefaultToolk it().getSystemC lipboard( ) tream(cb_ data) setContents( DataHandler( ba,"text/ rtf"), None)
from java.awt.
from java.awt.
from javax.activation import DataHandler
from java.awt import Toolkit
from java.lang import String
from java.nio import ByteBuffer
from java.lang import StringBuffer
from java.io import InputStream, ByteArrayInputS
cb = Toolkit.
cb_data = map(ord, rtf_str)
ba = ByteArrayInputS
cb.