def _cut(event): """ Cut selection. ('x' is not an operator.) """ clipboard_data = event.current_buffer.cut_selection() klembord.set_text(clipboard_data.text)
def set_clipboard_content(content, *, rich=False): """ 对klembord剪切板的功能做略微的简化 """ from bs4 import BeautifulSoup import klembord if rich: klembord.set_with_rich_text( BeautifulSoup(content, 'lxml').text, content) else: klembord.set_text(content)
def wrapper(*args, **kwargs): # 1 运行函数获得结果 s = func(*args, **kwargs) # 2 复制到剪切板 if copy: if rtype == 'text' and isinstance(s, str): klembord.set_text(s) elif rtype == 'html' and isinstance(s, str): s0 = BeautifulSoup(s, 'lxml').text klembord.set_with_rich_text(s0, s) elif rtype == 'dict' and isinstance(s, dict): klembord.set(s) # 3 输出 if paste: pyautogui.hotkey('ctrl', 'v') # 目前来看就这个方法最靠谱 if typing: type_text(s) return s
def _yank(event, text_object): """ Yank operator. (Copy text.) """ _, clipboard_data = text_object.cut(event.current_buffer) klembord.set_text(clipboard_data.text)
def _yank_line(event): """ Yank the whole line. """ text = "\n".join(event.current_buffer.document.lines_from_current[: event.arg]) klembord.set_text(text)
def copyText(text): klembord.set_text(text)