Doc for clipboard

This commit is contained in:
El Mau 2022-03-03 23:45:19 -06:00
parent 6bfa41b43c
commit 899fb0112f
3 changed files with 64 additions and 2 deletions

View File

@ -79,6 +79,24 @@ You can call any `dispatch command`_ used only if property or method no exists i
Method automatically add `.uno:` Method automatically add `.uno:`
ClipBoard
---------
* Set text in clipboard
.. code-block:: python
app.clipboard.set('My Text')
* Get content of clipboard
.. code-block:: python
content = app.clipboard.content
app.debug(content)
Disable or enabled commands Disable or enabled commands
--------------------------- ---------------------------

View File

@ -40,6 +40,7 @@
.. autosummary:: .. autosummary::
ClipBoard
Color Color
Config Config
Dates Dates

View File

@ -64,6 +64,7 @@ import unohelper
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
from com.sun.star.awt.MessageBoxResults import YES from com.sun.star.awt.MessageBoxResults import YES
from com.sun.star.beans import PropertyValue, NamedValue from com.sun.star.beans import PropertyValue, NamedValue
from com.sun.star.datatransfer import XTransferable, DataFlavor
from com.sun.star.io import IOException, XOutputStream from com.sun.star.io import IOException, XOutputStream
from com.sun.star.ui.dialogs import TemplateDescription from com.sun.star.ui.dialogs import TemplateDescription
@ -1922,6 +1923,47 @@ class Color(object):
COLOR_ON_FOCUS = Color()('LightYellow') COLOR_ON_FOCUS = Color()('LightYellow')
class ClipBoard(object):
SERVICE = 'com.sun.star.datatransfer.clipboard.SystemClipboard'
CLIPBOARD_FORMAT_TEXT = 'text/plain;charset=utf-16'
class TextTransferable(unohelper.Base, XTransferable):
def __init__(self, text):
df = DataFlavor()
df.MimeType = ClipBoard.CLIPBOARD_FORMAT_TEXT
df.HumanPresentableName = 'encoded text utf-16'
self.flavors = (df,)
self._data = text
def getTransferData(self, flavor):
return self._data
def getTransferDataFlavors(self):
return self.flavors
@classmethod
def set(cls, value):
ts = cls.TextTransferable(value)
sc = create_instance(cls.SERVICE)
sc.setContents(ts, None)
return
@classproperty
def contents(cls):
df = None
text = ''
sc = create_instance(cls.SERVICE)
transferable = sc.getContents()
data = transferable.getTransferDataFlavors()
for df in data:
if df.MimeType == cls.CLIPBOARD_FORMAT_TEXT:
break
if df:
text = transferable.getTransferData(df)
return text
class IOStream(object): class IOStream(object):
"""Classe for input/output stream""" """Classe for input/output stream"""
@ -2025,12 +2067,12 @@ class LOMain():
""" """
return cls._set_app_command(command, False) return cls._set_app_command(command, False)
# ~ @classproperty @classproperty
def cmd(cls): def cmd(cls):
"""Disable or enable commands""" """Disable or enable commands"""
return cls._commands return cls._commands
# ~ @classproperty @classproperty
def desktop(cls): def desktop(cls):
"""Create desktop instance """Create desktop instance
@ -2567,6 +2609,7 @@ def __getattr__(name):
'email': Email, 'email': Email,
'color': Color(), 'color': Color(),
'io': IOStream, 'io': IOStream,
'clipboard': ClipBoard,
'lo': LOMain, 'lo': LOMain,
'command': LOMain.cmd, 'command': LOMain.cmd,
'docs': LODocuments(), 'docs': LODocuments(),