def _prompt_for_code(device_code): # copy code to clipboard pyperclip.copy(device_code["user_code"]) verif_uri = device_code.get("verification_url", device_code.get("verification_uri")) title = "Authentication needed for KeyVault access." logon_mssg = "User code {} copied to clipboard.".format( device_code["user_code"]) if is_ipython(): display(HTML(f"<h3>{title}</h3>")) logon_mssg += "<br><a href='{}' target='_blank'>".format(verif_uri) logon_mssg += "Click to open logon page</a><br>" else: print(title) print("-" * len(title)) logon_mssg += "\nOpen the URL '{}' in a browser\n".format(verif_uri) logon_mssg += "then press Ctrl/Cmd-V to paste your code to authenticate. " if "expires_in" in device_code: logon_mssg += "(Code valid for {} min)".format( int(int(device_code["expires_in"]) / 60)) elif "expires_on" in device_code: logon_mssg += "(Code valid until {})".format(device_code["expires_on"]) if is_ipython(): display(HTML(logon_mssg)) else: print(logon_mssg)
def cp(data, headers=False, index=False): if isinstance(data, np.ndarray): data = pd.DataFrame(data) if isinstance(data, pd.DataFrame): data.to_clipboard(header=False, index=False) else: cb.copy(data)
def call_model(args, model, image_resizer, tokenizer, img=None): global last_pic encoder, decoder = model.encoder, model.decoder if type(img) is bool: img = None if img is None: if last_pic is None: print('Provide an image.') return '' else: img = last_pic.copy() else: last_pic = img.copy() img = minmax_size(pad(img), args.max_dimensions, args.min_dimensions) if image_resizer is not None and not args.no_resize: with torch.no_grad(): input_image = img.convert('RGB').copy() r, w = 1, input_image.size[0] for _ in range(10): img = pad( minmax_size( input_image.resize( (w, int(input_image.size[1] * r)), Image.BILINEAR if r > 1 else Image.LANCZOS), args.max_dimensions, args.min_dimensions)) t = test_transform(image=np.array(img.convert( 'RGB')))['image'][:1].unsqueeze(0) w = (image_resizer(t.to(args.device)).argmax(-1).item() + 1) * 32 logging.info(r, img.size, (w, int(input_image.size[1] * r))) if (w == img.size[0]): break r = w / img.size[0] else: img = np.array(pad(img).convert('RGB')) t = test_transform(image=img)['image'][:1].unsqueeze(0) im = t.to(args.device) with torch.no_grad(): model.eval() device = args.device encoded = encoder(im.to(device)) dec = decoder.generate(torch.LongTensor([args.bos_token ])[:, None].to(device), args.max_seq_len, eos_token=args.eos_token, context=encoded.detach(), temperature=args.get('temperature', .25)) pred = post_process(token2str(dec, tokenizer)[0]) try: clipboard.copy(pred) except: pass return pred
def copy_js(extension): try: from pandas.io import clipboard except ImportError: try: import pyperclip as clipboard except ImportError: sys.exit( 'Please install either "pandas" or "pyperclip" to use the copy command.' ) with open(Path(this_dir) / "js" / f"xlwings.{extension}", "r") as f: clipboard.copy(f.read()) print("Successfully copied to clipboard.")
def clipboard2dict(key=0, value=1): """Returns a dictionary based on clipboard contents. For example, copy a range in Excel as input. The resulting dictionary will be a key:value pair of two columns in the range. Args: key (int, optional): Identify the index position for the column to be used as the key. Defaults to 0. value (int, optional): Identify the index position for the column to be used as the value. Defaults to 1. Returns: dictionary: dictionary representation of range in clipboard. """ df = pd.read_clipboard() dictionary = dict(zip(df.iloc[:, key], df.iloc[:, value])) copy(str(dictionary))
def test_clipboard(capsys): # This test is a bit nasty as we necessarily need to modify the # clipboard. We do, however, try to preserve the content. YMMV. import pandas.io.clipboard as cp old = cp.paste() try: df = pd.read_csv(_get_path("a")) df.to_clipboard() _call("from clipboard") captured = Capture(capsys.readouterr()) assert not captured.err df = captured.df captured.assert_shape(6, 2) finally: cp.copy(old)
def copy_report_csv(self): copy(self.reportCSV) self.copyReportCSVBtn["text"] = "CSV Copied!"
def copy_report(self): copy(self.reportText) self.copyReportBtn["text"] = "Report Copied!"
def clipboard_copy(self): clipboard.copy(self.myEntry2.get())