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
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)
def clearClipboard(self): try: with winUser.openClipboard(gui.mainFrame.Handle): winUser.emptyClipboard() # Translators: message presented when the clipboard content has been deleted. ui.message(_("Clipboard cleared")) except Exception as e: # Translators: message presented when the clipboard content cannot be deleted. ui.message(_("Clipboard not cleared")) log.debug("Cannot clear clipboard: %s" % e)
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
def clearClipboard(): with winUser.openClipboard(gui.mainFrame.Handle): winUser.emptyClipboard()