コード例 #1
0
ファイル: misc.py プロジェクト: trotsky1997/powerClipboard
    def noti(a="0", title='Now Runnng at', tail=" mode"):
        def work():
            n.send((
                title,
                a + tail,
            ))

        go(work)
コード例 #2
0
def cook_clipboard_pic(vistor):
    ans = 0

    def work():
        nonlocal ans
        imgpath = ImageGrab()
        with open(imgpath, "rb") as f:
            ans = vistor(f.read())
        os.remove(imgpath)

    go(work)
    # return pyperclip.paste()

    return ans
コード例 #3
0
    def caller(a):
        def calling(sysTrayIcon, a=a):
            if 0 <= a < len(ops):
                mode[0] = a
                if mode[1] == -1:
                    mode[1] = 0
                if a < 2 and mode[2] == 1:
                    mode[2] = 0
                    noti("OCR only")
                else:
                    if mode[2] != 1:
                        noti(ops[a])
            elif a == len(ops):
                if mode[2] == 1:
                    noti("Translate only")
                    mode[2] = 0
                elif mode[2] == 0:
                    noti("OCR&Translate")
                    mode[2] = 1
            elif a == len(ops) + 1:
                if mode[1] != -1:
                    mode[1] = -1
                    noti("Listening Paused")
                else:
                    mode[1] = 0
                    noti("Listening Recoverd")
            elif a == len(ops) + 2:
                mode[3] = (mode[3] + 1) % 2
            elif a == -1:
                mode[1] = 1
                n.send(("Info", "Exiting"))

            #print(mode[0], mode[1], mode[2], mode[3])

        return lambda sysTrayIcon: go(calling, args=(sysTrayIcon,))
コード例 #4
0
ファイル: misc.py プロジェクト: trotsky1997/powerClipboard
def clipper(mode, n):  # c1r
    # try:

    def noti(a="0", title='Now Runnng at', tail=" mode"):
        def work():
            n.send((
                title,
                a + tail,
            ))

        go(work)

    action = [pic2text, pic2latex] + [vendor2engine(i) for i in mtVendors]
    # #print(action)
    old = pyperclip.paste()

    def test():
        try:
            nonlocal old
            pyperclip.copy("test")
            val = pyperclip.paste()
            ans = action[2](val)
            pyperclip.copy(ans)
            # print(ans)
            noti("Initlized Successfully!", title="Info", tail="")
            pyperclip.copy(old)
        except:
            pyperclip.copy(old)
            noti("Initlization Failed!", title="Info", tail="")

    go(test)

    def worker():

        nonlocal old
        val = pyperclip.paste(re=1)

        # def reg():
        #     nonlocal val
        #     txt = val
        #     txt = str(txt).strip()
        #     # 字符串按行分割
        #     txt = txt.splitlines()
        #     n = len(txt)
        #     # 用空格拼接每行
        #     txt = ' '.join(txt)
        #     # 将所有长度大于1的空白符转为1个空格
        #     txt = ' '.join(txt.split())
        # reg()
        if old == val:
            return
        if mode[2] == 0:
            try:
                ans = action[mode[0]](val)
                if mode[0] < 2:
                    noti("OCR Successfully!", title="Info", tail="")
            except:
                ans = action[2](val)

        elif mode[2] == 1:
            try:
                dans = action[0](val)
            except:
                dans = val
            if mode[0] < 2:
                eng = 2
            else:
                eng = mode[0]
            ans = action[eng](dans)
            noti("OCR&TRanslation Successfully!", title="Info", tail="")
        pyperclip.copy(ans, re=1)
        # print(ans)
        old = pyperclip.paste(re=1)
        if old == "pic":
            old = time.time()

    while True:
        if mode[1] == -1:
            old = pyperclip.paste()
        if mode[1] == 1:
            break
        if mode[1] == 0:
            go(worker)
コード例 #5
0
ファイル: app.py プロジェクト: trotsky1997/powerClipboard
        mode[0] = 2  # function mode
        mode[1] = 0  # listening mode
        mode[2] = 0  # OCR and translate mode
        mode[3] = 0  # No notification mode

        n1, n2 = Pipe()

        clipper = Process(target=clipper, args=(mode, n2))
        tray = trayer(ops, mode, n2)
        # observer = Process(target=clipboard_observer, args=(c1l, mode))
        clipper.start()

        def sub():
            nowNotice = None
            while True:
                if mode[1] == 1:
                    clipper.kill()
                    tray.shutdown()
                    if nowNotice != None:
                        nowNotice.kill()
                    break
                title, msg = n1.recv()
                if nowNotice != None:
                    nowNotice.kill()
                nowNotice = Process(target=WindowsBalloonTip,
                                    args=(msg, title)).start()

        go(sub)
except:
    pass