Example #1
0
 def setText(self, aString, aType=win32con.CF_TEXT):
     w.OpenClipboard()
     w.EmptyClipboard()
     w.SetClipboardData(aType, aString)
     w.CloseClipboard()
def set_text(string):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, string)
    win32clipboard.CloseClipboard()
Example #3
0
def ImageGrab():
    class BITMAPFILEHEADER(ctypes.Structure):
        _pack_ = 1  # structure field byte alignment
        _fields_ = [
            ('bfType', WORD),  # file type ("BM")
            ('bfSize', DWORD),  # file size in bytes
            ('bfReserved1', WORD),  # must be zero
            ('bfReserved2', WORD),  # must be zero
            ('bfOffBits', DWORD),  # byte offset to the pixel array
        ]

    SIZEOF_BITMAPFILEHEADER = ctypes.sizeof(BITMAPFILEHEADER)

    class BITMAPINFOHEADER(ctypes.Structure):
        _pack_ = 1  # structure field byte alignment
        _fields_ = [('biSize', DWORD), ('biWidth', LONG), ('biHeight', LONG),
                    ('biPLanes', WORD), ('biBitCount', WORD),
                    ('biCompression', DWORD), ('biSizeImage', DWORD),
                    ('biXPelsPerMeter', LONG), ('biYPelsPerMeter', LONG),
                    ('biClrUsed', DWORD), ('biClrImportant', DWORD)]

    SIZEOF_BITMAPINFOHEADER = ctypes.sizeof(BITMAPINFOHEADER)

    win32clipboard.OpenClipboard()
    try:
        if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_DIB):
            data = win32clipboard.GetClipboardData(win32clipboard.CF_DIB)
        else:
            win32clipboard.CloseClipboard()
            # #print("!#$$$#")
            raise ('clipboard does not contain an image in DIB format')
            #
            sys.exit(1)
            #
    finally:
        try:
            win32clipboard.CloseClipboard()
        except:
            pass

    bmih = BITMAPINFOHEADER()
    ctypes.memmove(ctypes.pointer(bmih), data, SIZEOF_BITMAPINFOHEADER)

    if bmih.biCompression != BI_BITFIELDS:  # RGBA?
        #print('insupported compression type {}'.format(bmih.biCompression))
        sys.exit(1)

    bmfh = BITMAPFILEHEADER()
    ctypes.memset(ctypes.pointer(bmfh), 0,
                  SIZEOF_BITMAPFILEHEADER)  # zero structure
    bmfh.bfType = ord('B') | (ord('M') << 8)
    bmfh.bfSize = SIZEOF_BITMAPFILEHEADER + len(data)  # file size
    SIZEOF_COLORTABLE = 0
    bmfh.bfOffBits = SIZEOF_BITMAPFILEHEADER + \
        SIZEOF_BITMAPINFOHEADER + SIZEOF_COLORTABLE

    bmp_filename = 'clipboard.bmp'
    with open(bmp_filename, 'wb') as bmp_file:
        bmp_file.write(bmfh)
        bmp_file.write(data)

    #print('file "{}" created from clipboard image'.format(bmp_filename))

    return f'./{bmp_filename}'
Example #4
0
def setText(aString):
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_TEXT, aString)
    w.CloseClipboard()
Example #5
0
W["linesep"] = '\r\n'

W = PROGS["pythonwin"]
W["apppath"] = r""
W["windowcaption"] = "pythonwin"
W["windowclass"] = "Afx"
W["editcontrol"] = ['Afx', "Scintilla"]

# name of the control where the text goes in
W["edittext"] = [None, None]  # expect a new file, unsaved
W["aftertext"] = '\r\n'  # always after a text (richedit)
W["linesep"] = '\r\n'

# for testing in application word (isVisible only)
W = PROGS["word"]
W["apppath"] = None
W["windowcaption"] = "Microsoft Word"
W["windowclass"] = None
W["editcontrol"] = "RICHEDIT50W"  # name of the control where the text goes in
W["testcloseapp"] = 0

if __name__ == "__main__":
    import win32clipboard
    t = ""
    try:
        win32clipboard.OpenClipboard()
        t = win32clipboard.GetClipboardData()
    finally:
        win32clipboard.CloseClipboard()
    print "catch clipboard: \n|%s|" % repr(t)
Example #6
0
def getCopyText():
    w.OpenClipboard()
    copy_text = w.GetClipboardData(win32con.CF_TEXT)
    w.CloseClipboard()
    return copy_text.decode('GB2312')
import win32clipboard as clip
import win32con

clip.OpenClipboard()
print clip.GetClipboardData(win32con.CF_TEXT)
clip.CloseClipboard()
Example #8
0
    def input_kp26_cca(self, target):
        #        print(self.mc)
        if target == 'mc':
            df = self.mc
            target_type = 'mach_s'
        else:
            df = self.lb
            target_type = 'lab_s'

        for n in tqdm(range(0, len(df))):
            row = df.iloc[n]
            #            print(row['Cost Center'], row['Fixed'], row['Variable'])
            fix = row['Fixed']
            var = row['Variable']
            cc = row['Cost Center']
            #            print(cc)

            # delete cc which already input.
            pyautogui.press('del')
            pyautogui.typewrite(cc)
            for n in range(0, 3):
                pyautogui.press('tab')
            pyautogui.press('del')
            pyautogui.typewrite(target_type)
            pyautogui.hotkey('f6')
            time.sleep(2)

            # page changed to input area
            # copy the plan activity rate

            # get value from clipboard to see if they are blank.
            for n in range(0, 3):
                # in case plan activity quantity or capacity alraedy exists, remain it otherwise input 1

                for n in ['Plan activity', 'Capacity']:
                    if self.act_capa == True:
                        pyautogui.hotkey('ctrl', 'c')
                        win32clipboard.OpenClipboard()

                        try:
                            plan_act = win32clipboard.GetClipboardData(
                                win32clipboard.CF_UNICODETEXT)
                        except (TypeError, win32clipboard.error):
                            try:
                                plan_act = win32clipboard.GetClipboardData(
                                    win32clipboard.CF_TEXT)

    #                            text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING)
                            except (TypeError, win32clipboard.error):
                                plan_act = '0'

                        win32clipboard.EmptyClipboard()
                        win32clipboard.CloseClipboard()

                        #                    print("{} of {}:".format(n, cc), plan_act)
                        #                    print(str(plan_act))
                        if (str(plan_act) == 'return 0') | (str(plan_act)
                                                            == '0'):
                            pyautogui.typewrite('1')
                            pyautogui.press('tab')
                        else:
                            pyautogui.press('tab')

                    else:
                        pyautogui.typewrite('1')
                        pyautogui.press('tab')

                for d in [fix, var, '10000']:
                    if str(d) == 'nan':
                        pyautogui.press('tab')
                    else:
                        pyautogui.press('del')
                        pyautogui.typewrite(str(d))
                        pyautogui.press('tab')

                pyautogui.press('tab')

            # save the data that input

            print('Input rate for {} completed: fix:{}, var:{}'.format(
                cc, fix, var))
            pyautogui.hotkey('ctrl', 's')

            time.sleep(5)
            # go to Cost Center tap
            for n in range(0, 4):
                pyautogui.press('tab')
Example #9
0
 def GetText(self):
     wincb.OpenClipboard()
     t = wincb.GetClipboardData(win32con.CF_TEXT)
     wincb.CloseClipboard()
     return t
Example #10
0
 def set_clipboard(self, x):
     wcb.OpenClipboard()
     wcb.SetClipboardData(wc.CF_TEXT, x)
     wcb.CloseClipboard()
Example #11
0
 def query_clipboard(self):
     wcb.OpenClipboard()
     result = wcb.IsClipboardFormatAvailable(wc.CF_TEXT)
     wcb.CloseClipboard()
     return result
Example #12
0
def getText():
    """获取剪贴板文本"""
    w.OpenClipboard()
    d = w.GetClipboardData(win32con.CF_UNICODETEXT)
    w.CloseClipboard()
    return d
Example #13
0
def write_to_CF(upgrade_sw):  #把升级的sw路径放到剪切板
    # 写入剪切板
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_TEXT, upgrade_sw.encode(encoding='gbk'))
    w.CloseClipboard()
Example #14
0
 def read_clipboard(self):
     wcb.OpenClipboard()
     copied_url = wcb.GetClipboardData(win32con.CF_TEXT)
     wcb.CloseClipboard()
     return (copied_url).decode('utf8')
def get_text():
    w.OpenClipboard()
    d = w.GetClipboardData(win32con.CF_TEXT)
    w.CloseClipboard()
    return d.decode('GBK')
Example #16
0
 def CopyUrl(self,url):
     wincb.OpenClipboard()
     wincb.EmptyClipboard()
     wincb.SetClipboardData(win32con.CF_TEXT,url)
Example #17
0
 def setclip(self, text):
     win32clipboard.OpenClipboard()
     win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text)
     win32clipboard.CloseClipboard()
Example #18
0
 def clickClipbord(self):
     w.OpenClipboard()
     w.EmptyClipboard()
     # TODO 弹框提示 复制成功
     w.SetClipboardData(win32con.CF_UNICODETEXT, self.textBrowser.toPlainText())
     w.CloseClipboard()
Example #19
0
 def send_to_clipboard(cls, clip_type, data):
     win32clipboard.OpenClipboard()
     win32clipboard.EmptyClipboard()
     win32clipboard.SetClipboardData(clip_type, data)
     win32clipboard.CloseClipboard()
Example #20
0
 def copy(self, text):
     win32clipboard.OpenClipboard()
     win32clipboard.EmptyClipboard()
     win32clipboard.SetClipboardText(text)
     win32clipboard.CloseClipboard()
Example #21
0
def get_selected_text():
    win32clipboard.OpenClipboard()
    text = win32clipboard.GetClipboardData()
    win32clipboard.CloseClipboard()
    return text
Example #22
0
 def get_copy_value(self):
     win32clipboard.OpenClipboard()
     text = win32clipboard.GetClipboardData()
     win32clipboard.CloseClipboard()
     return text
Example #23
0
def getText():
    w.OpenClipboard()
    # d = w.GetClipboardData(win32con.CF_TEXT)
    d = w.GetClipboardData()
    w.CloseClipboard()
    return d
Example #24
0
    }

    # 截图
    image = grab_im()
    image.save(tmp_image)

    # 扶正图片
    sleep(.01)
    level_im(tmp_image, rotated_image)

    # 识别内容
    result = ocr(rotated_image, options)

    # 拼接成段落
    for i in result['words_result']:
        temp_arr.append(i['words'])
    texts = re.sub(pat, '', '\n'.join(temp_arr))

    print(texts)

    # 识别结果复制到剪贴板
    wc.OpenClipboard()
    wc.EmptyClipboard()
    wc.SetClipboardData(win32con.CF_UNICODETEXT, texts)
    wc.CloseClipboard()

    # 识别结果保存并打开
    with open(op_text, 'w+', encoding='gbk') as f:
        f.write(texts)
    os.system("notepad {}".format(op_text))
Example #25
0
def getCopyText():
    wc.OpenClipboard()
    copy_text = wc.GetClipboardData(win32con.CF_UNICODETEXT)
    wc.CloseClipboard
    return copy_text
Example #26
0
def setText(aString):
    """设置剪贴板文本"""
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
    w.CloseClipboard()
def get_text():
    win32clipboard.OpenClipboard()
    text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
    win32clipboard.CloseClipboard()
    return text
Example #28
0
def set_text_to_clipboard(str=None):
    print('set text :', str)
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(win32con.CF_TEXT, str)
    win32clipboard.CloseClipboard()
 def getText():
     '''获取剪切板的内容'''
     WC.OpenClipboard()
     value = WC.GetClipboardData(win32con.CF_TEXT)
     WC.CloseClipboard()
     return value
 def SetText(self,aString):
     w.OpenClipboard()                                      #打开剪切板
     w.EmptyClipboard()                                     #清空
     w.SetClipboardData(win32con.CF_UNICODETEXT, aString)    #写入
     w.CloseClipboard()                                      #关闭