I do not generally use the API using Python so I cannot comment on using Python.
I have also not used headless mode so I cannot comment on what is and is not available other than knowing that dispatches are not available.
Finally, I have done almost nothing using the clipboard, but...
First note that the clipboard should have content of different varieties. I assume that you are aware of this because you have a line as follows:
copy_with_format(value, 'text/html')
And if I look at the clipboard I see this as an available type
Dim sClipName As String
Dim oClip As Object
Dim oFlavors As Variant
Dim oFlavor As Variant
Dim i as Integer
Dim s as String
sClipName = "com.sun.star.datatransfer.clipboard.SystemClipboard"
oClip = createUnoService(sClipName)
oFlavors = oClip.getContents().getTransferDataFlavors()
s = ""
For i = LBound(oFlavors) To UBound(oFlavors)
oFlavor = oFlavors(i)
s = s & i & " : " & oFlavor.MimeType
s = s & CHR$(10)
Next
MsgBox s
I see that method defined in this code here:
https://github.com/Probesys/lotemplate/blob/html_formatting/lotemplate/utils.py
I see that you open a pipe.
I did some experiments and I am extracting the actual HTML. I assume that this is not really what you want, but this is how I extract it and display it. I was simply playing around with it out of curiousity.
Dim sClipName As String
Dim oClip As Object
Dim oFlavors As Variant
Dim oFlavor As Variant
Dim i as Integer
Dim idx as Integer
Dim s as String
sClipName = "com.sun.star.datatransfer.clipboard.SystemClipboard"
oClip = createUnoService(sClipName)
oFlavors = oClip.getContents().getTransferDataFlavors()
s = ""
idx = -1
For i = LBound(oFlavors) To UBound(oFlavors)
oFlavor = oFlavors(i)
s = s & i & " : " & oFlavor.MimeType
If oFlavor.MimeType = "text/html" Then
idx = i
End If
s = s & CHR$(10)
Next
'MsgBox s
If idx < 0 Then
Print "text/html mime type not found"
Exit Sub
End If
' Now print the actual HMTL as a string!
Dim oData As Variant
oData = oClip.getContents().getTransferData(oFlavors(idx))
s = ""
For i = LBound(oData) To UBound(oData)
s = s & CHR$(oData(i))
Next
MsgBox s
If I kept going, then I would attempt to then use the transferable content directly, which is obtained from oClip.getContents() I believe. But, one of the real questions is.... Does the clipboard have the contents shown in the correct format? I assume it does.
So, perhaps this helps a little anyway.
Andrew Pitonyak
On Sunday, March 26, 2023 06:06 EDT, Zorg <zorg@xxxxxxxxxxxx> wrote:
Hello
Hope some can help me here
Here is my problem
We are developing our software using the uno api python
We re trying to to copy a string formatted in html in a libreoffice odt
We manage to do it but using dispatcher
The problem is that dispatcher not working in headless mode so il force us to use a xserver (xvfb) et Xclip.
It work but it's far from being optimized.
here is the code https://github.com/Probesys/lotemplate/blob/html_formatting/lotemplate/classes.py line 349-355
We have try using XTransferable but without any success.
Thanks in advance for your help
Sorg