我们从Python开源项目中,提取了以下42个代码示例,用于说明如何使用pyperclip.paste()。
def copy_data(self, hCtrl, key=0): # background mode "?CVirtualGridCtrl|Custom<n>??????????????????" if key: self.switch_tab(self.two_way, key) # ?????('W')???('E')???('R') start = time.time() print("??????????????...") # ?????????????3?...orz for i in range(10): time.sleep(0.3) op.SendMessageW(hCtrl, MSG['WM_COMMAND'], MSG['COPY_DATA'], NODE['FORM'][-1]) ret = pyperclip.paste().splitlines() if len(ret) > 1: break temp = (x.split('\t') for x in ret) header = next(temp) if '????' in header: header.insert(header.index('????'), '??') header.remove('????') print('IT TAKE {} SECONDS TO GET REAL-TIME DATA'.format(time.time() - start)) return tuple(dict(zip(header, x)) for x in temp)
def twitter_tweet(self): print("1. write tweet") print("2. copy from clipboard") if six.PY2: choice = raw_input('Enter choice:') else: choice = input('Enter choice:') if int(choice) == 1: if six.PY2: tweet = raw_input('Enter tweet here:') else: tweet = input('Enter tweet here:') else: tweet = pyperclip.paste() driver = twitter_login(self) post_box = driver.find_element_by_id('tweet-box-home-timeline') post_box.send_keys(tweet) submit = driver.find_element_by_css_selector( 'button.tweet-action.EdgeButton.EdgeButton--primary.js-tweet-btn') submit.click() print("Posted") return driver
def get_paste_buffer(): """Get the contents of the clipboard / paste buffer. :return: str - contents of the clipboard """ pb_str = pyperclip.paste() # If value returned from the clipboard is unicode and this is Python 2, convert to a "normal" Python 2 string first if six.PY2 and not isinstance(pb_str, str): import unicodedata pb_str = unicodedata.normalize('NFKD', pb_str).encode('ascii', 'ignore') return pb_str
def write_to_paste_buffer(txt): """Copy text to the clipboard / paste buffer. :param txt: str - text to copy to the clipboard """ pyperclip.copy(txt)
def replace_with_file_contents(fname): """Action to perform when successfully matching parse element definition for inputFrom parser. :param fname: str - filename :return: str - contents of file "fname" """ try: with open(os.path.expanduser(fname[0])) as source_file: result = source_file.read() except IOError: result = '< %s' % fname[0] # wasn't a file after all # TODO: IF pyparsing input parser logic gets fixed to support empty file, add support to get from paste buffer return result
def copy(): """ Returns the current text on clipboard. """ data = pyperclip.paste() ## before using pyperclip # if os.name == "posix": # p = subprocess.Popen(["xsel", "-bo"], stdout=subprocess.PIPE) # data = p.communicate()[0].decode("utf-8") # elif os.name == "nt": # data = None # else: # print("We don't yet support %s Operating System." % os.name) # exit() return data
def upload(username, password): """ Sends the copied text to server. """ payload = {"text": copy(), "device": ""} res = requests.post( server_url+"copy-paste/", data = payload, auth = (username, password) ) if res.status_code == 200: print("Succeses! Copied to Cloud-Clipboard.") else: print("Error: ", res.text)
def paste(data): """ Copies 'data' to local clipboard which enables pasting. """ # p = subprocess.Popen(["xsel", "-bi"], stdout=subprocess.PIPE, # stdin=subprocess.PIPE) # p = p.communicate(data.encode("utf-8")) # if p[1] is not None: # print("Error in accessing local clipboard") pyperclip.copy(data)
def download(username, password): """ Downloads from server and updates the local clipboard. """ res = requests.get(server_url+"copy-paste/", auth=(username, password)) if res.status_code == 200: paste(json.loads(res.text)["text"]) else: print("Cannot download the data.")
def usage(): print("Error: Unknown argument") print("Usage: cloudcb.py copy|paste|register <email> <password>")
def get_data(self): text = pyperclip.paste() # When the clipboard data is equal to what we copied last time, reuse # the `ClipboardData` instance. That way we're sure to keep the same # `SelectionType`. if self._data and self._data.text == text: return self._data # Pyperclip returned something else. Create a new `ClipboardData` # instance. else: return ClipboardData( text=text, type=SelectionType.LINES if '\n' in text else SelectionType.LINES)
def push_list_from_clipboard(): push_type_dict = { u"?": 1, u"?": 2, u"\u2192": 3 } def construct_push(line): words = line.split(' ') if len(words) < 2: return None push = re.sub('\\s', '', words[0]) if push not in push_type_dict: return None push = push_type_dict[push] u_id = re.sub('\\s', '', words[1]) if u_id[-1] != ':': return None u_id = re.sub(':', '', u_id).encode('ascii') return {'push': push, 'id': u_id} content = pyperclip.paste() lines = re.split('\r\n|\r|\n', content) return [x for x in map(construct_push, lines) if x]
def determine_clipboard(): # Determine the OS/platform and set the copy() and paste() functions accordingly. if 'cygwin' in platform.system().lower(): return init_windows_clipboard(cygwin=True) if os.name == 'nt' or platform.system() == 'Windows': return init_windows_clipboard() if os.name == 'mac' or platform.system() == 'Darwin': return init_osx_clipboard() if HAS_DISPLAY: # Determine which command/module is installed, if any. try: import gtk # check if gtk is installed except ImportError: pass else: return init_gtk_clipboard() try: import PyQt4 # check if PyQt4 is installed except ImportError: pass else: return init_qt_clipboard() if _executable_exists("xclip"): return init_xclip_clipboard() if _executable_exists("xsel"): return init_xsel_clipboard() if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() return init_no_clipboard()
def set_clipboard(clipboard): global copy, paste if clipboard == 'osx': from .clipboards import init_osx_clipboard copy, paste = init_osx_clipboard() elif clipboard == 'gtk': from .clipboards import init_gtk_clipboard copy, paste = init_gtk_clipboard() elif clipboard == 'qt': from .clipboards import init_qt_clipboard copy, paste = init_qt_clipboard() elif clipboard == 'xclip': from .clipboards import init_xclip_clipboard copy, paste = init_xclip_clipboard() elif clipboard == 'xsel': from .clipboards import init_xsel_clipboard copy, paste = init_xsel_clipboard() elif clipboard == 'klipper': from .clipboards import init_klipper_clipboard copy, paste = init_klipper_clipboard() elif clipboard == 'no': from .clipboards import init_no_clipboard copy, paste = init_no_clipboard() elif clipboard == 'windows': from .windows import init_windows_clipboard copy, paste = init_windows_clipboard()
def main(): global recent_value while True: tmp_value = pyperclip.paste() if tmp_value != recent_value: recent_value = tmp_value myDetect(recent_value) time.sleep(0.1)
def copy_to_clipboard(text): current = pyperclip.paste() if (not clipboard) or (clipboard and clipboard[-1]!=current): clipboard.append(current) pyperclip.copy(text) clipboard.append(text)
def clearclip(text=""): ''' Clear the clipboard if nothing has been copied since data was added to it ''' if text == "": pyperclip.copy("") elif pyperclip.paste() == text: pyperclip.copy("")
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) text = pyperclip.paste() self.setupUi(self, text,error)
def Copy_exit(button,choice): ####called when user selects copy to clipboard pyperclip.copy(str(choice.url)) spam = pyperclip.paste() sys.exit()
def process(self): while self.active: tmp_val = pyperclip.paste() if tmp_val != self.last_clipboard: self.last_clipboard = tmp_val self.copied.emit(tmp_val) # self.window.handleClipboard(tmp_val) time.sleep(0.1)
def Pastetext(self): self.contents.insert(INSERT, pyperclip.paste())
def determine_clipboard(): # Determine the OS/platform and set # the copy() and paste() functions accordingly. if 'cygwin' in platform.system().lower(): # FIXME: pyperclip currently does not support Cygwin, # see https://github.com/asweigart/pyperclip/issues/55 pass elif os.name == 'nt' or platform.system() == 'Windows': return init_windows_clipboard() if os.name == 'mac' or platform.system() == 'Darwin': return init_osx_clipboard() if HAS_DISPLAY: # Determine which command/module is installed, if any. try: import gtk # check if gtk is installed except ImportError: pass else: return init_gtk_clipboard() try: import PyQt4 # check if PyQt4 is installed except ImportError: pass else: return init_qt_clipboard() if _executable_exists("xclip"): return init_xclip_clipboard() if _executable_exists("xsel"): return init_xsel_clipboard() if _executable_exists("klipper") and _executable_exists("qdbus"): return init_klipper_clipboard() return init_no_clipboard()
def set_clipboard(clipboard): global copy, paste clipboard_types = {'osx': init_osx_clipboard, 'gtk': init_gtk_clipboard, 'qt': init_qt_clipboard, 'xclip': init_xclip_clipboard, 'xsel': init_xsel_clipboard, 'klipper': init_klipper_clipboard, 'windows': init_windows_clipboard, 'no': init_no_clipboard} copy, paste = clipboard_types[clipboard]()
def clipboard_read(): return paste()
def _read_clipboard(self): for _ in range(15): try: win32api.keybd_event(17, 0, 0, 0) win32api.keybd_event(67, 0, 0, 0) win32api.keybd_event(67, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) time.sleep(0.2) return pyperclip.paste() except Exception as e: log.error('open clipboard failed: {}, retry...'.format(e)) time.sleep(1) else: raise Exception('read clipbord failed')
def WriteClip(info): import pyperclip pyperclip.copy(info) spam = pyperclip.paste() return spam # ================??????================
def paste_from_clipboard(): text = pyperclip.paste() return text
def copy_to_clipboard(new_text): pyperclip.copy(new_text) print("The new string is now copied to the clipboard. Hit CTRL V to paste.")
def paste_from_clipboard(): text = pyperclip.paste().split("\r") return text
def copy_to_clipboard(new_list): new_list[-1] = '\n' + new_list[-1] new_text = ''.join(new_list) pyperclip.copy(new_text) print("The new string is now copied to the clipboard. Hit CTRL V to paste.")
def create_list(): input_list = pyperclip.paste().split('\n') input_list.sort(key=float) return input_list
def openMaps(address): if address == "": address = paste() open_new_tab("http://www.google.com/maps/place/"+address) #open a url in new tab
def get_data(self, key='W'): "?CVirtualGridCtrl|Custom<n>?????????????????" keystroke(self.two_way, ord(key)) # ?????('W')???('E')???('R') wait_a_second() # ?????????... op.SendMessageW(self.custom, WM_COMMAND, 57634, self.path_custom[-1]) # background mode return pyperclip.paste()
def readChar(): if event.key == pygame.K_BACKSPACE: return 'backspace' elif event.key == pygame.K_PAGEUP: return 'pageup' elif event.key == pygame.K_PAGEDOWN: return 'pagedown' elif event.key == pygame.K_TAB: return 'tab' elif event.key == pygame.K_RETURN: return 'enter' elif event.key == pygame.K_ESCAPE: return 'esc' elif event.key in (pygame.K_RSHIFT, pygame.K_LSHIFT): return 'shift' elif event.key in (pygame.K_RCTRL, pygame.K_LCTRL): return 'control' elif event.key == pygame.K_RIGHT: return 'kright' elif event.key == pygame.K_LEFT: return 'kleft' elif event.key == pygame.K_UP: return 'kup' elif event.key == pygame.K_DOWN: return 'kdown' elif event.key == pygame.K_CAPSLOCK: return None elif event.key == 282: return 'paste' elif event.key == 283: return 'begincur' elif event.key == 284: return 'endcur' elif event.key == 285: return 'delall' else: return event.unicode
def _redirect_output(self, statement): """Handles output redirection for >, >>, and |. :param statement: ParsedString - subclass of str which also contains pyparsing ParseResults instance """ if statement.parsed.pipeTo: self.kept_state = Statekeeper(self, ('stdout',)) # Create a pipe with read and write sides read_fd, write_fd = os.pipe() # Make sure that self.poutput() expects unicode strings in Python 3 and byte strings in Python 2 write_mode = 'w' read_mode = 'r' if six.PY2: write_mode = 'wb' read_mode = 'rb' # Open each side of the pipe and set stdout accordingly # noinspection PyTypeChecker self.stdout = io.open(write_fd, write_mode) # noinspection PyTypeChecker subproc_stdin = io.open(read_fd, read_mode) # We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True. try: self.pipe_proc = subprocess.Popen(shlex.split(statement.parsed.pipeTo), stdin=subproc_stdin) except Exception as ex: # Restore stdout to what it was and close the pipe self.stdout.close() subproc_stdin.close() self.pipe_proc = None self.kept_state.restore() self.kept_state = None # Re-raise the exception raise ex elif statement.parsed.output: if (not statement.parsed.outputTo) and (not can_clip): raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable') self.kept_state = Statekeeper(self, ('stdout',)) self.kept_sys = Statekeeper(sys, ('stdout',)) if statement.parsed.outputTo: mode = 'w' if statement.parsed.output == 2 * self.redirector: mode = 'a' sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode) else: sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+") if statement.parsed.output == '>>': self.poutput(get_paste_buffer())