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
python类copy()的实例源码
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 set_data(self, data):
assert isinstance(data, ClipboardData)
self._data = data
pyperclip.copy(data.text)
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 set_data(self, data):
assert isinstance(data, ClipboardData)
self._data = data
pyperclip.copy(data.text)
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))