本文整理汇总了Python中xerox.copy函数的典型用法代码示例。如果您正苦于以下问题:Python copy函数的具体用法?Python copy怎么用?Python copy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = optparse.OptionParser()
using_help = '''
the service that you want to use. For example: gist for Github's Gist,
pastebin for PasteBin.com
'''
parser.add_option('-u', '--using', dest='using',
help=using_help)
(options, args) = parser.parse_args()
using = options.using
if not using:
using = 'pastebin'
obj = SharePastesFactory.create(using)
try:
url = obj.api_call(xerox.paste())
xerox.copy(url)
except xerox.base.XclipNotFound:
print 'xclip not found. Install xclip for SharePastes to work.'
sys.exit(1)
try:
from pync import Notifier
Notifier.notify('URL added to your clipboard %s.' % url,
title='SharePastes')
except:
pass
示例2: action
def action(args):
# TODO Handle STDOUT on get
keyword = args.keyword
namespace = args.namespace
conn = util.connect_database()
if not conn:
exit('Unable to access %s; exiting' % util.DB_LOCATION)
clippings = util.get_clippings(
conn,
key=keyword,
namespace=namespace
)
msg = value = None
if len(clippings) == 0: # Key not found
if namespace:
msg = "Unknown namespace/key: %s/%s" % (namespace, keyword)
else:
msg = "Unknown key: %s" % keyword
elif len(clippings) == 1:
value = clippings[0][1]
msg = "Set clipboard to %s" % value
xerox.copy(value)
else:
msg = 'Multiple choices:\n' + '\n'.join(
["\t%s/%s: %s" % (c[0], keyword, c[1]) for c in clippings]
)
return msg
示例3: set_clipboard
def set_clipboard(text, datatype=None):
"""
Arg datatype currently not used. Will generally assumed to be unicode text.
From http://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python
"""
if 'xerox' in sys.modules.keys():
xerox.copy(text)
elif 'pyperclip' in sys.modules.keys():
pyperclip.copy(text)
elif 'gtk' in sys.modules.keys():
clipboard = gtk.clipboard_get()
text = clipboard.set_text(text)
elif 'win32clipboard' in sys.modules.keys():
wcb = win32clipboard
wcb.OpenClipboard()
wcb.EmptyClipboard()
# wcb.SetClipboardText(text) # doesn't work
# SetClipboardData Usage:
# >>> wcb.SetClipboardData(<type>, <data>)
# wcb.SetClipboardData(wcb.CF_TEXT, text.encode('utf-8')) # doesn't work
wcb.SetClipboardData(wcb.CF_UNICODETEXT, unicode(text)) # works
wcb.CloseClipboard() # User cannot use clipboard until it is closed.
else:
# If code is run from within e.g. an ipython qt console, invoking Tk root's mainloop() may hang the console.
r = Tk()
# r.withdraw()
r.clipboard_clear()
r.clipboard_append(text)
r.mainloop() # the Tk root's mainloop() must be invoked.
r.destroy()
示例4: main
def main():
args = parse_args()
tab = not args.spaces
code = add_indentation(get_code(args), tab)
if args.stdout: print code
else: xerox.copy(code)
示例5: callback
def callback(event):
# moved to a name with Screen Shot in it
if event.mask is 128 and file_str in str(event.name):
# split the extension
fileExtension = os.path.splitext(event.name)[1]
newName = str(hash_for_file(event.name))[0:6] + fileExtension
upload_file(event.name, scp_path + newName)
xerox.copy(protocol + hostname + web_path + newName)
示例6: convert_zalgo
def convert_zalgo(text, intensity=50, copy=False):
input_text = u' '.join(text)
zalgotext = zalgo.zalgo(input_text, intensity)
if copy:
xerox.copy(u'' + zalgotext)
return zalgotext
示例7: test_copy_and_paste
def test_copy_and_paste(self):
# copy
self.assertIsInstance(self.text, str)
xerox.copy(self.text)
# paste
got = xerox.paste()
self.assertIsInstance(got, str)
self.assertEqual(got, self.text)
示例8: parse
def parse(return_output=True, file_path=None):
if not file_path:
try:
file_path = sys.argv[1]
except IndexError:
# assume `email.html`
file_path = 'email.html'
# check file exists
if not exists(file_path):
raise IOError('File does not exist')
# check extension and mimetype
filename, ext = splitext(file_path)
mime_type = MimeTypes().guess_type(file_path)[0]
if ext.lower() not in ['.htm', '.html'] or mime_type != 'text/html':
raise Exception('File does not appear to be an HTML file.')
# process file
with open(file_path, 'r') as html_file:
data = html_file.read()
# extract body
soup = BeautifulSoup(data, 'html.parser')
body = soup.body.contents[1]
# strip comments
[comment.extract() for comment in body.findAll(
text=lambda text: isinstance(text, Comment))]
# replace image tags with the name of the image
body_soup = BeautifulSoup(str(body), 'html.parser')
for img in body_soup.findAll('img'):
img.replace_with(img['name'])
# add trouble link row
trouble_row = body_soup.new_tag('tr')
trouble_column = body_soup.new_tag('td')
trouble_column.string = 'trouble'
trouble_row.append(trouble_column)
body_soup.tr.insert_before(trouble_row)
# add inline css to each td
for td in body_soup.find_all('td'):
td['style'] = 'text-align: left; vertical-align: top;'
# right align trouble link text
body_soup.tr.td['style'] = 'text-align: right; vertical-align: top;'
output = unicode(body_soup)
# copy HTML to clipboard FTW
xerox.copy(output)
sys.stdout.write('HTML copied to clipboard' + '\n')
if return_output:
return output
示例9: on_key_press
def on_key_press( self, symbol, modifiers ):
# whether we handle the text here
self.texthandled = 0
# kill the alert if you push anything
self.alerttime = 0
# some global key strokes
if symbol == key.F11:
if self.fullscreenwait == 0:
self.set_fullscreen( not self.fullscreen )
self.fullscreenwait = 1 # wait a second before allowing switching back
self.activate()
self.set_focus(None)
self.texthandled = 1
elif (symbol == key.Q or symbol == key.W) and modifiers & key.MOD_CTRL:
pyglet.app.exit()
# check for command mode...
elif self.commandmode:
if symbol == key.RETURN:
# if we pressed enter after entering a command...
self.setcommand( False )
self.texthandled = 1
# check for inputting things in some other focus box...
elif self.focus:
# if we are focused on some input device, don't let
# any other commands be available except to possibly escape from it,
# also basic copy and paste.
if symbol == key.ESCAPE:
self.set_focus( None )
self.texthandled = 1
elif symbol == key.C and modifiers & key.MOD_CTRL:
xerox.copy( self.focus.getselectedtext() )
self.texthandled = 1
elif symbol == key.V and modifiers & key.MOD_CTRL:
self.focus.dealwithtext( xerox.paste() )
self.texthandled = 1
# otherwise look at what it could mean for the global guy
else:
if ( symbol == key.Q or symbol == key.ESCAPE ):
self.texthandled = 1
self.alert( "ctrl+Q or ctrl+W to quit" )
elif symbol == key.SLASH:
self.texthandled = 1
self.setcommand() # get command mode ready
elif symbol == key.W:
self.alert(self.lastalert,10)
elif symbol == key.S:
self.savefile()
elif symbol == key.E:
self.loadfile( "scratch" )
print "key press ", symbol, " are we handled? ", self.texthandled
return pyglet.event.EVENT_HANDLED
示例10: main
def main(poster, file):
payload = {}
payload["poster"] = poster
content, syntax = get_data_from_file(file)
payload["content"] = content
payload["syntax"] = syntax
res = requests.post('http://paste.ubuntu.com', data=payload)
link = res.url
print ('link is {}'.format(link))
xerox.copy(link)
print ('It\'s copied to the clipboard !')
示例11: run
def run(self):
youdao = Youdao()
#youdao.get_translation(msg)
print "start youdao_copy"
xerox.copy("你好")
word = None
word_new =None
err_old = None
try :
word = xerox.paste()
except BaseException,err:
print err
示例12: main
def main():
if (len(sys.argv) != 2):
exit("Which file?")
if APP_KEY == '' or APP_SECRET == '':
exit("You need to set your APP_KEY and APP_SECRET!")
lnd = LinkAndDelete(APP_KEY, APP_SECRET)
path = lnd.upload(sys.argv[1])
if (path):
path = path.replace(PUBLIC_DIR,"/")
url = "http://dl.dropbox.com/u/" + repr(lnd.getUID()) + path
Notifier.notify("LinkAndDelete","Loaded successfuly\n" + url,"GetLinkAndDelete")
xerox.copy(url)
os.remove(sys.argv[1])
示例13: pw
def pw(query, database_path, copy, echo, open, strict):
"""Search for USER and KEY in GPG-encrypted password database."""
# install silent Ctrl-C handler
def handle_sigint(*_):
click.echo()
sys.exit(1)
signal.signal(signal.SIGINT, handle_sigint)
# load database
db = Database.load(database_path)
# parse query (split at right-most "@"" sign, since user names are typically email addresses)
user_pattern, _, key_pattern = query.rpartition('@')
# search database
results = db.search(key_pattern, user_pattern)
results = list(results)
if strict and len(results) != 1:
click.echo('error: multiple or no records found (but using --strict mode)', file=sys.stderr)
sys.exit(1)
# sort results according to key (stability of sorted() ensures that the order of accounts for any given key remains untouched)
results = sorted(results, key=lambda e: e.key)
# print results
output = ''
for idx, entry in enumerate(results):
# key and user
key = style_match(key_pattern).join(entry.key.split(key_pattern)) if key_pattern else entry.key
user = style_match(user_pattern).join(entry.user.split(user_pattern)) if user_pattern else entry.user
output += key
if user:
output += ': ' + user
# password
if echo:
output += ' | ' + style_password(entry.password)
if copy and idx == 0:
xerox.copy(entry.password)
output += ' | ' + style_success('*** PASSWORD COPIED TO CLIPBOARD ***')
# other info
if entry.link:
if open and idx == 0:
import webbrowser
webbrowser.open(entry.link)
output += ' | ' + entry.link
if entry.notes:
output += ' | ' + entry.notes
output += '\n'
click.echo(output.rstrip('\n')) # echo_via_pager has some unicode problems & can remove the colors
示例14: test_echo_vs_copy
def test_echo_vs_copy():
# no copy nor echo
expected = "phones.myphone"
xerox.copy("")
result = invoke_cli("--no-copy", "--no-echo", "myphone")
assert not result.exception and result.exit_code == 0
assert result.output.strip() == expected.strip()
assert xerox.paste() == ""
# only echo
expected = "phones.myphone | 0000"
xerox.copy("")
result = invoke_cli("--no-copy", "--echo", "myphone")
assert not result.exception and result.exit_code == 0
assert result.output.strip() == expected.strip()
assert xerox.paste() == ""
# only echo
expected = "phones.myphone | *** PASSWORD COPIED TO CLIPBOARD ***"
xerox.copy("")
result = invoke_cli("--copy", "--no-echo", "myphone")
assert not result.exception and result.exit_code == 0
assert result.output.strip() == expected.strip()
assert xerox.paste() == "0000"
# both copy and echo
expected = "phones.myphone | 0000 | *** PASSWORD COPIED TO CLIPBOARD ***"
xerox.copy("")
result = invoke_cli("--copy", "--echo", "myphone")
assert not result.exception and result.exit_code == 0
assert result.output.strip() == expected.strip()
assert xerox.paste() == "0000"
示例15: main
def main():
try:
plaintext = ""
if len(sys.argv) == 1:
plaintext = raw_input('Enter text -:\n')
else:
plaintext = sys.argv[1]
ciphertext = plaintext.encode('rot13')
print ciphertext
xerox.copy(ciphertext)
print 'Copied to clipboard!!'
except Exception as exception:
print "Error : {exception}".format(exception=exception.message)