Exemple #1
0
def put_image_to_clip(image):
    img_byte_arr = io.BytesIO()  # BytesIO实现了在内存中读写bytes
    pb = pasteboard.Pasteboard()

    image.save(img_byte_arr, format='PNG')
    img_byte_arr = img_byte_arr.getvalue()
    pb.set_contents(img_byte_arr, pasteboard.PNG)
Exemple #2
0
def setClipboardData(t, data):
    """向剪贴板写入数据。
    
    Arguments:
        t {string} -- 要写入数据的类型。
        data {string} -- 要写入的数据。若类型为图片则此参数为图片的路径。
    """
    if OS_CUR == OS_WINDOWS:
        if t == TYPE_PNG:
            import win32con
            from PIL import Image
            Image.open(data).save(data + '.bmp')  # win的剪贴板仅支持bmp格式
            from ctypes import windll
            aString = windll.user32.LoadImageW(0, data + '.bmp',
                                               win32con.IMAGE_BITMAP, 0, 0,
                                               win32con.LR_LOADFROMFILE)
            # print(aString)
            if aString != 0:  # 由于图片编码问题 图片载入失败的话 aString 就等于0
                wcb.OpenClipboard()
                wcb.EmptyClipboard()
                wcb.SetClipboardData(win32con.CF_BITMAP, aString)
                wcb.CloseClipboard()

        elif t == TYPE_STRING:
            wcb.OpenClipboard()
            wcb.EmptyClipboard()
            wcb.SetClipboardText(data)
            wcb.CloseClipboard()

        else:
            exit(2)

    elif OS_CUR == OS_MAC:
        if t == TYPE_PNG:
            f = open(data, 'rb')
            img = f.read()
            pb = pasteboard.Pasteboard()
            pb.set_contents(img, pasteboard.PNG)
            f.close()

        elif t == TYPE_STRING:
            pb = pasteboard.Pasteboard()
            pb.set_contents(data)

        else:
            exit(2)
Exemple #3
0
def paste():
    pb = pasteboard.Pasteboard()
    input_buf = pb.get_contents(type=pasteboard.PNG)

    if input_buf is None:
        print('Pasteboard is empty! :c')
        sys.exit()

    hash = blake2b(input_buf, digest_size=6).hexdigest()

    filename = hash + '.png'
    mime = magic.from_buffer(input_buf, mime=True)

    object = upload_file(filename, input_buf, mime)

    pprint(object)

    print('https://dl.lobi.to/' + quote(filename))
Exemple #4
0
def main(obj):
    front_app = _GET_FRONT_APP_SCRIPT.run()

    try:
        res = _SHOW_DIALOG_SCRIPT.run(f"Choose action for '{obj}'")
        if res.get(_EVENT_GAVE_UP):
            print('no selection')
            return
        selected_action = res.get(_EVENT_BUTTON_HIT)
    except ScriptError:
        # User canceled - i.e. want's to edit the link
        selected_action = 'Edit'

    if selected_action == 'Copy':
        pasteboard.Pasteboard().set_contents(obj, pasteboard.String)
        _SET_FRONT_APP_SCRIPT.run(front_app)
    elif selected_action in {'Open', 'Edit'}:
        command = ['/usr/bin/open']
        if selected_action == 'Edit':
            command.append('-t')
        command.append(obj)
        check_call(command)
    else:
        raise ValueError(f'Invalid selection: {selected_action}')
Exemple #5
0
#!/usr/bin/env python
import pasteboard
import sys

pb = pasteboard.Pasteboard()
pb.set_contents(sys.stdin.read(), type=pasteboard.HTML)
Exemple #6
0
sys.path.insert(0, "./modules/api")
import album_id

from util import *
image_path = ""
description = ""

try:
    image_path = sys.argv[1]
except IndexError:
    print("Please start by main.sh which will pass in the file path.")
    exit(1)

if "URL" in image_path:
    image_path = pasteboard.Pasteboard().get_contents()
    if "http" not in image_path:
        # exit code 2: Neither file path or url is not provided.
        print("No Image URL found in clipboard.")
        exit(2)

try:
    description = sys.argv[2]
except IndexError:
    # it's ok not to provide with description
    pass

config = {
    # "album": album_id.album_2020_08_22,
    "album": "j9PuG1C",  # album name: UK-10-2021
    # "album": album_id.hello_imgur,
Exemple #7
0
 def sendToClipboard(data):
     pb = pasteboard.Pasteboard()
     pb.set_contents(data)
Exemple #8
0
 def receiveFromClipboard():
     pb = pasteboard.Pasteboard()
     return pb.get_contents(type=pasteboard.String)
Exemple #9
0
def test_get_set_contents_with_emoji_santa():
    s = '\x1f385'
    pb = pasteboard.Pasteboard()
    assert pb.set_contents(s)
    assert pb.get_contents() == s
Exemple #10
0
def test_get_set_contents_with_null_char():
    pb = pasteboard.Pasteboard()
    assert pb.set_contents('abc\x00def')
    assert pb.get_contents() == 'abc'
Exemple #11
0
def test_get_set_contents_data(type, s):
    pb = pasteboard.Pasteboard()
    assert pb.set_contents(s, type=type)
    assert pb.get_contents(type=type) == s
    assert pb.get_contents(type=type, diff=True) is None
Exemple #12
0
def test_get_contents_diff_not_none_after_set(s):
    pb = pasteboard.Pasteboard()
    assert pb.set_contents(s)
    assert pb.get_contents(diff=True) == s
    assert pb.get_contents(diff=True) is None
Exemple #13
0
def test_get_set_contents_default(s):
    assume(s.encode('utf-8'))
    pb = pasteboard.Pasteboard()
    assert pb.set_contents(s)
    assert pb.get_contents() == s