我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pyperclip.copy()。
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.limit_button.clicked.connect(self.limittfunc) self.diffButton_normal.clicked.connect(self.diff_normal) self.diffButton_complex.clicked.connect(self.diff_complex) self.integralButton_normal.clicked.connect(self.integral_normal) self.integralButton_complex.clicked.connect(self.integral_complex) self.allCalculator.clicked.connect(self.allcalc) self.binomialButton.clicked.connect(self.binomialfunc) self.solver_button.clicked.connect(self.solver) self.sumButton.clicked.connect(self.sumfunc) self.factorButton.clicked.connect(self.factorfunc) self.fourierButton.clicked.connect(self.fourier) self.integralButton_copy.clicked.connect(self.copy) self.integralButton_copy_3.clicked.connect(self.copy) self.integralButton_copy_9.clicked.connect(self.copy) self.integralButton_copy_10.clicked.connect(self.copy) self.integralButton_copy_11.clicked.connect(self.copy) self.integralButton_copy_12.clicked.connect(self.copy) self.integralButton_copy_13.clicked.connect(self.copy) self.integralButton_copy_2.clicked.connect(self.copy) self.integralButton_copy_4.clicked.connect(self.copy)
def main(): my_message = 'If a man is offered a fact which goes against his instincts, he will scrutinize it closely, and unless the evidence is overwhelming, he will refuse to believe it. If, on the other hand, he is offered something which affords a reason for acting in accordance to his instincts, he will accept it even on the slightest evidence. The origin of myths is explained in this way. -Bertrand Russell' my_key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ' my_mode = 'encrypt' # Check my_key is valid or not check_valid_key(my_key) if my_mode=='encrypt': translated = encrypt_message(my_key, my_message) elif my_mode=='decrypt': translated = decrypt_message(my_key, my_message) print('Using key %s' % my_key) print('THe %sed message is :' % my_mode) print(translated) pyperclip.copy(translated) print() print('This message has copied to clipboard')
def main(): if len(sys.argv) != 3: print('Usage: $python decrypt.py [filename] [key]') exit(1) try: f = open(sys.argv[1]) except FileNotFoundError as e: print(e) exit(1) plain_text = f.read() key = int(sys.argv[2]) cipher_text = decrypt_message(key, plain_text) print(cipher_text + '|') # Copy to clipboard pyperclip.copy(cipher_text) print('Plain text has save to clipboard')
def clip_df(df, tablefmt='html'): """ Copy a dataframe as plain text to your clipboard. Probably only works on Mac. For format types see ``tabulate`` package documentation. :param pandas.DataFrame df: Input DataFrame. :param str tablefmt: What type of table? :return: None. """ if tablefmt == 'material': html = tabulate.tabulate(df, headers=df.columns, tablefmt='html') html = html.replace('<table>', '<table class="mdl-data-table mdl-js-data-table">') header = '<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">\n<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">\n<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>' html = header + '\n' + html else: html = tabulate.tabulate(df, headers=df.columns, tablefmt=tablefmt) pyperclip.copy(html) print('Copied {} table to clipboard!'.format(tablefmt)) return html
def copy_magnet(self, link): """Copy magnetic link to clipboard. This method is different from copylink_clipboard(). This method handles the --copy argument. If --copy argument is supplied, magnetic link is copied to clipboard. """ from torrench.Torrench import Torrench tr = Torrench() if tr.check_copy(): try: pyperclip.copy(link) print("(Magnetic link copied to clipboard)") except Exception as e: print("(Unable to copy magnetic link to clipboard. Is [xclip] installed?)") print("(See logs for details)") self.logger.error(e) else: print("(use --copy to copy magnet to clipboard)")
def product_search(): # Checks the individual products for the recaptcha sitekey print("\nFound {} product links on page {}.\n".format(len(product_links), (params['start']+1))) index = 0 for product in product_links: index += 1 print('{} of {}: Checking for sitekey in: {}'.format(index + len(product_links)*(params['start']), len(product_links) * (params['start']+1), product)) site_key_results = sitekey_scraper(str(product)) if site_key_results: pyperclip.copy(site_key_results) print("\nFollowing Recaptcha Sitekey has been copied to clipboard:\n\n{}\n".format( site_key_results)) return True return False # # where the magic happens, u feel?
def get_command(self, ctx, cmd_name): """Allow aliases for commands. """ if cmd_name == 'list': cmd_name = 'ls' elif cmd_name == 'search': cmd_name = 'find' elif cmd_name == 'gen': cmd_name = 'generate' elif cmd_name == 'add': cmd_name = 'insert' elif cmd_name in ['remove', 'delete']: cmd_name = 'rm' elif cmd_name == 'rename': cmd_name = 'mv' elif cmd_name == 'copy': cmd_name = 'cp' # TODO(benedikt) Figure out how to make 'show' the default # command and pass cmd_name as the first argument. rv = click.Group.get_command(self, ctx, cmd_name) if rv is not None: return rv
def cp(ctx, old_path, new_path, force): """Copies the password or directory names `old-path` to `new-path`. This command is alternatively named `copy`. If `--force` is specified, silently overwrite `new_path` if it exists. If `new-path` ends in a trailing `/`, it is always treated as a directory. Passwords are selectively reencrypted to the corresponding keys of their new destination. """ try: ctx.obj.copy_path(old_path, new_path, force) except StoreNotInitialisedError: click.echo(MSG_STORE_NOT_INITIALISED_ERROR) return 1 except FileNotFoundError: click.echo('{0} is not in the password store.'.format(old_path)) return 1 except PermissionError: click.echo(MSG_PERMISSION_ERROR) return 1 except RecursiveCopyMoveError: click.echo(MSG_RECURSIVE_COPY_MOVE_ERROR.format('copy')) return 1
def clipboard(text,prnt, clear): ''' Copy data to clipboard and start a thread to remove it after 20 seconds ''' try: pyperclip.copy(text) print("Copied to clipboard") except: print("There was an error copying to clipboard. Do you have xsel installed?") quit() if prnt: print(text) if clear: global myThread if myThread and myThread.is_running(): myThread.stop() myThread.join() myThread = StoppingThread(target=timer, args=(20,text,)) myThread.start()
def main(args): ext = {"py":"python3","cpp":"cpp","c":"c"} url = "https://paste.ubuntu.com/" with open(args) as f: file_name, syntax = sys.argv[1].rsplit("/")[-1].rsplit(".") payload = { "poster" : file_name, "syntax" : ext[syntax], "content" : str(f.read()) } req = requests.post(url, data=payload) print(req.url) pyperclip.copy(str(req.url)) return 0
def upload_img(file, arg): with open(file, 'rb') as f: start_time = time() ufile = requests.post( img_server, files={arg: f.read(), 'content_type': 'application/octet-stream'}) end_time = time() url = ufile.text.split()[-1] usage_time = round(end_time - start_time, 2) print('upload time: {}s'.format(usage_time)) try: pyperclip.copy(url) except NameError: pass except: pass return url
def upload_text(file, arg): postfix = file.split('.')[-1] with open(file, 'r') as f: start_time = time() ufile = requests.post( text_server, data={arg: f.read(), 'content_type': 'application/octet-stream'}) end_time = time() url = ufile.text url = url.strip() url = url + "/{}".format(postfix) usage_time = round(end_time - start_time, 2) print('upload time: {}s'.format(usage_time)) try: pyperclip.copy(url) except NameError: pass except: pass return url
def upload_pipe_test(arg): args = sys.stdin start_time = time() ufile = requests.post( text_server, data={arg: args.read(), 'content_type': 'application/octet-stream'}) end_time = time() url = ufile.text url = url.strip() usage_time = round(end_time - start_time, 2) print('upload time: {}s'.format(usage_time)) try: pyperclip.copy(url) except NameError: pass return url # opt
def build(file, copy): click.echo('Transpiling to Javascript...') t = envoy.run('transcrypt -p .none {}'.format(file)) if t.status_code != 0: click.echo(t.std_out) sys.exit(-1) click.echo('Completed.') if copy is True: basename = os.path.basename(file) basename = os.path.splitext(basename)[0] basedir = os.path.dirname(file) fpath = os.path.join(basedir, '__javascript__/{}.min.js'.format(basename)) with open(fpath, 'r') as minfile: pyperclip.copy(minfile.read()) click.echo('Minified app.js copied to clipboard')
def main(): my_message = 'helloworld' # Your Cipher key my_key = 3 my_message = my_message.upper() # mode = 'decrypt' translated = caesar_cipher(my_message, my_key) # Save to clipboard pyperclip.copy(translated) print(translated) print('Cipher text has save to clipboard')
def main(): my_message = """Alan Mathison Turing was a British mathematician, logician , cryptanalyst, and computer scientist. He was highly influential in the d evelopment of computer science, providing a formalisation of the concepts of "algorithm" and "computation" with the Turing machine. Turing is widely con sidered to be the father of computer science and artificial intelligence. D uring World War II, Turing worked for the Government Code and Cypher School (GCCS) at Bletchley Park, Britain's codebreaking centre. For a time he was head of Hut 8, the section responsible for German naval cryptanalysis. He devised a number of techniques for breaking German ciphers, including the method of the bombe, an electromechanical machine that could find settin gs for the Enigma machine. After the war he worked at the National Physi cal Laboratory, where he created one of the first designs for a stored-pr ogram computer, the ACE. In 1948 Turing joined Max Newman's Computing Lab oratory at Manchester University, where he assisted in the development of the Manchester computers and became interested in mathematical biology. He wrote a paper on the chemical basis of morphogenesis, and predicted o scillating chemical reactions such as the Belousov-Zhabotinsky reaction, which were first observed in the 1960s. Turing's homosexuality resulted i n a criminal prosecution in 1952, when homosexual acts were still illegal in the United Kingdom. He accepted treatment with female hormones (chemical castration) as an alternative to prison. Turing died in 1954, just over two weeks before his 42nd birthday, from cyanide poisoning. An inquest determined that his death was suicide; his mother and some others believed his death was accidental. On 10 September 2009, following an Internet campaign, British Prime Minister Gordon Brown made an official public apology on behalf of the British government for "the appalling way he was treated." As of May 2012 a private member's bill was before the House of Lords which would grant Turing a statutory pardon if enacted.""" print("Reverse Cipher") translated = reverse_cipher(my_message) print(translated) # Copy to clipboard pyperclip.copy(translated)
def main(): # replace your key and plain text my_message = 'Hello world' my_key = 5 cipher_text = encrypt_message(my_key, my_message) print(cipher_text + '|') # Copy to clipboard pyperclip.copy(cipher_text) print('Cipher text has save to clipboard')
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 __init__(self, obj, attribs): """Use the instance attributes as a generic key-value store to copy instance attributes from outer object. :param obj: instance of cmd2.Cmd derived class (your application instance) :param attribs: Tuple[str] - tuple of strings listing attributes of obj to save a copy of """ self.obj = obj self.attribs = attribs if self.obj: self._save()
def checkForCopy(self, arg): if self.checkBox_copy.isChecked() == True: pyperclip.copy(str(arg))
def copy(self): pyperclip.copy(str(result))
def copylink_clipboard(self, link): """Copy Magnetic/Upstream link to clipboard""" try: self.logger.debug("Copying magnetic/upstream link to clipboard") pyperclip.copy(link) self.logger.debug("Copied successfully.") message = "Link copied to clipboard.\n" print(self.colorify("green", message)) except Exception as e: print("Something went wrong.") print("Please make sure [xclip] package is installed.") print("See logs for details.\n\n") self.logger.error(e)
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 set_data(self, data): assert isinstance(data, ClipboardData) self._data = data pyperclip.copy(data.text)
def copy_to_clipboard(text): """Writes a text to clipboard.""" logger.info('Copying text to clipboard: %s', text) pyperclip.copy(text)
def update_history_menu(self): self.historyMenu.clear() last = None for url in self.history['urls']: title = self.history['titles'][url] action = QtGui.QAction(title, self, triggered=partial(pyperclip.copy, url)) self.historyMenu.insertAction(last, action) last = action
def upload(self, name): key = os.path.basename(name) q = qiniu.Auth(self.access_key, self.secret_key) with open(name, 'rb') as img: data = img token = q.upload_token(self.bucket) ret, info = qiniu.put_data(token, key, data) if self.parseRet(ret, info): md_url = "![]({}/{})".format(self.domain, key) print(md_url) title = name pyperclip.copy(md_url) self.append_history(title, md_url)
def show(ctx, pass_name, clip, passthrough=False): """Decrypt and print a password named `pass-name`. If `--clip` or `-c` is specified, do not print the password but instead copy the first line to the clipboard using pyperclip. On Linux you will need to have xclip/xsel and on OSX pbcopy/pbpaste installed. """ try: data = ctx.obj.get_key(pass_name) # If pass_name is actually a folder in the password store pass # lists the folder instead. except FileNotFoundError: if not passthrough: return ctx.invoke(ls, subfolder=pass_name, passthrough=True) else: click.echo(MSG_FILE_NOT_FOUND.format(pass_name)) return 1 except StoreNotInitialisedError: click.echo(MSG_STORE_NOT_INITIALISED_ERROR) return 1 except PermissionError: click.echo(MSG_PERMISSION_ERROR) return 1 if clip: pyperclip.copy(data.split('\n')[0]) click.echo('Copied {0} to the clipboard.'.format(pass_name)) else: # The key data always ends with a newline. So no need to add # another one. click.echo(data, nl=False)
def generate(ctx, pass_name, pass_length, no_symbols, clip, in_place, force): """Generate a new password of length `pass-length` and insert into `pass-name`. If `--no-symbols` or `-n` is specified, do not use any non-alphanumeric characters in the generated password. If `--clip` or `-c` is specified, do not print the password but instead copy it to the clipboard. On Linux you will need to have xclip/xsel and on OSX pbcopy/pbpaste installed. Prompt before overwriting an existing password, unless `--force` or `-f` is specified. If `--in-place` or `-i` is specified, do not interactively prompt, and only replace the first line of the password file with the new generated password, keeping the remainder of the file intact. """ symbols = not no_symbols try: password = ctx.obj.gen_key(pass_name, pass_length, symbols, force, in_place) except StoreNotInitialisedError: click.echo(MSG_STORE_NOT_INITIALISED_ERROR) return 1 except PermissionError: click.echo(MSG_PERMISSION_ERROR) return 1 except FileNotFoundError: click.echo(MSG_FILE_NOT_FOUND.format(pass_name)) return 1 if password is None: return 1 if clip: pyperclip.copy(password) click.echo('Copied {0} to the clipboard.'.format(pass_name)) else: click.echo('The generated password for {0} is:'.format(pass_name)) click.echo(password)
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 copy_clipboard(self): pyperclip.copy(self.IDC_plainTextLink.toPlainText())
def copy_to_clipboard(generated): global copied selection = safe_input('Which password would you like to copy? [1/2/3] ').strip() if selection in ['1', '2', '3']: password = generated[int(selection) - 1] else: print(color('Invalid option. Pick either 1, 2 or 3.\n', Fore.RED)) return copy_to_clipboard(generated) try: pyperclip.copy(password) copied = True print('\nCopied!\n') except pyperclip.exceptions.PyperclipException: print(color('Could not copy! If you\'re using linux, make sure xclip is installed.\n', Fore.RED))
def exit(msg=''): if copied: pyperclip.copy('') if msg: print(color('\n%s' % msg, Fore.RED)) print(color('\nExiting securely... You are advised to close this terminal.', Fore.RED)) raise SystemExit
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 to_clipboard(self): """ send viz to clipboard """ pyperclip.copy(self.html)
def Input__paste(tabs, tab, data): try: backup = pyperclip.determine_clipboard()[1]() # Not sure if is correct D: except: backup = None pyperclip.copy(data) await tab.Input.press_key(tabs.helpers.keyboard.PASTE) if backup is not None: pyperclip.copy(backup)
def entry_point(): args = docopt(DOC, version=VERSION) path = args['<path>'] doc_type = get_doc_type(args) fields = load_config(locate_config()) # load operator. remote = fields.get(CONFIG_REMOTE, 'github') if remote not in REGISTERED_REMOTES: raise RuntimeError( 'FATAL: {0} is not a valid remote type.'.format(remote), ) RemoteConfig, RemoteOperation = REGISTERED_REMOTES[remote] ret_fname, resource_url = upload_file( path, fields, RemoteConfig, RemoteOperation, ) url = translate_url( ret_fname, resource_url, doc_type, ) if not args['--no-clipboard']: pyperclip.copy(url) print(url)
def Copy_exit(button,choice): ####called when user selects copy to clipboard pyperclip.copy(str(choice.url)) spam = pyperclip.paste() sys.exit()
def __init__(self, MainWindow, parent=None): super(ClipThread, self).__init__(parent) self.window = MainWindow pyperclip.copy('') self.last_clipboard = '' self.active = True
def copyFitting(self): self.stopClipboard() fit = [] ship = self.shipName if self.shipName else 'Metal Scraps' fit.append("[{}, New Fit]".format(ship)) for key in self.mapped_items: for item in self.mapped_items[key]["items"]: fit.append(item) fit.append('') pyperclip.copy('') pyperclip.copy("\n".join(fit))
def copytext(self): self.Copiedtext = pyperclip.copy(self.contents.get(1.0, END))