Beispiel #1
0
def getDevicePixelRatio():
    """ get dpi scale ratio """
    hdc = GetDC(None)
    t = GetDeviceCaps(hdc, DESKTOPHORZRES)
    d = GetDeviceCaps(hdc, HORZRES)
    ReleaseDC(None, hdc)
    return t / d
Beispiel #2
0
def icon_path(exe: path_type, name: str):
    id_file_name = f'{name}.png'
    id_path = p_join(this_dir, 'icons', id_file_name)

    if not p_exists(id_path):

        ico_x = GetSystemMetrics(SM_CXICON)

        try:
            large, small = ExtractIconEx(exe, 0)
        except error:
            return default_icon_path

        if not len(large):
            return default_icon_path

        if len(small):
            DestroyIcon(small[0])

        hdc = CreateDCFromHandle(GetDC(0))
        h_bmp = CreateBitmap()
        h_bmp.CreateCompatibleBitmap(hdc, ico_x, ico_x)
        hdc = hdc.CreateCompatibleDC()

        hdc.SelectObject(h_bmp)
        hdc.DrawIcon((0, 0), large[0])

        bmp_str = h_bmp.GetBitmapBits(True)
        img = Image.frombuffer('RGBA', (32, 32), bmp_str, 'raw', 'BGRA', 0, 1)

        img.save(id_path)

        print(f'Icon of {exe} saved in {id_path}')

    return id_path
def getlableSize(text,
                 font,
                 size,
                 underline=False,
                 strikeout=False,
                 Italic=False,
                 Bold=False,
                 Shadow=False):
    tempdc = 0
    tempbmp = 0
    f = 0
    lf = LOGFONT()
    textsize = 0
    tempdc = CreateDC("DISPLAY", "", None)
    tempbmp = CreateCompatibleBitmap(tempdc, 1, 1)
    tempobj = SelectObject(tempdc, tempbmp)  # 設定套用
    lf.lfFaceName = font
    lf.lfHeight = muldiv(size, GetDeviceCaps(GetDC(0), 90), 72)
    lf.lfUnderline = underline
    lf.lfItalic = Italic
    lf.lfStrikeOut = strikeout
    # 後來發現 粗體和陰影並不會增加太多字體大小
    # if Bold or Shadow:
    #     lf.lfWeight = 800
    # else:
    #     lf.lfWeight = 400
    f = CreateFontIndirect(lf)
    tempobj = SelectObject(tempdc, f)  # 設定套用

    for chr in text:  # 將字體配合主程式呼叫送出
        textsize = GetTextExtentPoint32(tempdc, chr)
        yield textsize
    return 0, 0
Beispiel #4
0
def test_small():
    win = GetDC(GetActiveWindow())
    # 작은창일때 체킹포인트
    color1 = GetPixel(win, 543, 419)
    color2 = GetPixel(win, 741, 433)
    color3 = GetPixel(win, 704, 188)

    # 큰창일때 체킹포인트
    click(684, 362)
    color4 = GetPixel(win, 544, 597)
    color5 = GetPixel(win, 546, 581)

    colorbool1 = str(color1)[0] == '6'
    colorbool2 = str(color2)[0] in ['8', '6']
    colorbool3 = str(color3)[:2] == '16'

    colorbool4 = str(color4)[0] == '6'
    colorbool5 = str(color5)[:2] == '16'

    if colorbool1 & colorbool2 & colorbool3:
        return "small"
    elif colorbool4 & colorbool5:
        return "big"
    else:
        print("False")
        return False
Beispiel #5
0
class KeyPresser(Thread):
    gcd = 1
    kc = KeyboardController()
    mc = MouseController()
    c = RGB(255, 0, 0)
    dc = GetDC(0)
    macro = ""

    def __init__(self, m):
        print(macros[m])
        self.macro = m
        Thread.__init__(self)
        self.daemon = True
        self.start()

    def indicator(self):
        width = int(GetSystemMetrics(0) / 2)
        for i in range(width - 12, width + 12):
            for j in range(24):
                SetPixel(self.dc, i, j, self.c)

    def run(self):
        while True:
            global run, pause, macros

            if running:
                self.indicator()

                if not pause:
                    for macro in macros[self.macro]:
                        if isinstance(macro, tuple):
                            self.mc.scroll(macro[0], macro[1])

                        else:
                            self.kc.press(macro)
                            self.kc.release(macro)

                        sleep(0.1)
                sleep(self.gcd)
            else:
                sleep(2)
Beispiel #6
0
    def __getIconFromProc(self, proc):

        path = proc.cmdline()[0]

        ico_size = GetSystemMetrics(SM_CXICON)

        large, _ = ExtractIconEx(path, 0)

        hdc = CreateDCFromHandle(GetDC(0))
        hbmp = CreateBitmap()
        hbmp.CreateCompatibleBitmap(hdc, ico_size, ico_size)
        hdc = hdc.CreateCompatibleDC()

        hdc.SelectObject(hbmp)
        hdc.DrawIcon((0, 0), large[0])

        bmpstr = hbmp.GetBitmapBits(True)

        image = Image.frombuffer('RGB', (ico_size, ico_size), bmpstr, 'raw',
                                 'BGRX', 0, 1)

        self.__imageList.append(image)
Beispiel #7
0
    def on_init_dialog(self, win, hwnd, msg, wparam, lparam):
        try:
            win.hwnd = hwnd

            dc = GetDC(win.hwnd)
            try:
                prev = SelectObject(dc, GetStockObject(DEFAULT_GUI_FONT))
                try:
                    tm = GetTextMetrics(dc)
                    win.x_unit = (tm["AveCharWidth"] + 1) / 4
                    win.y_unit = tm["Height"] / 8
                finally:
                    SelectObject(dc, prev)
            finally:
                ReleaseDC(win.hwnd, dc)

            win.label_height = round(9 * win.y_unit)

            win.notify = dict()
            self.controls[type(win.contents)].init(self, win.contents, win)

        except BaseException as exc:
            win.init_exc = exc