예제 #1
0
def copyToClip(text: str, notify: Optional[bool] = False) -> bool:
    """Copies the given text to the windows clipboard.
	@returns: True if it succeeds, False otherwise.
	@param text: the text which will be copied to the clipboard
	@param notify: whether to emit a confirmation message
	"""
    if not isinstance(text, str) or len(text) == 0:
        return False
    import gui
    try:
        with winUser.openClipboard(gui.mainFrame.Handle):
            winUser.emptyClipboard()
            winUser.setClipboardData(winUser.CF_UNICODETEXT, text)
        got = getClipData()
    except OSError:
        if notify:
            ui.reportTextCopiedToClipboard()  # No argument reports a failure.
        return False
    if got == text:
        if notify:
            ui.reportTextCopiedToClipboard(text)
        return True
    if notify:
        ui.reportTextCopiedToClipboard()  # No argument reports a failure.
    return False
예제 #2
0
 def copyToClip(text):
     if not isinstance(text, str):
         raise TypeError("str required")
     import gui
     with openClipboard(gui.mainFrame.Handle):
         emptyClipboard()
         if text:
             setClipboardData(CF_UNICODETEXT, text)
예제 #3
0
파일: api.py 프로젝트: albaye/nvda
def copyToClip(text):
    """Copies the given text to the windows clipboard.
@returns: True if it succeeds, False otherwise.
@rtype: boolean
@param text: the text which will be copied to the clipboard
@type text: string
"""
    if not isinstance(text, str) or len(text) == 0:
        return False
    import gui
    with winUser.openClipboard(gui.mainFrame.Handle):
        winUser.emptyClipboard()
        winUser.setClipboardData(winUser.CF_UNICODETEXT, text)
    got = getClipData()
    return got == text